PR fixes
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { getRequestHeaders, substituteParams } from '../../../../script.js'; |
| 2 | 2 | import { Popup, POPUP_RESULT, POPUP_TYPE } from '../../../popup.js'; |
| 3 | 3 | import { executeSlashCommandsOnChatInput, executeSlashCommandsWithOptions } from '../../../slash-commands.js'; |
| 4 | +import { SlashCommandScope } from '../../../slash-commands/SlashCommandScope.js'; | |
| 4 | 5 | import { SlashCommandParser } from '../../../slash-commands/SlashCommandParser.js'; |
| 5 | 6 | import { debounceAsync, warn } from '../index.js'; |
| 6 | 7 | import { QuickReply } from './QuickReply.js'; |
| @@ -1443,9 +1443,7 @@ async function sendWindowAIRequest(messages, signal, stream) { | ||
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | const onStreamResult = (res, err) => { |
| 1446 | 1446 | if (err) {return; |
| 1447 | - return; | |
| 1448 | - } | |
| 1449 | 1447 | |
| 1450 | 1448 | const thisContent = res?.message?.content; |
| 1451 | 1449 | |
| @@ -224,9 +224,7 @@ router.post('/download', jsonParser, async (request, response) => { | ||
| 224 | 224 | // Delete if previous download failed |
| 225 | 225 | if (fs.existsSync(temp_path)) { |
| 226 | 226 | fs.unlink(temp_path, (err) => { |
| 227 | 227 | if (err) {throw err; |
| 228 | - throw err; | |
| 229 | - } | |
| 230 | 228 | }); |
| 231 | 229 | } |
| 232 | 230 | const fileStream = fs.createWriteStream(destination, { flags: 'wx' }); |
| @@ -288,9 +286,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 288 | 286 | // Delete if previous download failed |
| 289 | 287 | if (fs.existsSync(file_path)) { |
| 290 | 288 | fs.unlink(file_path, (err) => { |
| 291 | 289 | if (err) {throw err; |
| 292 | - throw err; | |
| 293 | - } | |
| 294 | 290 | }); |
| 295 | 291 | console.info('Asset deleted.'); |
| 296 | 292 | } |
| @@ -317,9 +313,7 @@ router.post('/delete', jsonParser, async (request, response) => { | ||
| 317 | 313 | * @returns {void} |
| 318 | 314 | */ |
| 319 | 315 | router.post('/character', jsonParser, async (request, response) => { |
| 320 | 316 | if (request.query.name === undefined) {return response.sendStatus(400); |
| 321 | - return response.sendStatus(400); | |
| 322 | - } | |
| 323 | 317 | |
| 324 | 318 | // For backwards compatibility, don't reject invalid character names, just sanitize them |
| 325 | 319 | const name = sanitize(request.query.name.toString()); |
| @@ -327,11 +321,9 @@ router.post('/character', jsonParser, async (request, response) => { | ||
| 327 | 321 | |
| 328 | 322 | // Check category |
| 329 | 323 | let category = null; |
| 330 | 324 | for (let i of VALID_CATEGORIES) { |
| 331 | 325 | if (i == inputCategory) { |
| 332 | 326 | category = i; |
| 333 | - } | |
| 334 | - } | |
| 335 | 327 | |
| 336 | 328 | if (category === null) { |
| 337 | 329 | console.error('Bad request: unsupported asset category.'); |
| @@ -348,9 +340,7 @@ router.post('/character', jsonParser, async (request, response) => { | ||
| 348 | 340 | if (category == 'live2d') { |
| 349 | 341 | const folders = fs.readdirSync(folderPath, { withFileTypes: true }); |
| 350 | 342 | for (const folderInfo of folders) { |
| 351 | 343 | if (!folderInfo.isDirectory()) {continue; |
| 352 | - continue; | |
| 353 | - } | |
| 354 | 344 | |
| 355 | 345 | const modelFolder = folderInfo.name; |
| 356 | 346 | const live2dModelPath = path.join(folderPath, modelFolder); |
| @@ -418,9 +418,7 @@ async function sendMakerSuiteRequest(request, response) { | ||
| 418 | 418 | * @param {express.Response} response Express response |
| 419 | 419 | */ |
| 420 | 420 | async function sendAI21Request(request, response) { |
| 421 | 421 | if (!request.body) {return response.sendStatus(400); |
| 422 | - return response.sendStatus(400); | |
| 423 | - } | |
| 424 | 422 | |
| 425 | 423 | const controller = new AbortController(); |
| 426 | 424 | console.debug(request.body.messages); |
| @@ -848,7 +846,8 @@ router.post('/status', jsonParser, async function (request, response_getstatus_o | ||
| 848 | 846 | }); |
| 849 | 847 | |
| 850 | 848 | router.post('/bias', jsonParser, async function (request, response) { |
| 851 | 849 | if (!request.body || !Array.isArray(request.body)) return response.sendStatus(400); |
| 850 | + return response.sendStatus(400); | |
| 852 | 851 | |
| 853 | 852 | try { |
| 854 | 853 | const result = {}; |
| @@ -202,8 +202,7 @@ router.post('/transcribe-audio', urlencodedParser, async function (request, resp | ||
| 202 | 202 | return response.sendStatus(400); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | console.infodebug('Transcribing audio with KoboldCpp', server); |
| 206 | - console.debug(server); | |
| 207 | 206 | |
| 208 | 207 | const fileBase64 = fs.readFileSync(request.file.path).toString('base64'); |
| 209 | 208 | fs.rmSync(request.file.path); |
| @@ -101,8 +101,7 @@ router.post('/status', jsonParser, async function (request, response) { | ||
| 101 | 101 | request.body.api_server = request.body.api_server.replace('localhost', '127.0.0.1'); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | console.infodebug('Trying to connect to API', request.body); |
| 105 | - console.debug(request.body); | |
| 106 | 105 | const baseUrl = trimV1(request.body.api_server); |
| 107 | 106 | |
| 108 | 107 | const args = { |
| @@ -229,9 +228,7 @@ router.post('/status', jsonParser, async function (request, response) { | ||
| 229 | 228 | }); |
| 230 | 229 | |
| 231 | 230 | router.post('/props', jsonParser, async function (request, response) { |
| 232 | 231 | if (!request.body.api_server) {return response.sendStatus(400); |
| 233 | - return response.sendStatus(400); | |
| 234 | - } | |
| 235 | 232 | |
| 236 | 233 | try { |
| 237 | 234 | const baseUrl = trimV1(request.body.api_server); |
| @@ -265,9 +262,7 @@ router.post('/props', jsonParser, async function (request, response) { | ||
| 265 | 262 | }); |
| 266 | 263 | |
| 267 | 264 | router.post('/generate', jsonParser, async function (request, response) { |
| 268 | 265 | if (!request.body) {return response.sendStatus(400); |
| 269 | - return response.sendStatus(400); | |
| 270 | - } | |
| 271 | 266 | |
| 272 | 267 | try { |
| 273 | 268 | if (request.body.api_server.indexOf('localhost') !== -1) { |
| @@ -435,9 +430,7 @@ const ollama = express.Router(); | ||
| 435 | 430 | |
| 436 | 431 | ollama.post('/download', jsonParser, async function (request, response) { |
| 437 | 432 | try { |
| 438 | 433 | if (!request.body.name || !request.body.api_server) {return response.sendStatus(400); |
| 439 | - return response.sendStatus(400); | |
| 440 | - } | |
| 441 | 434 | |
| 442 | 435 | const name = request.body.name; |
| 443 | 436 | const url = String(request.body.api_server).replace(/\/$/, ''); |
| @@ -20,7 +20,7 @@ router.post('/', jsonParser, async (req, res) => { | ||
| 20 | 20 | const pipe = await getPipeline(TASK); |
| 21 | 21 | const result = await pipe(rawImage); |
| 22 | 22 | const text = result[0].generated_text; |
| 23 | 23 | console.debuginfo('Image caption:', text); |
| 24 | 24 | |
| 25 | 25 | return res.json({ caption: text }); |
| 26 | 26 | } catch (error) { |
| @@ -52,7 +52,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { | ||
| 52 | 52 | |
| 53 | 53 | /** @type {any} */ |
| 54 | 54 | const data = await result.json(); |
| 55 | 55 | console.debuginfo('Multimodal captioning response', data); |
| 56 | 56 | |
| 57 | 57 | const candidates = data?.candidates; |
| 58 | 58 | if (!candidates) { |
| @@ -364,12 +364,12 @@ router.post('/generate-image', jsonParser, async (request, response) => { | ||
| 364 | 364 | return response.sendStatus(400); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | console.debuginfo('Horde image generation request:', generation); |
| 368 | 368 | |
| 369 | 369 | const controller = new AbortController(); |
| 370 | 370 | request.socket.removeAllListeners('close'); |
| 371 | 371 | request.socket.on('close', function () { |
| 372 | 372 | console.infowarn('Horde image generation request aborted.'); |
| 373 | 373 | controller.abort(); |
| 374 | 374 | if (generation.id) ai_horde.deleteImageGenerationRequest(generation.id); |
| 375 | 375 | }); |
| @@ -276,7 +276,7 @@ router.post('/generate', jsonParser, async function (req, res) { | ||
| 276 | 276 | |
| 277 | 277 | /** @type {any} */ |
| 278 | 278 | const data = await response.json(); |
| 279 | 279 | console.debuginfo('NovelAI Output', data?.output); |
| 280 | 280 | return res.send(data); |
| 281 | 281 | } |
| 282 | 282 | } catch (error) { |
| @@ -164,7 +164,7 @@ router.post('/caption-image', jsonParser, async (request, response) => { | ||
| 164 | 164 | |
| 165 | 165 | /** @type {any} */ |
| 166 | 166 | const data = await result.json(); |
| 167 | 167 | console.debuginfo('Multimodal captioning response', data); |
| 168 | 168 | const caption = data?.choices[0]?.message?.content; |
| 169 | 169 | |
| 170 | 170 | if (!caption) { |
| @@ -43,8 +43,8 @@ router.post('/recognize', jsonParser, async (req, res) => { | ||
| 43 | 43 | const start = performance.now(); |
| 44 | 44 | const result = await pipe(wav, { language: lang || null, task: 'transcribe' }); |
| 45 | 45 | const end = performance.now(); |
| 46 | 46 | console.debuginfo(`Execution duration: ${(end - start) / 1000} seconds`); |
| 47 | 47 | console.debuginfo('Transcribed audio:', result.text); |
| 48 | 48 | |
| 49 | 49 | return res.json({ text: result.text }); |
| 50 | 50 | } catch (error) { |
| @@ -35,7 +35,7 @@ function decodeBuffer(buffer) { | ||
| 35 | 35 | try { |
| 36 | 36 | return iconv.decode(Buffer.from(buffer), 'utf-8'); |
| 37 | 37 | } catch (error) { |
| 38 | 38 | console.warnerror('Failed to decode buffer:', error); |
| 39 | 39 | return Buffer.from(buffer).toString('utf-8'); |
| 40 | 40 | } |
| 41 | 41 | } |
| @@ -165,9 +165,7 @@ export function formatBytes(bytes) { | ||
| 165 | 165 | */ |
| 166 | 166 | export async function extractFileFromZipBuffer(archiveBuffer, fileExtension) { |
| 167 | 167 | return await new Promise((resolve, reject) => yauzl.fromBuffer(Buffer.from(archiveBuffer), { lazyEntries: true }, (err, zipfile) => { |
| 168 | 168 | if (err) {reject(err); |
| 169 | - reject(err); | |
| 170 | - } | |
| 171 | 169 | |
| 172 | 170 | zipfile.readEntry(); |
| 173 | 171 | zipfile.on('entry', (entry) => { |
| @@ -469,9 +467,8 @@ export function forwardFetchResponse(from, to) { | ||
| 469 | 467 | from.body.pipe(to); |
| 470 | 468 | |
| 471 | 469 | to.socket.on('close', function () { |
| 472 | 470 | if (from.body instanceof Readable) {from.body.destroy(); // Close the remote stream |
| 473 | - from.body.destroy(); // Close the remote stream | |
| 471 | + | |
| 474 | - } | |
| 475 | 472 | to.end(); // End the Express response |
| 476 | 473 | }); |
| 477 | 474 | |