teralomaniac commited on
Commit
0a67b3e
1 Parent(s): 73b1774
Files changed (4) hide show
  1. clewd.js +30 -35
  2. lib/clewd-stream.js +10 -2
  3. lib/clewd-superfetch.js +1 -1
  4. lib/clewd-utils.js +66 -77
clewd.js CHANGED
@@ -7,7 +7,7 @@
7
  const {createServer: Server, IncomingMessage, ServerResponse} = require('node:http'), {createHash: Hash, randomUUID, randomInt, randomBytes} = require('node:crypto'), {TransformStream, ReadableStream} = require('node:stream/web'), {Readable, Writable} = require('node:stream'), {Blob} = require('node:buffer'), {existsSync: exists, writeFileSync: write, createWriteStream} = require('node:fs'), {join: joinP} = require('node:path'), {ClewdSuperfetch: Superfetch, SuperfetchAvailable} = require('./lib/clewd-superfetch'), {AI, fileName, genericFixes, bytesToSize, setTitle, checkResErr, Replacements, Main} = require('./lib/clewd-utils'), ClewdStream = require('./lib/clewd-stream');
8
 
9
  /******************************************************* */
10
- let currentIndex, Firstlogin = true, changeflag = 0, changing, changetime = 0, totaltime, invalidtime = 0, uuidOrgArray = [], model, reqModel, tokens, apiKey, timestamp = Date.now();
11
 
12
  const events = require('events'), CookieChanger = new events.EventEmitter();
13
  require('events').EventEmitter.defaultMaxListeners = 0;
@@ -22,7 +22,7 @@ CookieChanger.on('ChangeCookie', () => {
22
  console.error('Proxy error\n%o', err);
23
  }));
24
  timestamp = Date.now();
25
- invalidtime += 1;
26
  }, !Config.rProxy || Config.rProxy === AI.end() ? 15000 + timestamp - Date.now() : 0);
27
  });
28
 
@@ -36,13 +36,6 @@ const convertToType = value => {
36
  Config.Cookie = '';
37
  writeSettings(Config);
38
  currentIndex = (currentIndex - 1 + Config.CookieArray.length) % Config.CookieArray.length;
39
- }, ProModelConvert = model => {
40
- if (/^claude-2\.0$/.test(model)) return AI.mdl()[7];
41
- if (/1\.3/.test(model)) return AI.mdl()[5];
42
- if (/^claude-v1\.\d$/.test(model)) return AI.mdl()[1];
43
- if (/100k/.test(model)) return AI.mdl()[2];
44
- if (/v1\.\d/.test(model)) return AI.mdl()[3];
45
- return model;
46
  }, padtxt = content => {
47
  const {countTokens} = require('@anthropic-ai/tokenizer');
48
  const placeholder = Config.padtxt_placeholder || randomBytes(randomInt(5, 15)).toString('hex');
@@ -224,7 +217,7 @@ const updateParams = res => {
224
  }, onListen = async () => {
225
  /***************************** */
226
  if (Firstlogin) {
227
- Firstlogin = false;
228
  console.log(`${Main}\nhttp://${Config.Ip}:${Config.Port}/v1\n\n${Object.keys(Config.Settings).map((setting => UnknownSettings?.includes(setting) ? `??? ${setting}: ${Config.Settings[setting]}` : `${setting}: ${ChangedSettings?.includes(setting) ? '' : ''}${Config.Settings[setting]}`)).sort().join('\n')}\n`);
229
  Config.Settings.Superfetch && SuperfetchAvailable(true);
230
  if (Config.localtunnel) {
@@ -234,12 +227,11 @@ const updateParams = res => {
234
  console.log(`\nTunnel URL for outer websites: ${tunnel.url}/v1\n`);
235
  })
236
  }
237
- totaltime = Config.CookieArray.length;
238
  }
239
  if (Config.CookieArray?.length > 0) {
240
  Config.Cookie = Config.CookieArray[currentIndex];
241
  currentIndex = (currentIndex + 1) % Config.CookieArray.length;
242
- changetime += 1;
243
  }
244
  let percentage = ((changetime + Math.max(Config.CookieIndex - 1, 0)) / totaltime) * 100
245
  if (Config.Cookiecounter < 0 && percentage > 100) {
@@ -289,17 +281,17 @@ const updateParams = res => {
289
  });
290
  await checkResErr(accountRes);
291
  const accountInfo = await accountRes.json();
292
- model = accountInfo.account.statsig.values.dynamic_configs["6zA9wvTedwkzjLxWy9PVe7yydI00XDQ6L5Fejjq/2o8="]?.value?.model;
293
  /**************************** */
294
  console.log(Config.CookieArray?.length > 0 ? `(index: ${currentIndex || Config.CookieArray.length}) Logged in %o` : 'Logged in %o', { //console.log('Logged in %o', {
295
  name: accInfo.name?.split('@')?.[0],
296
  mail: accountInfo.account.email_address, //
297
  model, //
298
- capabilities: accInfo.capabilities,
299
  });
300
  uuidOrg = accInfo?.uuid;
301
  /************************* */
302
- if (reqModel && reqModel != model && !Config.Settings.PassParams) return CookieChanger.emit('ChangeCookie');
303
  const Overlap = uuidOrgArray.includes(uuidOrg) && percentage <= 100 && Config.CookieArray?.length > 0;
304
  !Overlap && uuidOrgArray.push(uuidOrg);
305
  const Unverified = !accountInfo.account.completed_verification_at;
@@ -347,7 +339,7 @@ const updateParams = res => {
347
  console.log(`${type}: ${json.error ? json.error.message || json.error.type || json.detail : 'OK'}`);
348
  })(flag.type))));
