@lzhzzzzwill/cofos 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cofos.js +36 -4
- package/package.json +1 -1
package/bin/cofos.js
CHANGED
|
@@ -207,6 +207,8 @@ function createTui() {
|
|
|
207
207
|
|
|
208
208
|
let buffer = "";
|
|
209
209
|
let onSubmit = () => {};
|
|
210
|
+
let onExit = () => {};
|
|
211
|
+
let submitting = false;
|
|
210
212
|
let suggestionMatches = [];
|
|
211
213
|
let selectedSuggestion = 0;
|
|
212
214
|
|
|
@@ -268,6 +270,8 @@ function createTui() {
|
|
|
268
270
|
}
|
|
269
271
|
|
|
270
272
|
function submitInput() {
|
|
273
|
+
if (submitting) return;
|
|
274
|
+
submitting = true;
|
|
271
275
|
let value = input.getValue();
|
|
272
276
|
if (!suggestions.hidden && selectedCommand()) value = selectedCommand();
|
|
273
277
|
hideSuggestions();
|
|
@@ -275,9 +279,11 @@ function createTui() {
|
|
|
275
279
|
input.focus();
|
|
276
280
|
screen.render();
|
|
277
281
|
onSubmit(String(value || ""));
|
|
282
|
+
setTimeout(() => { submitting = false; }, 0);
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
input.key(["enter"], submitInput);
|
|
286
|
+
screen.key(["enter"], submitInput);
|
|
281
287
|
|
|
282
288
|
input.on("keypress", (_ch, key = {}) => {
|
|
283
289
|
if (["up", "down", "tab", "enter", "escape"].includes(key.name)) return;
|
|
@@ -308,7 +314,7 @@ function createTui() {
|
|
|
308
314
|
});
|
|
309
315
|
|
|
310
316
|
screen.key(["escape"], hideSuggestions);
|
|
311
|
-
screen.key(["C-c"], () =>
|
|
317
|
+
screen.key(["C-c"], () => onExit());
|
|
312
318
|
|
|
313
319
|
input.focus();
|
|
314
320
|
screen.render();
|
|
@@ -319,6 +325,8 @@ function createTui() {
|
|
|
319
325
|
append,
|
|
320
326
|
print: (text = "") => append(String(text) + "\n"),
|
|
321
327
|
setSubmitHandler: (fn) => { onSubmit = fn; },
|
|
328
|
+
setExitHandler: (fn) => { onExit = fn; },
|
|
329
|
+
focus: () => { input.focus(); screen.render(); },
|
|
322
330
|
setPrompt: (label) => { input.setLabel(` ${label} `); screen.render(); },
|
|
323
331
|
destroy: () => screen.destroy(),
|
|
324
332
|
};
|
|
@@ -423,7 +431,7 @@ function main() {
|
|
|
423
431
|
proc.stdout.setEncoding("utf-8");
|
|
424
432
|
proc.stderr.setEncoding("utf-8");
|
|
425
433
|
|
|
426
|
-
let buf = "", ready = false, generating = false, responseOpen = false, closed = false;
|
|
434
|
+
let buf = "", ready = false, generating = false, responseOpen = false, commandOpen = false, closed = false;
|
|
427
435
|
const inputQ = [];
|
|
428
436
|
let mlBuf = [];
|
|
429
437
|
|
|
@@ -435,6 +443,7 @@ function main() {
|
|
|
435
443
|
ui.destroy();
|
|
436
444
|
}
|
|
437
445
|
|
|
446
|
+
ui.setExitHandler(shutdown);
|
|
438
447
|
process.on("SIGTERM", shutdown);
|
|
439
448
|
process.on("SIGINT", shutdown);
|
|
440
449
|
|
|
@@ -470,6 +479,14 @@ function main() {
|
|
|
470
479
|
if (/^\/(clear)$/.test(input)) {
|
|
471
480
|
mlBuf = [];
|
|
472
481
|
responseOpen = false;
|
|
482
|
+
commandOpen = true;
|
|
483
|
+
proc.stdin.write(input + "\n");
|
|
484
|
+
generating = true;
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
if (/^\/(topk)(?:\s+\d+)?$/.test(input) || /^\/rag\s+(?:on|off)$/.test(input)) {
|
|
488
|
+
responseOpen = false;
|
|
489
|
+
commandOpen = true;
|
|
473
490
|
proc.stdin.write(input + "\n");
|
|
474
491
|
generating = true;
|
|
475
492
|
return true;
|
|
@@ -479,7 +496,7 @@ function main() {
|
|
|
479
496
|
return false;
|
|
480
497
|
}
|
|
481
498
|
|
|
482
|
-
ui.print(Y + "●
|
|
499
|
+
ui.print(Y + "● " + R + input);
|
|
483
500
|
responseOpen = false;
|
|
484
501
|
generating = true;
|
|
485
502
|
proc.stdin.write(input + "\n");
|
|
@@ -507,6 +524,20 @@ function main() {
|
|
|
507
524
|
}
|
|
508
525
|
if (!generating) { buf = ""; return; }
|
|
509
526
|
|
|
527
|
+
if (commandOpen) {
|
|
528
|
+
const di = buf.indexOf(DONE);
|
|
529
|
+
if (di === -1) return;
|
|
530
|
+
const pre = buf.slice(0, di).trim();
|
|
531
|
+
if (pre) ui.print(G + "• " + R + pre);
|
|
532
|
+
buf = buf.slice(di + DONE.length);
|
|
533
|
+
if (buf[0] === "\n") buf = buf.slice(1);
|
|
534
|
+
generating = false;
|
|
535
|
+
commandOpen = false;
|
|
536
|
+
ui.focus();
|
|
537
|
+
drain();
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
510
541
|
if (!responseOpen) {
|
|
511
542
|
const ri = buf.indexOf(RESPONSE);
|
|
512
543
|
if (ri === -1) {
|
|
@@ -517,7 +548,7 @@ function main() {
|
|
|
517
548
|
buf = buf.slice(ri + RESPONSE.length);
|
|
518
549
|
if (buf[0] === "\n") buf = buf.slice(1);
|
|
519
550
|
responseOpen = true;
|
|
520
|
-
ui.append(GR + "◆ COFOS" + R
|
|
551
|
+
ui.append(GR + B + "◆ COFOS " + R);
|
|
521
552
|
}
|
|
522
553
|
|
|
523
554
|
const di = buf.indexOf(DONE);
|
|
@@ -529,6 +560,7 @@ function main() {
|
|
|
529
560
|
generating = false;
|
|
530
561
|
responseOpen = false;
|
|
531
562
|
ui.append("\n");
|
|
563
|
+
ui.focus();
|
|
532
564
|
drain();
|
|
533
565
|
} else {
|
|
534
566
|
const keep = DONE.length - 1;
|