diff --git a/library_service/static/page/create_book.js b/library_service/static/page/create_book.js
index 6b86a02..8c7c88a 100644
--- a/library_service/static/page/create_book.js
+++ b/library_service/static/page/create_book.js
@@ -398,6 +398,8 @@ $(document).ready(() => {
let curInfoEl = null;
let lastType = null;
let idleTimer = null;
+ let thinkTimer = null;
+ let thinkStartTime = null;
const twQueues = new Map();
@@ -519,31 +521,65 @@ $(document).ready(() => {
}
}
+ function formatThinkTime(sec) {
+ if (sec < 60) {
+ return sec.toFixed(1) + "с";
+ }
+ const m = Math.floor(sec / 60);
+ const s = Math.floor(sec % 60);
+ return m + "м " + String(s).padStart(2, "0") + "с";
+ }
+
function addThinkBlock() {
const id = "ai-t-" + Date.now();
$logEntries.append(`
-
-
-
+
+
+
+
+ Думает
+
+
+
+ 0.0с
+
+
+
- `);
+
+
+ `);
+
$(`[data-toggle="${id}-b"]`).on("click", function () {
$(`#${id}-b`).toggleClass("hidden");
$(this).find(".ai-t-chev").toggleClass("rotate-180");
});
+
curThinkEl = $(`#${id}`);
scrollLog();
+
+ thinkStartTime = performance.now();
+ clearInterval(thinkTimer);
+ thinkTimer = setInterval(() => {
+ if (!curThinkEl) return;
+ const elapsed = (performance.now() - thinkStartTime) / 1000;
+ curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed));
+ }, 100);
}
function appendThink(text) {
@@ -557,14 +593,26 @@ $(document).ready(() => {
function endThink() {
if (!curThinkEl) return;
+
+ clearInterval(thinkTimer);
+ thinkTimer = null;
+
+ if (thinkStartTime) {
+ const elapsed = (performance.now() - thinkStartTime) / 1000;
+ curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed));
+ thinkStartTime = null;
+ }
+
const p = curThinkEl.find(".ai-t-txt")[0];
twFlush(p);
curThinkEl.find(".ai-t-txt").removeClass("typing-cursor");
curThinkEl.find(".ai-t-spin").removeClass("animate-spin").html(`
-
- `);
+
+ `);
const id = curThinkEl.attr("id");
if (id) {
@@ -645,6 +693,10 @@ $(document).ready(() => {
}
function hideWidget() {
+ clearInterval(thinkTimer);
+ thinkTimer = null;
+ thinkStartTime = null;
+
$aiWidget.addClass("hidden");
$logWrap.addClass("hidden");
$logEntries.empty();
diff --git a/library_service/static/page/edit_book.js b/library_service/static/page/edit_book.js
index 021f3d8..9027d2d 100644
--- a/library_service/static/page/edit_book.js
+++ b/library_service/static/page/edit_book.js
@@ -503,6 +503,8 @@ $(document).ready(() => {
let curInfoEl = null;
let lastType = null;
let idleTimer = null;
+ let thinkTimer = null;
+ let thinkStartTime = null;
const twQueues = new Map();
@@ -611,7 +613,6 @@ $(document).ready(() => {
title: $titleInput.val() || null,
description: $descInput.val() || null,
page_count: $pagesInput.val() ? parseInt($pagesInput.val(), 10) : null,
- status: $statusSelect.val() || "active",
};
}
@@ -625,31 +626,65 @@ $(document).ready(() => {
}
}
+ function formatThinkTime(sec) {
+ if (sec < 60) {
+ return sec.toFixed(1) + "с";
+ }
+ const m = Math.floor(sec / 60);
+ const s = Math.floor(sec % 60);
+ return m + "м " + String(s).padStart(2, "0") + "с";
+ }
+
function addThinkBlock() {
const id = "ai-t-" + Date.now();
$logEntries.append(`
-
-
-
+
+
+
+
+ Думает
+
+
+
+ 0.0с
+
+
+
- `);
+
+
+ `);
+
$(`[data-toggle="${id}-b"]`).on("click", function () {
$(`#${id}-b`).toggleClass("hidden");
$(this).find(".ai-t-chev").toggleClass("rotate-180");
});
+
curThinkEl = $(`#${id}`);
scrollLog();
+
+ thinkStartTime = performance.now();
+ clearInterval(thinkTimer);
+ thinkTimer = setInterval(() => {
+ if (!curThinkEl) return;
+ const elapsed = (performance.now() - thinkStartTime) / 1000;
+ curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed));
+ }, 100);
}
function appendThink(text) {
@@ -663,14 +698,26 @@ $(document).ready(() => {
function endThink() {
if (!curThinkEl) return;
+
+ clearInterval(thinkTimer);
+ thinkTimer = null;
+
+ if (thinkStartTime) {
+ const elapsed = (performance.now() - thinkStartTime) / 1000;
+ curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed));
+ thinkStartTime = null;
+ }
+
const p = curThinkEl.find(".ai-t-txt")[0];
twFlush(p);
curThinkEl.find(".ai-t-txt").removeClass("typing-cursor");
curThinkEl.find(".ai-t-spin").removeClass("animate-spin").html(`
-
- `);
+
+ `);
const id = curThinkEl.attr("id");
if (id) {
@@ -751,6 +798,10 @@ $(document).ready(() => {
}
function hideWidget() {
+ clearInterval(thinkTimer);
+ thinkTimer = null;
+ thinkStartTime = null;
+
$aiWidget.addClass("hidden");
$logWrap.addClass("hidden");
$logEntries.empty();