349
  /***************************** */
350
- if (Config.CookieArray?.length > 0) {
351
  console.log(`${'consumer_banned' === flagtype ? 'Banned' : 'Restricted'}!`);
352
  'consumer_banned' === flagtype && CookieCleaner();
353
  Config.Cookiecounter < 0 && console.log(`[progress]: ${percentage.toFixed(2)}%\n[length]: ${Config.CookieArray.length}\n`);
@@ -357,8 +349,8 @@ const updateParams = res => {
357
  if (Config.Cookiecounter < 0 || Exceededlimit) {
358
  console.log(Config.Cookiecounter < 0 ? `[progress]: ${percentage.toFixed(2)}%\n[length]: ${Config.CookieArray.length}\n` : 'Exceeded limit!\n');
359
  return CookieChanger.emit('ChangeCookie');
 
360
  /***************************** */
361
- }
362
  const convRes = await fetch(`${Config.rProxy || AI.end()}/api/organizations/${uuidOrg}/chat_conversations`, {
363
  method: 'GET',
364
  headers: {
@@ -369,7 +361,7 @@ const updateParams = res => {
369
  updateParams(convRes);
370
  conversations.length > 0 && await Promise.all(conversations.map((conv => deleteChat(conv.uuid))));
371
  /***************************** */
372
- invalidtime = 0, changing = false;
373
  } catch (err) {
374
  console.error('Clewd:\n%o', err);
375
  Config.CookieArray?.length > 0 && CookieChanger.emit('ChangeCookie');
@@ -398,7 +390,7 @@ const updateParams = res => {
398
  /***************************** */
399
  data: [ //data: AI.mdl().map((name => ({
400
  ...AI.mdl().slice(1).map((name => ({ id: name }))), {
401
- id: 'claude-2.0' },{
402
  id: 'claude-v1.3' },{
403
  id: 'claude-v1.3-100k' },{
404
  id: 'claude-v1.2' },{
@@ -426,7 +418,9 @@ const updateParams = res => {
426
  req.on('end', (async () => {
427
  let clewdStream, titleTimer, samePrompt = false, shouldRenew = true, retryRegen = false;
428
  try {
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) || req.headers.authorization?.match(/(?<=3rdKey: *)[\S]*/);
@@ -438,9 +432,9 @@ const updateParams = res => {
438
  model = body.model;
439
  } else if (req.headers.authorization.includes('sk-ant-api') || Config.ProxyPassword != '' && req.headers.authorization != 'Bearer ' + Config.ProxyPassword) {
440
  throw Error(req.headers.authorization.includes('sk-ant-api') ? 'apiKey Wrong' : 'ProxyPassword Wrong');
441
- } else if (changing || Config.CookieArray?.length > 0 && invalidtime >= Config.CookieArray?.length || reqModel && reqModel != model && !Config.Settings.PassParams) {
442
  changing ? invalidtime = 0 : changeflag = -1;
443
- throw Error(reqModel && reqModel && !Config.Settings.PassParams != body.model ? 'Polling requset model...' : 'Changing Cookie...');
444
  }
445
  /************************* */
446
  if (messages?.length < 1) {
@@ -474,9 +468,9 @@ const updateParams = res => {
474
  throw Error('Only one can be used at the same time: AllSamples/NoSamples');
475
  }
476
  //const model = body.model;
477
- if (!apiKey && Config.Settings.PassParams) { //if (model === AI.mdl()[0]) {
478
- model = ProModelConvert(model); //return;
479
- }
480
  if (!/claude-.*/.test(model)) {
481
  throw Error('Invalid model selected: ' + model);
482
  }
@@ -723,8 +717,8 @@ const updateParams = res => {
723
  timezone: AI.zone(),
724
  model
725
  },
726
- organization_uuid: uuidOrg,
727
  conversation_uuid: Conversation.uuid,
 
728
  text: prompt || '',
729
  attachments
730
  };
@@ -756,7 +750,7 @@ const updateParams = res => {
756
  version: Main,
757
  minSize: Config.BufferSize,
758
  model,
759
- streaming: body.stream, //null != body.stream,
760
  abortControl,
761
  source: fetchAPI
762
  }, Logger);
@@ -775,21 +769,21 @@ const updateParams = res => {
775
  param: null,
776
  code: err.code || 500
777
  }
778
- });
779
  }
780
  }
781
  clearInterval(titleTimer);
782
  if (clewdStream) {
783
  clewdStream.censored && console.warn('likely your account is hard-censored');
784
- prevImpersonated = clewdStream.impersonated;
785
  setTitle('ok ' + bytesToSize(clewdStream.size));
786
  429 == fetchAPI?.status ? console.log(`Exceeded limit!\n`) : console.log(`${200 == fetchAPI?.status ? '' : ''}${fetchAPI?.status}!\n`); //console.log(`${200 == fetchAPI.status ? '' : ''}${fetchAPI.status}!\n`);
787
  clewdStream.empty();
788
  }
789
- if (!apiKey) { //if (prevImpersonated) {
790
- await deleteChat(Conversation.uuid);
791
  /******************************** */
792
- changeflag += 1;
793
  if (changeflag < 0 || Config.CookieArray?.length > 0 && (429 == fetchAPI?.status || Config.Cookiecounter > 0 && changeflag >= Config.Cookiecounter)) {
794
  changeflag = 0;
795
  CookieChanger.emit('ChangeCookie');
@@ -803,9 +797,10 @@ const updateParams = res => {
803
  case '/v1/complete':
804
  res.json({
805
  error: {
806
- message: 'clewd: Set "Chat Completion" to OpenAI instead of Claude. Enable "External" models aswell'
 
807
  }
808
- });
809
  break;
810
 
811
  default:
@@ -895,4 +890,4 @@ process.on('SIGINT', cleanup);
895
 
896
  process.on('exit', (async () => {
897
  console.log('exiting...');
898
- }));
 
7
  const {createServer: Server, IncomingMessage, ServerResponse} = require('node:http'), {createHash: Hash, randomUUID, randomInt, randomBytes} = require('node:crypto'), {TransformStream, ReadableStream} = require('node:stream/web'), {Readable, Writable} = require('node:stream'), {Blob} = require('node:buffer'), {existsSync: exists, writeFileSync: write, createWriteStream} = require('node:fs'), {join: joinP} = require('node:path'), {ClewdSuperfetch: Superfetch, SuperfetchAvailable} = require('./lib/clewd-superfetch'), {AI, fileName, genericFixes, bytesToSize, setTitle, checkResErr, Replacements, Main} = require('./lib/clewd-utils'), ClewdStream = require('./lib/clewd-stream');
8
 
9
  /******************************************************* */
10
+ let currentIndex, Firstlogin = true, changeflag = 0, changing, changetime = 0, totaltime, invalidtime = 0, uuidOrgArray = [], model, reqModel, cookieModel, tokens, apiKey, timestamp;
11
 
12
  const events = require('events'), CookieChanger = new events.EventEmitter();
13
  require('events').EventEmitter.defaultMaxListeners = 0;
 
22
  console.error('Proxy error\n%o', err);
23
  }));
24
  timestamp = Date.now();
25
+ invalidtime++;
26
  }, !Config.rProxy || Config.rProxy === AI.end() ? 15000 + timestamp - Date.now() : 0);
27
  });
28
 
 
36
  Config.Cookie = '';
37
  writeSettings(Config);
38
  currentIndex = (currentIndex - 1 + Config.CookieArray.length) % Config.CookieArray.length;
 
 
 
 
 
 
 
39
  }, padtxt = content => {
40
  const {countTokens} = require('@anthropic-ai/tokenizer');
41
  const placeholder = Config.padtxt_placeholder || randomBytes(randomInt(5, 15)).toString('hex');
 
217
  }, onListen = async () => {
218
  /***************************** */
219
  if (Firstlogin) {
220
+ Firstlogin = false, timestamp = Date.now(), totaltime = Config.CookieArray.length;
221
  console.log(`${Main}\nhttp://${Config.Ip}:${Config.Port}/v1\n\n${Object.keys(Config.Settings).map((setting => UnknownSettings?.includes(setting) ? `??? ${setting}: ${Config.Settings[setting]}` : `${setting}: ${ChangedSettings?.includes(setting) ? '' : ''}${Config.Settings[setting]}`)).sort().join('\n')}\n`);
222
  Config.Settings.Superfetch && SuperfetchAvailable(true);
223
  if (Config.localtunnel) {
 
227
  console.log(`\nTunnel URL for outer websites: ${tunnel.url}/v1\n`);
228
  })
229
  }
 
230
  }
231
  if (Config.CookieArray?.length > 0) {
232
  Config.Cookie = Config.CookieArray[currentIndex];
233
  currentIndex = (currentIndex + 1) % Config.CookieArray.length;
234
+ changetime++;
235
  }
236
  let percentage = ((changetime + Math.max(Config.CookieIndex - 1, 0)) / totaltime) * 100
237
  if (Config.Cookiecounter < 0 && percentage > 100) {
 
281
  });
282
  await checkResErr(accountRes);
283
  const accountInfo = await accountRes.json();
284
+ model = accountInfo.account.statsig.values.dynamic_configs["6zA9wvTedwkzjLxWy9PVe7yydI00XDQ6L5Fejjq/2o8="]?.value?.model, cookieModel = model;
285
  /**************************** */
286
  console.log(Config.CookieArray?.length > 0 ? `(index: ${currentIndex || Config.CookieArray.length}) Logged in %o` : 'Logged in %o', { //console.log('Logged in %o', {
287
  name: accInfo.name?.split('@')?.[0],
288
  mail: accountInfo.account.email_address, //
289
  model, //
290
+ capabilities: accInfo.capabilities
291
  });
292
  uuidOrg = accInfo?.uuid;
293
  /************************* */
294
+ if (reqModel && reqModel != cookieModel && !Config.Settings.PassParams) return CookieChanger.emit('ChangeCookie');
295
  const Overlap = uuidOrgArray.includes(uuidOrg) && percentage <= 100 && Config.CookieArray?.length > 0;
296
  !Overlap && uuidOrgArray.push(uuidOrg);
297
  const Unverified = !accountInfo.account.completed_verification_at;
 
339
  console.log(`${type}: ${json.error ? json.error.message || json.error.type || json.detail : 'OK'}`);
340
  })(flag.type))));
