[chore] Fix type errors

4fcad0752f6e03d4796cda9838f96604298e02e9

Cohee <18619528+Cohee1207@users.noreply.github.com>

25 files changed, +78 -44Ignore whitespace
package-lock.json+0 -1
@@ -71,7 +71,6 @@
7171 "@types/lodash": "^4.17.10",
7272 "@types/mime-types": "^2.1.4",
7373 "@types/multer": "^1.4.12",
74- "@types/node-fetch": "^2.6.11",
7574 "@types/node-persist": "^3.1.8",
7675 "@types/png-chunk-text": "^1.0.3",
7776 "@types/png-chunks-encode": "^1.0.2",
package.json+0 -1
@@ -97,7 +97,6 @@
9797 "@types/lodash": "^4.17.10",
9898 "@types/mime-types": "^2.1.4",
9999 "@types/multer": "^1.4.12",
100- "@types/node-fetch": "^2.6.11",
101100 "@types/node-persist": "^3.1.8",
102101 "@types/png-chunk-text": "^1.0.3",
103102 "@types/png-chunks-encode": "^1.0.2",
src/character-card-parser.js+2 -2
@@ -13,7 +13,7 @@ import PNGtext from 'png-chunk-text';
1313 * @returns {Buffer} PNG image buffer with metadata
1414 */
1515export const write = (image, data) => {
1616 const chunks = extract(new Uint8Array(image));
1717 const tEXtChunks = chunks.filter(chunk => chunk.name === 'tEXt');
1818
1919 // Remove existing tEXt chunks
@@ -52,7 +52,7 @@ export const write = (image, data) => {
5252 * @returns {string} Character data
5353 */
5454export const read = (image) => {
5555 const chunks = extract(new Uint8Array(image));
5656
5757 const textChunks = chunks.filter((chunk) => chunk.name === 'tEXt').map((chunk) => PNGtext.decode(chunk.data));
5858
src/endpoints/anthropic.js+1 -1
@@ -42,7 +42,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
4242 'anthropic-version': '2023-06-01',
4343 'x-api-key': request.body.reverse_proxy ? request.body.proxy_password : readSecret(request.user.directories, SECRET_KEYS.CLAUDE),
4444 },
45- timeout: 0,
4645 });
4746
4847 if (!result.ok) {
@@ -51,6 +50,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
5150 return response.status(result.status).send({ error: true });
5251 }
5352
53+ /** @type {any} */
5454 const generateResponseJson = await result.json();
5555 const caption = generateResponseJson.content[0].text;
5656 console.log('Claude response:', generateResponseJson);
src/endpoints/backends/chat-completions.js+5 -4
@@ -152,7 +152,6 @@ async function sendClaudeRequest(request, response) {
152152 'x-api-key': apiKey,
153153 ...additionalHeaders,
154154 },
155- timeout: 0,
156155 });
157156
158157 if (request.body.stream) {
@@ -165,6 +164,7 @@ async function sendClaudeRequest(request, response) {
165164 return response.status(generateResponse.status).send({ error: true });
166165 }
167166
167+ /** @type {any} */
168168 const generateResponseJson = await generateResponse.json();
169169 const responseText = generateResponseJson?.content?.[0]?.text || '';
170170 console.log('Claude response:', generateResponseJson);
@@ -212,7 +212,6 @@ async function sendScaleRequest(request, response) {
212212 'Content-Type': 'application/json',
213213 'Authorization': `Basic ${apiKey}`,
214214 },
215- timeout: 0,
216215 });
217216
218217 if (!generateResponse.ok) {
@@ -220,6 +219,7 @@ async function sendScaleRequest(request, response) {
220219 return response.status(500).send({ error: true });
221220 }
222221
222+ /** @type {any} */
223223 const generateResponseJson = await generateResponse.json();
224224 console.log('Scale response:', generateResponseJson);
225225
@@ -335,7 +335,6 @@ async function sendMakerSuiteRequest(request, response) {
335335 'Content-Type': 'application/json',
336336 },
337337 signal: controller.signal,
338- timeout: 0,
339338 });
340339 // have to do this because of their busted ass streaming endpoint
341340 if (stream) {
@@ -354,6 +353,7 @@ async function sendMakerSuiteRequest(request, response) {
354353 return response.status(generateResponse.status).send({ error: true });
355354 }
356355
356+ /** @type {any} */
357357 const generateResponseJson = await generateResponse.json();
358358
359359 const candidates = generateResponseJson?.candidates;
@@ -676,6 +676,7 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o
676676 });
677677
678678 if (response.ok) {
679+ /** @type {any} */
679680 const data = await response.json();
680681 response_getstatus_openai.send(data);
681682
@@ -979,7 +980,6 @@ router.post('/generate', jsonParser, function (request, response) {
979980 },
980981 body: JSON.stringify(requestBody),
981982 signal: controller.signal,
982- timeout: 0,
983983 };
984984
985985 console.log(requestBody);
@@ -1005,6 +1005,7 @@ router.post('/generate', jsonParser, function (request, response) {
10051005 }
10061006
10071007 if (fetchResponse.ok) {
1008+ /** @type {any} */
10081009 let json = await fetchResponse.json();
10091010 response.send(json);
10101011 console.log(json);
src/endpoints/backends/kobold.js+2 -1
@@ -96,7 +96,7 @@ router.post('/generate', jsonParser, async function (request, response_generate)
9696 for (let i = 0; i < MAX_RETRIES; i++) {
9797 try {
9898 const url = request.body.streaming ? `${request.body.api_server}/extra/generate/stream` : `${request.body.api_server}/v1/generate`;
9999 const response = await fetch(url, { method: 'POST', timeout: 0, ...args });
100100
101101 if (request.body.streaming) {
102102 // Pipe remote SSE stream to Express response
@@ -156,6 +156,7 @@ router.post('/status', jsonParser, async function (request, response) {
156156
157157 const result = {};
158158
159+ /** @type {any} */
159160 const [koboldUnitedResponse, koboldExtraResponse, koboldModelResponse] = await Promise.all([
160161 // We catch errors both from the response not having a successful HTTP status and from JSON parsing failing
161162
src/endpoints/backends/scale-alt.js+1 -1
@@ -70,7 +70,6 @@ router.post('/generate', jsonParser, async function (request, response) {
7070 'Content-Type': 'application/json',
7171 'cookie': `_jwt=${cookie}`,
7272 },
73- timeout: 0,
7473 body: JSON.stringify(body),
7574 });
7675
@@ -80,6 +79,7 @@ router.post('/generate', jsonParser, async function (request, response) {
8079 return response.status(500).send({ error: { message: result.statusText } });
8180 }
8281
82+ /** @type {any} */
8383 const data = await result.json();
8484 const output = data?.result?.data?.json?.outputs?.[0] || '';
8585
src/endpoints/backends/text-completions.js+11 -6
@@ -28,6 +28,10 @@ export const router = express.Router();
2828 */
2929async function parseOllamaStream(jsonStream, request, response) {
3030 try {
31+ if (!jsonStream.body) {
32+ throw new Error('No body in the response');
33+ }
34+
3135 let partialData = '';
3236 jsonStream.body.on('data', (data) => {
3337 const chunk = data.toString();
@@ -153,6 +157,7 @@ router.post('/status', jsonParser, async function (request, response) {
153157 return response.status(400);
154158 }
155159
160+ /** @type {any} */
156161 let data = await modelsReply.json();
157162
158163 if (request.body.legacy_api) {
@@ -190,6 +195,7 @@ router.post('/status', jsonParser, async function (request, response) {
190195 const modelInfoReply = await fetch(modelInfoUrl, args);
191196
192197 if (modelInfoReply.ok) {
198+ /** @type {any} */
193199 const modelInfo = await modelInfoReply.json();
194200 console.log('Ooba model info:', modelInfo);
195201
@@ -206,6 +212,7 @@ router.post('/status', jsonParser, async function (request, response) {
206212 const modelInfoReply = await fetch(modelInfoUrl, args);
207213
208214 if (modelInfoReply.ok) {
215+ /** @type {any} */
209216 const modelInfo = await modelInfoReply.json();
210217 console.log('Tabby model info:', modelInfo);
211218
@@ -359,6 +366,7 @@ router.post('/generate', jsonParser, async function (request, response) {
359366 const completionsReply = await fetch(url, args);
360367
361368 if (completionsReply.ok) {
369+ /** @type {any} */
362370 const data = await completionsReply.json();
363371 console.log('Endpoint response:', data);
364372
@@ -415,7 +423,6 @@ ollama.post('/download', jsonParser, async function (request, response) {
415423 name: name,
416424 stream: false,
417425 }),
418- timeout: 0,
419426 });
420427
421428 if (!fetchResponse.ok) {
@@ -448,7 +455,6 @@ ollama.post('/caption-image', jsonParser, async function (request, response) {
448455 images: [request.body.image],
449456 stream: false,
450457 }),
451- timeout: 0,
452458 });
453459
454460 if (!fetchResponse.ok) {
@@ -456,6 +462,7 @@ ollama.post('/caption-image', jsonParser, async function (request, response) {
456462 return response.status(500).send({ error: true });
457463 }
458464
465+ /** @type {any} */
459466 const data = await fetchResponse.json();
460467 console.log('Ollama caption response:', data);
461468
@@ -487,7 +494,6 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
487494 const fetchResponse = await fetch(`${baseUrl}/completion`, {
488495 method: 'POST',
489496 headers: { 'Content-Type': 'application/json' },
490- timeout: 0,
491497 body: JSON.stringify({
492498 prompt: `USER:[img-1]${String(request.body.prompt).trim()}\nASSISTANT:`,
493499 image_data: [{ data: request.body.image, id: 1 }],
@@ -502,6 +508,7 @@ llamacpp.post('/caption-image', jsonParser, async function (request, response) {
502508 return response.status(500).send({ error: true });
503509 }
504510
511+ /** @type {any} */
505512 const data = await fetchResponse.json();
506513 console.log('LlamaCpp caption response:', data);
507514
@@ -531,7 +538,6 @@ llamacpp.post('/props', jsonParser, async function (request, response) {
531538
532539 const fetchResponse = await fetch(`${baseUrl}/props`, {
533540 method: 'GET',
534- timeout: 0,
535541 });
536542
537543 if (!fetchResponse.ok) {
@@ -566,7 +572,6 @@ llamacpp.post('/slots', jsonParser, async function (request, response) {
566572 if (request.body.action === 'info') {
567573 fetchResponse = await fetch(`${baseUrl}/slots`, {
568574 method: 'GET',
569- timeout: 0,
570575 });
571576 } else {
572577 if (!/^\d+$/.test(request.body.id_slot)) {
@@ -579,7 +584,6 @@ llamacpp.post('/slots', jsonParser, async function (request, response) {
579584 fetchResponse = await fetch(`${baseUrl}/slots/${request.body.id_slot}?action=${request.body.action}`, {
580585 method: 'POST',
581586 headers: { 'Content-Type': 'application/json' },
582- timeout: 0,
583587 body: JSON.stringify({
584588 filename: request.body.action !== 'erase' ? `${request.body.filename}` : undefined,
585589 }),
@@ -623,6 +627,7 @@ tabby.post('/download', jsonParser, async function (request, response) {
623627 });
624628
625629 if (permissionResponse.ok) {
630+ /** @type {any} */
626631 const permissionJson = await permissionResponse.json();
627632
628633 if (permissionJson['permission'] !== 'admin') {
src/endpoints/content-manager.js+2 -0
@@ -380,6 +380,7 @@ async function downloadPygmalionCharacter(id) {
380380 throw new Error('Failed to download character');
381381 }
382382
383+ /** @type {any} */
383384 const jsonData = await result.json();
384385 const characterData = jsonData?.character;
385386
@@ -472,6 +473,7 @@ async function downloadJannyCharacter(uuid) {
472473 });
473474
474475 if (result.ok) {
476+ /** @type {any} */
475477 const downloadResult = await result.json();
476478 if (downloadResult.status === 'ok') {
477479 const imageResult = await fetch(downloadResult.downloadUrl);
src/endpoints/google.js+1 -1
@@ -40,7 +40,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
4040 headers: {
4141 'Content-Type': 'application/json',
4242 },
43- timeout: 0,
4443 });
4544
4645 if (!result.ok) {
@@ -49,6 +48,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
4948 return response.status(result.status).send({ error: true });
5049 }
5150
51+ /** @type {any} */
5252 const data = await result.json();
5353 console.log('Multimodal captioning response', data);
5454
src/endpoints/images.js+1 -1
@@ -68,7 +68,7 @@ router.post('/upload', jsonParser, async (request, response) => {
6868
6969 ensureDirectoryExistence(pathToNewFile);
7070 const imageBuffer = Buffer.from(base64Data, 'base64');
7171 await fs.promises.writeFile(pathToNewFile, new Uint8Array(imageBuffer));
7272 response.send({ path: clientRelativePath(request.user.directories.root, pathToNewFile) });
7373 } catch (error) {
7474 console.log(error);
src/endpoints/novelai.js+3 -3
@@ -252,7 +252,7 @@ router.post('/generate', jsonParser, async function (req, res) {
252252 try {
253253 const baseURL = (req.body.model.includes('kayra') || req.body.model.includes('erato')) ? TEXT_NOVELAI : API_NOVELAI;
254254 const url = req.body.streaming ? `${baseURL}/ai/generate-stream` : `${baseURL}/ai/generate`;
255255 const response = await fetch(url, { method: 'POST', timeout: 0, ...args });
256256
257257 if (req.body.streaming) {
258258 // Pipe remote SSE stream to Express response
@@ -274,6 +274,7 @@ router.post('/generate', jsonParser, async function (req, res) {
274274 return res.status(response.status).send({ error: { message } });
275275 }
276276
277+ /** @type {any} */
277278 const data = await response.json();
278279 console.log('NovelAI Output', data?.output);
279280 return res.send(data);
@@ -416,7 +417,6 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
416417 'Authorization': `Bearer ${token}`,
417418 'Accept': 'audio/mpeg',
418419 },
419- timeout: 0,
420420 });
421421
422422 if (!result.ok) {
@@ -426,7 +426,7 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
426426 }
427427
428428 const chunks = await readAllChunks(result.body);
429429 const buffer = Buffer.concat(chunks.map(chunk => new Uint8Array(chunk)));
430430 response.setHeader('Content-Type', 'audio/mpeg');
431431 return response.send(buffer);
432432 }
src/endpoints/openai.js+1 -2
@@ -154,7 +154,6 @@ router.post('/caption-image', jsonParser, async (request, response) => {
154154 ...headers,
155155 },
156156 body: JSON.stringify(body),
157- timeout: 0,
158157 });
159158
160159 if (!result.ok) {
@@ -163,6 +162,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
163162 return response.status(500).send(text);
164163 }
165164
165+ /** @type {any} */
166166 const data = await result.json();
167167 console.log('Multimodal captioning response', data);
168168 const caption = data?.choices[0]?.message?.content;
@@ -284,7 +284,6 @@ router.post('/generate-image', jsonParser, async (request, response) => {
284284 Authorization: `Bearer ${key}`,
285285 },
286286 body: JSON.stringify(request.body),
287- timeout: 0,
288287 });
289288
290289 if (!result.ok) {
src/endpoints/stable-diffusion.js+20 -6
@@ -65,6 +65,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
6565 throw new Error('SD WebUI returned an error.');
6666 }
6767
68+ /** @type {any} */
6869 const data = await result.json();
6970 const names = data.map(x => x.name);
7071 return names;
@@ -85,6 +86,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
8586 throw new Error('SD WebUI returned an error.');
8687 }
8788
89+ /** @type {any} */
8890 const data = await result.json();
8991 const names = data.map(x => x.name);
9092 return names;
@@ -118,6 +120,7 @@ router.post('/vaes', jsonParser, async (request, response) => {
118120 throw new Error('SD WebUI returned an error.');
119121 }
120122
123+ /** @type {any} */
121124 const data = await result.json();
122125 const names = data.map(x => x.model_name);
123126 return response.send(names);
@@ -143,6 +146,7 @@ router.post('/samplers', jsonParser, async (request, response) => {
143146 throw new Error('SD WebUI returned an error.');
144147 }
145148
149+ /** @type {any} */
146150 const data = await result.json();
147151 const names = data.map(x => x.name);
148152 return response.send(names);
@@ -169,6 +173,7 @@ router.post('/schedulers', jsonParser, async (request, response) => {
169173 throw new Error('SD WebUI returned an error.');
170174 }
171175
176+ /** @type {any} */
172177 const data = await result.json();
173178 const names = data.map(x => x.name);
174179 return response.send(names);
@@ -194,6 +199,7 @@ router.post('/models', jsonParser, async (request, response) => {
194199 throw new Error('SD WebUI returned an error.');
195200 }
196201
202+ /** @type {any} */
197203 const data = await result.json();
198204 const models = data.map(x => ({ value: x.title, text: x.title }));
199205 return response.send(models);
@@ -214,6 +220,7 @@ router.post('/get-model', jsonParser, async (request, response) => {
214220 'Authorization': getBasicAuthHeader(request.body.auth),
215221 },
216222 });
223+ /** @type {any} */
217224 const data = await result.json();
218225 return response.send(data['sd_model_checkpoint']);
219226 } catch (error) {
@@ -233,7 +240,6 @@ router.post('/set-model', jsonParser, async (request, response) => {
233240 headers: {
234241 'Authorization': getBasicAuthHeader(request.body.auth),
235242 },
236- timeout: 0,
237243 });
238244 const data = await result.json();
239245 return data;
@@ -253,7 +259,6 @@ router.post('/set-model', jsonParser, async (request, response) => {
253259 'Content-Type': 'application/json',
254260 'Authorization': getBasicAuthHeader(request.body.auth),
255261 },
256- timeout: 0,
257262 });
258263
259264 if (!result.ok) {
@@ -264,6 +269,7 @@ router.post('/set-model', jsonParser, async (request, response) => {
264269 const CHECK_INTERVAL = 2000;
265270
266271 for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
272+ /** @type {any} */
267273 const progressState = await getProgress();
268274
269275 const progress = progressState['progress'];
@@ -308,8 +314,6 @@ router.post('/generate', jsonParser, async (request, response) => {
308314 'Content-Type': 'application/json',
309315 'Authorization': getBasicAuthHeader(request.body.auth),
310316 },
311- timeout: 0,
312- // @ts-ignore
313317 signal: controller.signal,
314318 });
315319
@@ -345,6 +349,7 @@ router.post('/sd-next/upscalers', jsonParser, async (request, response) => {
345349 // Vlad doesn't provide Latent Upscalers in the API, so we have to hardcode them here
346350 const latentUpscalers = ['Latent', 'Latent (antialiased)', 'Latent (bicubic)', 'Latent (bicubic antialiased)', 'Latent (nearest)', 'Latent (nearest-exact)'];
347351
352+ /** @type {any} */
348353 const data = await result.json();
349354 const names = data.map(x => x.name);
350355
@@ -387,6 +392,7 @@ comfy.post('/samplers', jsonParser, async (request, response) => {
387392 throw new Error('ComfyUI returned an error.');
388393 }
389394
395+ /** @type {any} */
390396 const data = await result.json();
391397 return response.send(data.KSampler.input.required.sampler_name[0]);
392398 } catch (error) {
@@ -404,6 +410,7 @@ comfy.post('/models', jsonParser, async (request, response) => {
404410 if (!result.ok) {
405411 throw new Error('ComfyUI returned an error.');
406412 }
413+ /** @type {any} */
407414 const data = await result.json();
408415 return response.send(data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })));
409416 } catch (error) {
@@ -422,6 +429,7 @@ comfy.post('/schedulers', jsonParser, async (request, response) => {
422429 throw new Error('ComfyUI returned an error.');
423430 }
424431
432+ /** @type {any} */
425433 const data = await result.json();
426434 return response.send(data.KSampler.input.required.scheduler[0]);
427435 } catch (error) {
@@ -440,6 +448,7 @@ comfy.post('/vaes', jsonParser, async (request, response) => {
440448 throw new Error('ComfyUI returned an error.');
441449 }
442450
451+ /** @type {any} */
443452 const data = await result.json();
444453 return response.send(data.VAELoader.input.required.vae_name[0]);
445454 } catch (error) {
@@ -521,6 +530,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
521530 throw new Error('ComfyUI returned an error.');
522531 }
523532
533+ /** @type {any} */
524534 const data = await promptResult.json();
525535 const id = data.prompt_id;
526536 let item;
@@ -531,6 +541,7 @@ comfy.post('/generate', jsonParser, async (request, response) => {
531541 if (!result.ok) {
532542 throw new Error('ComfyUI returned an error.');
533543 }
544+ /** @type {any} */
534545 const history = await result.json();
535546 item = history[id];
536547 if (item) {
@@ -633,6 +644,7 @@ together.post('/generate', jsonParser, async (request, response) => {
633644 return response.sendStatus(500);
634645 }
635646
647+ /** @type {any} */
636648 const data = await result.json();
637649 console.log('TogetherAI response:', data);
638650
@@ -681,6 +693,8 @@ drawthings.post('/get-model', jsonParser, async (request, response) => {
681693 const result = await fetch(url, {
682694 method: 'GET',
683695 });
696+
697+ /** @type {any} */
684698 const data = await result.json();
685699
686700 return response.send(data['model']);
@@ -698,6 +712,8 @@ drawthings.post('/get-upscaler', jsonParser, async (request, response) => {
698712 const result = await fetch(url, {
699713 method: 'GET',
700714 });
715+
716+ /** @type {any} */
701717 const data = await result.json();
702718
703719 return response.send(data['upscaler']);
@@ -726,7 +742,6 @@ drawthings.post('/generate', jsonParser, async (request, response) => {
726742 'Content-Type': 'application/json',
727743 'Authorization': auth,
728744 },
729- timeout: 0,
730745 });
731746
732747 if (!result.ok) {
@@ -848,7 +863,6 @@ stability.post('/generate', jsonParser, async (request, response) => {
848863 'Accept': 'image/*',
849864 },
850865 body: formData,
851- timeout: 0,
852866 });
853867
854868 if (!result.ok) {
src/endpoints/translate.js+5 -4
@@ -78,6 +78,7 @@ router.post('/libre', jsonParser, async (request, response) => {
7878 return response.sendStatus(result.status);
7979 }
8080
81+ /** @type {any} */
8182 const json = await result.json();
8283 console.log('Translated text: ' + json.translatedText);
8384
@@ -158,7 +159,6 @@ router.post('/yandex', jsonParser, async (request, response) => {
158159 headers: {
159160 'Content-Type': 'application/x-www-form-urlencoded',
160161 },
161- timeout: 0,
162162 });
163163
164164 if (!result.ok) {
@@ -167,6 +167,7 @@ router.post('/yandex', jsonParser, async (request, response) => {
167167 return response.sendStatus(500);
168168 }
169169
170+ /** @type {any} */
170171 const json = await result.json();
171172 const translated = json.text.join();
172173 console.log('Translated text: ' + translated);
@@ -264,7 +265,6 @@ router.post('/deepl', jsonParser, async (request, response) => {
264265 'Authorization': `DeepL-Auth-Key ${key}`,
265266 'Content-Type': 'application/x-www-form-urlencoded',
266267 },
267- timeout: 0,
268268 });
269269
270270 if (!result.ok) {
@@ -273,6 +273,7 @@ router.post('/deepl', jsonParser, async (request, response) => {
273273 return response.sendStatus(result.status);
274274 }
275275
276+ /** @type {any} */
276277 const json = await result.json();
277278 console.log('Translated text: ' + json.translations[0].text);
278279
@@ -317,7 +318,6 @@ router.post('/onering', jsonParser, async (request, response) => {
317318
318319 const result = await fetch(fetchUrl, {
319320 method: 'GET',
320- timeout: 0,
321321 });
322322
323323 if (!result.ok) {
@@ -326,6 +326,7 @@ router.post('/onering', jsonParser, async (request, response) => {
326326 return response.sendStatus(result.status);
327327 }
328328
329+ /** @type {any} */
329330 const data = await result.json();
330331 console.log('Translated text: ' + data.result);
331332
@@ -373,7 +374,6 @@ router.post('/deeplx', jsonParser, async (request, response) => {
373374 'Accept': 'application/json',
374375 'Content-Type': 'application/json',
375376 },
376- timeout: 0,
377377 });
378378
379379 if (!result.ok) {
@@ -382,6 +382,7 @@ router.post('/deeplx', jsonParser, async (request, response) => {
382382 return response.sendStatus(result.status);
383383 }
384384
385+ /** @type {any} */
385386 const json = await result.json();
386387 console.log('Translated text: ' + json.data);
387388
src/transformers.mjs+3 -2
@@ -3,7 +3,7 @@ import fs from 'node:fs';
33import process from 'node:process';
44import { Buffer } from 'node:buffer';
55
66import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers';
77import { getConfigValue } from './util.js';
88
99configureTransformers();
@@ -117,7 +117,7 @@ async function migrateCacheToDataDir() {
117117 * Gets the transformers.js pipeline for a given task.
118118 * @param {import('sillytavern-transformers').PipelineType} task The task to get the pipeline for
119119 * @param {string} forceModel The model to use for the pipeline, if any
120120 * @returns {Promise<import('sillytavern-transformers').Pipeline>} Pipeline forThe thetransformers.js taskpipeline
121121 */
122122export async function getPipeline(task, forceModel = '') {
123123 await migrateCacheToDataDir();
@@ -137,6 +137,7 @@ export async function getPipeline(task, forceModel = '') {
137137 const instance = await pipeline(task, model, { cache_dir: cacheDir, quantized: tasks[task].quantized ?? true, local_files_only: localOnly });
138138 tasks[task].pipeline = instance;
139139 tasks[task].currentModel = model;
140+ // @ts-ignore
140141 return instance;
141142}
142143
src/util.js+12 -8
@@ -441,17 +441,21 @@ export function forwardFetchResponse(from, to) {
441441 to.statusCode = statusCode;
442442 to.statusMessage = statusText;
443443
444- from.body.pipe(to);
444+ if (from.body && to.socket) {
445+ from.body.pipe(to);
445446
446447 to.socket.on('close', function () {
447448 if (from.body instanceof Readable) from.body.destroy(); // Close the remote stream
448449 to.end(); // End the Express response
449450 });
450451
451452 from.body.on('end', function () {
452453 console.log('Streaming request finished');
454+ to.end();
455+ });
456+ } else {
453457 to.end();
454458 });
455459}
456460
457461/**
src/vectors/cohere-vectors.js+1 -0
@@ -38,6 +38,7 @@ export async function getCohereBatchVector(texts, isQuery, directories, model) {
3838 throw new Error('API request failed');
3939 }
4040
41+ /** @type {any} */
4142 const data = await response.json();
4243 if (!Array.isArray(data?.embeddings?.float)) {
4344 console.log('API response was not an array');
src/vectors/extras-vectors.js+1 -0
@@ -66,6 +66,7 @@ async function getExtrasVectorImpl(text, apiUrl, apiKey) {
6666 throw new Error('Extras request failed');
6767 }
6868
69+ /** @type {any} */
6970 const data = await response.json();
7071 const vector = data.embedding; // `embedding`: number[] (one text item), or number[][] (multiple text items).
7172
src/vectors/llamacpp-vectors.js+1 -0
@@ -30,6 +30,7 @@ export async function getLlamaCppBatchVector(texts, apiUrl, directories) {
3030 throw new Error(`LlamaCpp: Failed to get vector for text: ${response.statusText} ${responseText}`);
3131 }
3232
33+ /** @type {any} */
3334 const data = await response.json();
3435
3536 if (!Array.isArray(data?.data)) {
src/vectors/makersuite-vectors.js+1 -0
@@ -52,6 +52,7 @@ export async function getMakerSuiteVector(text, directories) {
5252 throw new Error('Google AI Studio request failed');
5353 }
5454
55+ /** @type {any} */
5556 const data = await response.json();
5657 // noinspection JSValidateTypes
5758 return data['embedding']['values'];
src/vectors/nomicai-vectors.js+1 -0
@@ -51,6 +51,7 @@ export async function getNomicAIBatchVector(texts, source, directories) {
5151 throw new Error('API request failed');
5252 }
5353
54+ /** @type {any} */
5455 const data = await response.json();
5556 if (!Array.isArray(data?.embeddings)) {
5657 console.log('API response was not an array');
src/vectors/ollama-vectors.js+1 -0
@@ -54,6 +54,7 @@ export async function getOllamaVector(text, apiUrl, model, keep, directories) {
5454 throw new Error(`Ollama: Failed to get vector for text: ${response.statusText} ${responseText}`);
5555 }
5656
57+ /** @type {any} */
5758 const data = await response.json();
5859
5960 if (!Array.isArray(data?.embedding)) {
src/vectors/openai-vectors.js+1 -0
@@ -61,6 +61,7 @@ export async function getOpenAIBatchVector(texts, source, directories, model = '
6161 throw new Error('API request failed');
6262 }
6363
64+ /** @type {any} */
6465 const data = await response.json();
6566
6667 if (!Array.isArray(data?.data)) {
src/vectors/vllm-vectors.js+1 -0
@@ -31,6 +31,7 @@ export async function getVllmBatchVector(texts, apiUrl, model, directories) {
3131 throw new Error(`VLLM: Failed to get vector for text: ${response.statusText} ${responseText}`);
3232 }
3333
34+ /** @type {any} */
3435 const data = await response.json();
3536
3637 if (!Array.isArray(data?.data)) {