341
  /***************************** */
342
+ if (Config.CookieArray?.length > 0) { //}
343
  console.log(`${'consumer_banned' === flagtype ? 'Banned' : 'Restricted'}!`);
344
  'consumer_banned' === flagtype && CookieCleaner();
345
  Config.Cookiecounter < 0 && console.log(`[progress]: ${percentage.toFixed(2)}%\n[length]: ${Config.CookieArray.length}\n`);
 
349
  if (Config.Cookiecounter < 0 || Exceededlimit) {
350
  console.log(Config.Cookiecounter < 0 ? `[progress]: ${percentage.toFixed(2)}%\n[length]: ${Config.CookieArray.length}\n` : 'Exceeded limit!\n');
351
  return CookieChanger.emit('ChangeCookie');
352
+ } else changing = false;
353
  /***************************** */
 
354
  const convRes = await fetch(`${Config.rProxy || AI.end()}/api/organizations/${uuidOrg}/chat_conversations`, {
355
  method: 'GET',
356
  headers: {
 
361
  updateParams(convRes);
362
  conversations.length > 0 && await Promise.all(conversations.map((conv => deleteChat(conv.uuid))));
363
  /***************************** */
364
+ invalidtime = 0;
365
  } catch (err) {
366
  console.error('Clewd:\n%o', err);
367
  Config.CookieArray?.length > 0 && CookieChanger.emit('ChangeCookie');
 
390
  /***************************** */
391
  data: [ //data: AI.mdl().map((name => ({
392
  ...AI.mdl().slice(1).map((name => ({ id: name }))), {
393
+ id: 'claude-2' },{
394
  id: 'claude-v1.3' },{
395
  id: 'claude-v1.3-100k' },{
396
  id: 'claude-v1.2' },{
 
418
  req.on('end', (async () => {
419
  let clewdStream, titleTimer, samePrompt = false, shouldRenew = true, retryRegen = false;
420
  try {
421
+ const body = JSON.parse(Buffer.concat(buffer).toString());
422
+ let {temperature} = body;
423
+ temperature = Math.max(.1, Math.min(1, temperature));
424
  let {messages} = body;
425
  /************************* */
426
  apiKey = req.headers.authorization?.match(/sk-ant-api\d\d-[\w-]{86}-[\w-]{6}AA/g) || req.headers.authorization?.match(/(?<=3rdKey: *)[\S]*/);
 
432
  model = body.model;
433
  } else if (req.headers.authorization.includes('sk-ant-api') || Config.ProxyPassword != '' && req.headers.authorization != 'Bearer ' + Config.ProxyPassword) {
434
  throw Error(req.headers.authorization.includes('sk-ant-api') ? 'apiKey Wrong' : 'ProxyPassword Wrong');
435
+ } else if (changing || Config.CookieArray?.length > 0 && invalidtime >= Config.CookieArray?.length || reqModel && reqModel != cookieModel && !Config.Settings.PassParams) {
436
  changing ? invalidtime = 0 : changeflag = -1;
437
+ throw Error(reqModel && reqModel != cookieModel && !Config.Settings.PassParams ? 'Polling requset model...' : 'Changing Cookie...');
438
  }
439
  /************************* */
440
  if (messages?.length < 1) {
 
468
  throw Error('Only one can be used at the same time: AllSamples/NoSamples');
469
  }
470
  //const model = body.model;
471
+ //if (model === AI.mdl()[0]) {
472
+ // return;
473
+ //}
474
  if (!/claude-.*/.test(model)) {
475
  throw Error('Invalid model selected: ' + model);
476
  }
 
717
  timezone: AI.zone(),
718
  model
719
  },
 
720
  conversation_uuid: Conversation.uuid,
721
+ organization_uuid: uuidOrg,
722
  text: prompt || '',
723
  attachments
724
  };
 
750
  version: Main,
751
  minSize: Config.BufferSize,
752
  model,
753
+ streaming: true === body.stream,
754
  abortControl,
755
  source: fetchAPI
756
  }, Logger);
 
769
  param: null,
770
  code: err.code || 500
771
  }
772
+ }, 500);
773
  }
774
  }
775
  clearInterval(titleTimer);
776
  if (clewdStream) {
777
  clewdStream.censored && console.warn('likely your account is hard-censored');
778
+ clewdStream.nochange && changeflag--; //prevImpersonated = clewdStream.impersonated;
779
  setTitle('ok ' + bytesToSize(clewdStream.size));
780
  429 == fetchAPI?.status ? console.log(`Exceeded limit!\n`) : console.log(`${200 == fetchAPI?.status ? '' : ''}${fetchAPI?.status}!\n`); //console.log(`${200 == fetchAPI.status ? '' : ''}${fetchAPI.status}!\n`);
781
  clewdStream.empty();
782
  }
783
+ if (!apiKey) { //if (prevImpersonated) { try {
784
+ await deleteChat(Conversation.uuid); //} catch (err) {}
785
  /******************************** */
786
+ changeflag++;
787
  if (changeflag < 0 || Config.CookieArray?.length > 0 && (429 == fetchAPI?.status || Config.Cookiecounter > 0 && changeflag >= Config.Cookiecounter)) {
788
  changeflag = 0;
789
  CookieChanger.emit('ChangeCookie');
 
797
  case '/v1/complete':
798
  res.json({
799
  error: {
800
+ message: 'clewd: Set "Chat Completion source" to OpenAI instead of Claude. Enable "External" models aswell',
801
+ code: 404
802
  }
803
+ }, 404);
804
  break;
805
 
806
  default:
 
890
 
891
  process.on('exit', (async () => {
892
  console.log('exiting...');
893
+ }));
lib/clewd-stream.js CHANGED
@@ -20,7 +20,7 @@ class ClewdStream extends TransformStream {
20
  this.#version = opts.version;
21
  this.#config = opts.config;
22
  this.#model = opts.model;
23
- this.#streaming = opts.streaming || false;
24
  this.#minSize = opts.minSize || 8;
25
  this.#abortControl = opts.abortControl;
26
  this.#source = opts.source;
@@ -42,6 +42,7 @@ class ClewdStream extends TransformStream {
42
  #stopReason=void 0;
43
  #hardCensor=false;
44
  #impersonated=false;
 
45
  get size() {
46
  return this.#recvLength;
47
  }
@@ -53,7 +54,12 @@ class ClewdStream extends TransformStream {
53
  }
54
  get impersonated() {
55
  return this.#impersonated;
56
- }
 
 
 
 
 
57
  empty() {
58
  this.#compOK = this.#compRaw = '';
59
  this.#compAll = [];
@@ -67,6 +73,7 @@ class ClewdStream extends TransformStream {
67
  #err(err, controller) {
68
  this.#logger?.write(JSON.stringify(err, null, 4));
69
  const message = `## ${this.#version}\n**${this.#model} error**:\n${err.status || err.code || err.type}\n\n\`\`\`${err.message}\`\`\`\n\nFAQ: https://rentry.org/teralomaniac_clewd`;
 
70
  this.#enqueue(this.#build(message), controller);
71
  return this.#endEarly(controller);
72
  }
@@ -97,6 +104,7 @@ class ClewdStream extends TransformStream {
97
  this.#compAll?.[0] === Buffer.from([ 73, 32, 97, 112, 111, 108, 111, 103, 105, 122, 101, 44, 32, 98, 117, 116, 32, 73, 32, 119, 105, 108, 108, 32, 110, 111, 116, 32, 112, 114, 111, 118, 105, 100, 101, 32, 97, 110, 121, 32, 114, 101, 115, 112, 111, 110, 115, 101, 115, 32, 116, 104, 97, 116, 32, 118, 105, 111, 108, 97, 116, 101, 32, 65, 110, 116, 104, 114, 111, 112, 105, 99, 39, 115, 32, 65, 99, 99, 101, 112, 116, 97, 98, 108, 101, 32, 85, 115, 101, 32, 80, 111, 108, 105, 99, 121, 32, 111, 114, 32, 99, 111, 117, 108, 100, 32, 112, 114, 111, 109, 111, 116, 101, 32, 104, 97, 114, 109, 46 ]).toString() && (this.#hardCensor = true);
98
  if (!this.#ended && 0 === this.total) {
99
  const err = `## ${this.#version}\n**error**:\n\n\`\`\`Received no valid replies at all\`\`\`\n\nFAQ: https://rentry.org/teralomaniac_clewd`;
 
100
  this.#enqueue(this.#build(err), controller);
101
  }
102
  this.#streaming && this.#enqueue('data: [DONE]\n\n', controller);
 
20
  this.#version = opts.version;
21
  this.#config = opts.config;
22
  this.#model = opts.model;
23
+ this.#streaming = opts.streaming;
24
  this.#minSize = opts.minSize || 8;
25
  this.#abortControl = opts.abortControl;
26
  this.#source = opts.source;
 
42
  #stopReason=void 0;
43
  #hardCensor=false;
44
  #impersonated=false;
45
+ #nochange=false; //
46
  get size() {
47
  return this.#recvLength;
48
  }
 
54
  }
55
  get impersonated() {
56
  return this.#impersonated;
57
+ }
58
+ /************************ */
59
+ get nochange() {
60
+ return this.#nochange;
61
+ }
62
+ /************************ */
63
  empty() {
64
  this.#compOK = this.#compRaw = '';
65
  this.#compAll = [];
 
73
  #err(err, controller) {
74
  this.#logger?.write(JSON.stringify(err, null, 4));
75
  const message = `## ${this.#version}\n**${this.#model} error**:\n${err.status || err.code || err.type}\n\n\`\`\`${err.message}\`\`\`\n\nFAQ: https://rentry.org/teralomaniac_clewd`;
76
+ this.#nochange = true; //
77
  this.#enqueue(this.#build(message), controller);
78
  return this.#endEarly(controller);
79
  }
 
104
  this.#compAll?.[0] === Buffer.from([ 73, 32, 97, 112, 111, 108, 111, 103, 105, 122, 101, 44, 32, 98, 117, 116, 32, 73, 32, 119, 105, 108, 108, 32, 110, 111, 116, 32, 112, 114, 111, 118, 105, 100, 101, 32, 97, 110, 121, 32, 114, 101, 115, 112, 111, 110, 115, 101, 115, 32, 116, 104, 97, 116, 32, 118, 105, 111, 108, 97, 116, 101, 32, 65, 110, 116, 104, 114, 111, 112, 105, 99, 39, 115, 32, 65, 99, 99, 101, 112, 116, 97, 98, 108, 101, 32, 85, 115, 101, 32, 80, 111, 108, 105, 99, 121, 32, 111, 114, 32, 99, 111, 117, 108, 100, 32, 112, 114, 111, 109, 111, 116, 101, 32, 104, 97, 114, 109, 46 ]).toString() && (this.#hardCensor = true);
105
  if (!this.#ended && 0 === this.total) {
106
  const err = `## ${this.#version}\n**error**:\n\n\`\`\`Received no valid replies at all\`\`\`\n\nFAQ: https://rentry.org/teralomaniac_clewd`;
107
+ this.#nochange = true; //
108
  this.#enqueue(this.#build(err), controller);
109
  }
110
  this.#streaming && this.#enqueue('data: [DONE]\n\n', controller);
lib/clewd-superfetch.js CHANGED
@@ -1,4 +1,4 @@
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 [err] unavailable for ${process.platform}-${process.arch}, use 3.8.5 for the time being\n`);return false}e&&console.log(`superfetch [found] ${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 [err]",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"),m=e=>"win32"===process.platform?".\\"+e:e,l=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),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,54,92,34,44,32,92,34,78,111,116,41,65,59,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,54,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,54,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,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,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,93],y=(e=false)=>{if(!u||!i(h)){e&&console.warn(`superfetch [err] unavailable for ${process.platform}-${process.arch}, use 3.8.5 for the time being\n`);return false}e&&console.log(`superfetch [found] ${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 _=l(m(o)),g=l(m(c)),v=l(m(i)),O=["-v","--cacert",""+l(m(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 [err]",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
@@ -13,9 +13,9 @@ new TextEncoder), Main = 'clewd修改版 v' + Version + '(1) by tera', Replaceme
13
  example_assistant: 'A'
14
  }, DangerChars = [ ...new Set([ ...Object.values(Replacements).join(''), ...'\n', ...':', ...'\\n' ]) ].filter((char => ' ' !== char)).sort(), AI = {
15
  end: () => Buffer.from([ 104, 116, 116, 112, 115, 58, 47, 47, 99, 108, 97, 117, 100, 101, 46, 97, 105 ]).toString(),
16
- mdl: () => JSON.parse(Buffer.from([ 91, 34, 33, 32, 85, 83, 73, 78, 71, 32, 77, 79, 68, 69, 76, 83, 32, 79, 84, 72, 69, 82, 32, 84, 72, 65, 78, 32, 99, 108, 97, 117, 100, 101, 45, 50, 46, 49, 32, 42, 67, 79, 85, 76, 68, 42, 32, 71, 69, 84, 32, 89, 79, 85, 32, 66, 65, 78, 78, 69, 68, 32, 73, 70, 32, 89, 79, 85, 39, 82, 69, 32, 78, 79, 84, 32, 65, 32, 80, 82, 79, 32, 85, 83, 69, 82, 32, 33, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 49, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 105, 110, 115, 116, 97, 110, 116, 45, 49, 48, 48, 107, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 105, 110, 115, 116, 97, 110, 116, 45, 49, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 105, 110, 115, 116, 97, 110, 116, 45, 49, 46, 50, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 49, 46, 51, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 50, 46, 48, 45, 109, 97, 103, 101, 110, 116, 97, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 50, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 50, 46, 49, 34, 93 ]).toString()),
17
  zone: () => Buffer.from([ 65, 115, 105, 97, 47, 83, 104, 97, 110, 103, 104, 97, 105 ]).toString(), //Buffer.from([ 65, 109, 101, 114, 105, 99, 97, 47, 78, 101, 119, 95, 89, 111, 114, 107 ]).toString(),
18
- agent: () => Buffer.from([ 77, 111, 122, 105, 108, 108, 97, 47, 53, 46, 48, 32, 40, 77, 97, 99, 105, 110, 116, 111, 115, 104, 59, 32, 73, 110, 116, 101, 108, 32, 77, 97, 99, 32, 79, 83, 32, 88, 32, 49, 48, 95, 49, 53, 95, 55, 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, 52, 46, 48, 46, 48, 46, 48, 32, 83, 97, 102, 97, 114, 105, 47, 53, 51, 55, 46, 51, 54, 32, 69, 100, 103, 47, 49, 49, 52, 46, 48, 46, 49, 56, 50, 51, 46, 55, 57 ]).toString(),
19
  cp: () => Buffer.from([ 55, 55, 49, 44, 52, 56, 54, 53, 45, 52, 56, 54, 54, 45, 52, 56, 54, 55, 45, 52, 57, 49, 57, 53, 45, 52, 57, 49, 57, 57, 45, 52, 57, 49, 57, 54, 45, 52, 57, 50, 48, 48, 45, 53, 50, 51, 57, 51, 45, 53, 50, 51, 57, 50, 45, 52, 57, 49, 55, 49, 45, 52, 57, 49, 55, 50, 45, 49, 53, 54, 45, 49, 53, 55, 45, 52, 55, 45, 53, 51, 44, 48, 45, 50, 51, 45, 54, 53, 50, 56, 49, 45, 49, 48, 45, 49, 49, 45, 51, 53, 45, 49, 54, 45, 53, 45, 49, 51, 45, 49, 56, 45, 53, 49, 45, 52, 53, 45, 52, 51, 45, 50, 55, 45, 49, 55, 53, 49, 51, 45, 50, 49, 44, 50, 57, 45, 50, 51, 45, 50, 52, 44, 48 ]).toString(),
20
  hdr: refPath => ({
21
  'Content-Type': 'application/json',
@@ -34,83 +34,72 @@ new TextEncoder), Main = 'clewd修改版 v' + Version + '(1) by tera', Replaceme
34
  return location;
35
  };
36
 
37
- module.exports.encodeDataJSON = completion => Encoder.encode(`data: ${JSON.stringify(completion)}\n\n`);
38
-
39
- module.exports.genericFixes = text => text.replace(/(\r\n|\r|\\n)/gm, '\n');
40
-
41
- module.exports.Replacements = Replacements;
42
-
43
- module.exports.DangerChars = DangerChars;
44
-
45
- module.exports.checkResErr = async (res, CookieChanger, throwIt = true) => { //module.exports.checkResErr = async (res, throwIt = true) => {
46
- let err, json, errAPI;
47
- if ('string' == typeof res) {
48
- json = JSON.parse(res);
49
- errAPI = json.error;
50
- err = Error(errAPI.message);
51
- } else if (res.status < 200 || res.status >= 300) {
52
- err = Error('Unexpected response code: ' + (res.status || json.status));
53
- json = await res.json();
54
- errAPI = json.error;
55
- }
56
- if (errAPI) {
57
- err.status = res.status || json.status;
58
- err.planned = true;
59
- errAPI.message && (err.message = errAPI.message);
60
- errAPI.type && (err.type = errAPI.type);
61
- if ((429 === res.status || 429 === json.status) && errAPI.resets_at) {
62
- const hours = ((new Date(1e3 * errAPI.resets_at).getTime() - Date.now()) / 1e3 / 60 / 60).toFixed(1);
63
- err.message += `, expires in ${hours} hours`;
64
  /************************** */
65
- if (CookieChanger) {
66
- console.log(`Exceeded limit!\n`);
67
- CookieChanger && CookieChanger.emit('ChangeCookie');
68
- }
69
  /************************** */
 
 
 
 
70
  }
71
- if (throwIt) {
72
- throw err;
 
 
 
73
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
75
- return err;
76
- };
77
-
78
- module.exports.bytesToSize = (bytes = 0, decimals = 2) => {
79
- if (0 === bytes) {
80
- return '0 Bytes';
81
- }
82
- const dm = decimals < 0 ? 0 : decimals, i = Math.round(Math.log(bytes) / Math.log(1024));
83
- return `${(bytes / Math.pow(1024, i)).toFixed(dm)} ${[ 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ][i]}`;
84
- };
85
-
86
- module.exports.indexOfAny = (text, last = false) => {
87
- let location = -1;
88
- const fakes = [ indexOfH(text, last), indexOfA(text, last) ].filter((idx => idx > -1)).sort();
89
- location = last ? fakes.reverse()[0] : fakes[0];
90
- return isNaN(location) ? -1 : location;
91
- };
92
-
93
- module.exports.cleanJSON = json => json.replace(/^data: {/gim, '{').replace(/\s+$/gim, '');
94
-
95
- module.exports.fileName = () => {
96
- const len = randomInt(5, 15);
97
- let name = randomBytes(len).toString('hex');
98
- for (let i = 0; i < name.length; i++) {
99
- const char = name.charAt(i);
100
- isNaN(char) && randomInt(1, 5) % 2 == 0 && ' ' !== name.charAt(i - 1) && (name = name.slice(0, i) + ' ' + name.slice(i));
101
- }
102
- return name + '.txt';
103
- };
104
-
105
- module.exports.indexOfA = indexOfA;
106
-
107
- module.exports.indexOfH = indexOfH;
108
-
109
- module.exports.setTitle = title => {
110
- title = `${Main} - ${title}`;
111
- process.title !== title && (process.title = title);
112
- };
113
-
114
- module.exports.Main = Main;
115
-
116
- module.exports.AI = AI;
 
13
  example_assistant: 'A'
14
  }, DangerChars = [ ...new Set([ ...Object.values(Replacements).join(''), ...'\n', ...':', ...'\\n' ]) ].filter((char => ' ' !== char)).sort(), AI = {
15
  end: () => Buffer.from([ 104, 116, 116, 112, 115, 58, 47, 47, 99, 108, 97, 117, 100, 101, 46, 97, 105 ]).toString(),
16
+ mdl: () => JSON.parse(Buffer.from([ 91, 34, 33, 32, 85, 83, 73, 78, 71, 32, 77, 79, 68, 69, 76, 83, 32, 79, 84, 72, 69, 82, 32, 84, 72, 65, 78, 32, 50, 46, 49, 32, 111, 114, 32, 50, 46, 48, 32, 42, 67, 79, 85, 76, 68, 42, 32, 71, 69, 84, 32, 89, 79, 85, 32, 66, 65, 78, 78, 69, 68, 32, 73, 70, 32, 89, 79, 85, 39, 82, 69, 32, 78, 79, 84, 32, 65, 32, 80, 82, 79, 32, 85, 83, 69, 82, 32, 33, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 50, 46, 49, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 50, 46, 48, 34, 44, 34, 99, 108, 97, 117, 100, 101, 45, 105, 110, 115, 116, 97, 110, 116, 45, 49, 46, 50, 34, 93 ]).toString()),
17
  zone: () => Buffer.from([ 65, 115, 105, 97, 47, 83, 104, 97, 110, 103, 104, 97, 105 ]).toString(), //Buffer.from([ 65, 109, 101, 114, 105, 99, 97, 47, 78, 101, 119, 95, 89, 111, 114, 107 ]).toString(),
18
+ agent: () => Buffer.from([ 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, 54, 46, 48, 46, 48, 46, 48, 32, 83, 97, 102, 97, 114, 105, 47, 53, 51, 55, 46, 51, 54 ]).toString(),
19
  cp: () => Buffer.from([ 55, 55, 49, 44, 52, 56, 54, 53, 45, 52, 56, 54, 54, 45, 52, 56, 54, 55, 45, 52, 57, 49, 57, 53, 45, 52, 57, 49, 57, 57, 45, 52, 57, 49, 57, 54, 45, 52, 57, 50, 48, 48, 45, 53, 50, 51, 57, 51, 45, 53, 50, 51, 57, 50, 45, 52, 57, 49, 55, 49, 45, 52, 57, 49, 55, 50, 45, 49, 53, 54, 45, 49, 53, 55, 45, 52, 55, 45, 53, 51, 44, 48, 45, 50, 51, 45, 54, 53, 50, 56, 49, 45, 49, 48, 45, 49, 49, 45, 51, 53, 45, 49, 54, 45, 53, 45, 49, 51, 45, 49, 56, 45, 53, 49, 45, 52, 53, 45, 52, 51, 45, 50, 55, 45, 49, 55, 53, 49, 51, 45, 50, 49, 44, 50, 57, 45, 50, 51, 45, 50, 52, 44, 48 ]).toString(),
20
  hdr: refPath => ({
21
  'Content-Type': 'application/json',
 
34
  return location;
35
  };
36
 
37
+ module.exports = {
38
+ Main,
39
+ AI,
40
+ Replacements,
41
+ DangerChars,
42
+ encodeDataJSON: completion => Encoder.encode(`data: ${JSON.stringify(completion)}\n\n`),
43
+ genericFixes: text => text.replace(/(\r\n|\r|\\n)/gm, '\n'),
44
+ checkResErr: async (res, CookieChanger, throwIt = true) => { //(res, throwIt = true) => {
45
+ let err, json, errAPI;
46
+ if ('string' == typeof res) {
47
+ json = JSON.parse(res);
48
+ errAPI = json.error;
49
+ err = Error(errAPI.message);
50
+ } else if (res.status < 200 || res.status >= 300) {
51
+ err = Error('Unexpected response code: ' + (res.status || json.status));
52
+ json = await res.json();
53
+ errAPI = json.error;
54
+ }
55
+ if (errAPI) {
56
+ err.status = res.status || json.status;
57
+ err.planned = true;
58
+ errAPI.message && (err.message = errAPI.message);
59
+ errAPI.type && (err.type = errAPI.type);
60
+ if ((429 === res.status || 429 === json.status) && errAPI.resets_at) {
61
+ const hours = ((new Date(1e3 * errAPI.resets_at).getTime() - Date.now()) / 1e3 / 60 / 60).toFixed(1);
62
+ err.message += `, expires in ${hours} hours`;
 
63
  /************************** */
64
+ if (CookieChanger) {
65
+ console.log(`Exceeded limit!\n`);
66
+ CookieChanger && CookieChanger.emit('ChangeCookie');
67
+ }
68
  /************************** */
69
+ }
70
+ if (throwIt) {
71
+ throw err;
72
+ }
73
  }
74
+ return err;
75
+ },
76
+ bytesToSize: (bytes = 0, decimals = 2) => {
77
+ if (0 === bytes) {
78
+ return '0 B';
79
  }
80
+ const dm = decimals < 0 ? 0 : decimals, i = Math.round(Math.log(bytes) / Math.log(1024));
81
+ return `${(bytes / Math.pow(1024, i)).toFixed(dm)} ${[ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ][i]}`;
82
+ },
83
+ indexOfAny: (text, last = false) => {
84
+ let location = -1;
85
+ const fakes = [ indexOfH(text, last), indexOfA(text, last) ].filter((idx => idx > -1)).sort();
86
+ location = last ? fakes.reverse()[0] : fakes[0];
87
+ return isNaN(location) ? -1 : location;
88
+ },
89
+ cleanJSON: json => json.indexOf('data:') > -1 ? json.split('data: ')?.[1] : json,
90
+ fileName: () => {
91
+ const len = randomInt(5, 15);
92
+ let name = randomBytes(len).toString('hex');
93
+ for (let i = 0; i < name.length; i++) {
94
+ const char = name.charAt(i);
95
+ isNaN(char) && randomInt(1, 5) % 2 == 0 && ' ' !== name.charAt(i - 1) && (name = name.slice(0, i) + ' ' + name.slice(i));
96
+ }
97
+ return name + '.txt';
98
+ },
99
+ indexOfA,
100
+ indexOfH,
101
+ setTitle: title => {
102
+ title = `${Main} - ${title}`;
103
+ process.title !== title && (process.title = title);
104
  }
105
+ };