@double_geste/agent-standup 1.37.0 → 1.39.0
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/README.md +2 -2
- package/bin/agent-standup.js +5 -3
- package/kokoro.js +2 -1
- package/package.json +1 -1
- package/public/index.html +247 -96
- package/public/locales/da.json +48 -10
- package/public/locales/de.json +48 -10
- package/public/locales/en.json +47 -9
- package/public/locales/es.json +48 -10
- package/public/locales/ja.json +48 -10
- package/public/locales/ko.json +48 -10
- package/public/locales/pt-BR.json +48 -10
- package/public/locales/zh-CN.json +48 -10
- package/public/locales/zh-TW.json +48 -10
- package/server.js +53 -12
package/server.js
CHANGED
|
@@ -367,6 +367,23 @@ const feedSince = (entry, after) => { const ev = entry.tl.events, sq = entry.sq,
|
|
|
367
367
|
const readTail = (file, bytes) => { const fd = fs.openSync(file, 'r'); try { const sz = fs.fstatSync(fd).size, n = Math.min(bytes, sz), buf = Buffer.alloc(n); fs.readSync(fd, buf, 0, n, sz - n); return { text: buf.toString('utf8'), cut: sz > bytes }; } finally { fs.closeSync(fd); } };
|
|
368
368
|
const readHead = (file, bytes) => { const fd = fs.openSync(file, 'r'); try { const n = Math.min(bytes, fs.fstatSync(fd).size), buf = Buffer.alloc(n); fs.readSync(fd, buf, 0, n, 0); return buf.toString('utf8'); } finally { fs.closeSync(fd); } };
|
|
369
369
|
const APPROVAL = /^(Edit|Write|MultiEdit|NotebookEdit)/, ASKS = /^(AskUserQuestion|ExitPlanMode)/, SUBTOOL = /^(Task|Agent)$/;
|
|
370
|
+
// A turn that ended without doing what was asked ("I couldn't verify how old the posts were, so 0 drafts"): to the eye, the same "your turn" as one that did. It says so in its first sentence;
|
|
371
|
+
// later on, "I couldn't" is mostly a caveat on work that was done ("Done. I couldn't test on Windows"), and so is a first sentence that says what worked before a "but". On 1,676 real ends of turn
|
|
372
|
+
// this flags 11, each a real "could not". A turn that ended on an error Claude Code wrote itself (the API, the login, the limit) is one too; "No response requested." is not.
|
|
373
|
+
const GAVE = /\b(?:I|we) (?:couldn't|could not|can't|cannot|wasn't able to|was unable to|am unable to|'m unable to|was not able to|failed to|did not manage|didn't manage)\b|\b(?:gave up|giving up|unable to (?:proceed|continue|complete))\b|je n'ai pas (?:pu|réussi)|\bimpossible de\b|\bje ne (?:peux|parviens|suis pas parvenu)|je n'arrive pas|\bno (?:pude|he podido|puedo|logré)\b|\bnão (?:consegui|posso|pude)\b|\bich (?:konnte|kann) (?:\S+ )?nicht\b/i;
|
|
374
|
+
// "I couldn't find any bugs", "I can't see a problem with it", "I can't reproduce it: it already works": a check that came out clean, not work left undone.
|
|
375
|
+
const CLEAN = /^\s+(?:(?:find|see|spot|detect|identify|trouver|voir|repérer|détecter|relever)\b[^.!?,;:]{0,30}?\b(?:bugs?|issues?|problems?|errors?|regressions?|mistakes?|flaws?|faults?|wrong|problèmes?|erreurs?|soucis|anomalies?|fautes?)\b|(?:reproduce|reproduire)\b[^.!?]{0,60}?\b(?:works|working|passes|already|fonctionne|marche|déjà|passent)\b)/i;
|
|
376
|
+
function gaveUp(text) { // the first sentence when it says it could not, else ''
|
|
377
|
+
const s = String(text || '').replace(/[’‘]/g, "'").replace(/^\s*#{1,6} ([^\n]*)\n+/, (h, t) => (GAVE.test(t) ? t + '. ' : '')).replace(/^[#>*\s]+/, '').replace(/\*\*/g, ''), m = s.match(/^[\s\S]{0,240}?[.!?:](?:\s|$)/), lead = (m ? m[0] : s.slice(0, 240)).trim(), all = new RegExp(GAVE.source, 'gi');
|
|
378
|
+
for (let f; (f = all.exec(lead));) { // each "could not" of the sentence: one that is a clean check does not count, the next one may
|
|
379
|
+
if (CLEAN.test(s.slice(f.index + f[0].length, f.index + f[0].length + 200))) continue; /* s, not lead: "I can't reproduce it: it already works" goes on after the colon (s and lead start at the same place) */
|
|
380
|
+
if (/\b(?:but|though|however|mais|cependant|pero|mas|aber)\b|;/i.test(lead.slice(0, f.index))) return '';
|
|
381
|
+
const rest = lead.slice(f.index + f[0].length), clear = /,\s*(?:but|however) (?:I|we) (?!(?:couldn't|could not|can't|cannot|didn't|did not|still)\b)|,\s*mais j'ai\b|,\s*pero (?:he|hemos)\b|\binstead\b(?! of)|\bà la place\b|,\s*so (?:I|we) (?:ran|used|switched|fell back|went with|worked around|tested|checked|verified|fixed|replaced|chose)\b|,\s*so (?:it|this|that|the \w+)(?:'s| is| are) (?:safe|done|complete|ready)\b/i;
|
|
382
|
+
if (clear.test(rest) && !/\b(?:still|also fails?|fail(?:s|ed)?|doesn't|didn't|won't|couldn't|can't|cannot|not|only|untested|yourself|left|what I could|partly|partially)\b|, but (?!I |we )/i.test(rest)) return ''; /* the same sentence goes on to what was done instead ("I couldn't reproduce it, but I found the cause", "…, so I switched to https.get"); not "…, so I wrote 0 drafts", a workaround that failed too, or work handed back ("but the commit is ready: push it yourself") */
|
|
383
|
+
return lead.replace(/\s+/g, ' ').replace(/\s*:$/, '');
|
|
384
|
+
}
|
|
385
|
+
return '';
|
|
386
|
+
}
|
|
370
387
|
const boardCache = new Map(); // file → { sig, parsed, title }
|
|
371
388
|
let boardMemo = { at: 0, rows: [] }, boardForced = 0;
|
|
372
389
|
const PR_URL = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+$/; // nothing else is given to the page as a link to open
|
|
@@ -377,7 +394,7 @@ const planFile = (f) => PLAN_FILE.test(f) || (!!PLAN_DIR && f.startsWith(PLAN_DI
|
|
|
377
394
|
const planText = (f) => { try { const st = fs.statSync(f); if (!st.isFile() || st.size > 262144) return ''; return clip(fs.readFileSync(f, 'utf8').trim(), 1200); } catch { return ''; } };
|
|
378
395
|
const menuOf = (b) => { // what a menu waiting for you shows, from the call it waits on, word for word: the questions and their options in their order (the terminal numbers them the same way), the command, the file, the plan
|
|
379
396
|
const i = b.input || {}, t = (x, n) => (typeof x === 'string' ? clip(x.trim(), n) : '');
|
|
380
|
-
if (b.name === 'AskUserQuestion') return { kind: 'question', questions: (Array.isArray(i.questions) ? i.questions : []).slice(0, 4).map((q) => ({ q: t(q && q.question, 300), multi: !!(q && q.multiSelect), options: (q && Array.isArray(q.options) ? q.options : []).slice(0, 8).map((o) => ({ label: t(o && o.label, 80), about: t(o && o.description, 140) })).filter((o) => o.label) })).filter((q) => q.q) };
|
|
397
|
+
if (b.name === 'AskUserQuestion') return { kind: 'question', questions: (Array.isArray(i.questions) ? i.questions : []).slice(0, 4).map((q) => ({ q: t(q && q.question, 300), head: t(q && q.header, 30), multi: !!(q && q.multiSelect), options: (q && Array.isArray(q.options) ? q.options : []).slice(0, 8).map((o) => ({ label: t(o && o.label, 80), about: t(o && o.description, 140) })).filter((o) => o.label) })).filter((q) => q.q) };
|
|
381
398
|
if (b.name === 'ExitPlanMode') return { kind: 'plan', text: t(i.plan, 1200) };
|
|
382
399
|
if (b.name === 'Bash') return { kind: 'command', cmd: t(i.command, 600), about: t(i.description, 160) };
|
|
383
400
|
if (/^(Edit|Write|MultiEdit|NotebookEdit)$/.test(b.name)) return { kind: 'edit', file: t(i.file_path || i.notebook_path, 300) };
|
|
@@ -412,7 +429,7 @@ function typedBefore(file) { // the first look at a session whose last order i
|
|
|
412
429
|
function parseTail(file, st) {
|
|
413
430
|
const sig = st.mtimeMs + ':' + st.size, hit = boardCache.get(file); if (hit && hit.sig === sig) return hit;
|
|
414
431
|
const { text, cut } = readTail(file, 192 * 1024), lines = text.split('\n'); if (cut) lines.shift();
|
|
415
|
-
const pend = new Map(); let lastType = null, lastTool = false, lastStop = null, stops = false, esc = false, lastTs = 0, custom = (hit && hit.custom) || null, ai = (hit && hit.ai) || null, first = hit ? hit.first : undefined, pr = (hit && hit.pr) || null, asked = (hit && hit.asked) || 0, plan = (hit && hit.plan) || null;
|
|
432
|
+
const pend = new Map(); let lastType = null, lastTool = false, lastStop = null, stops = false, esc = false, lastTs = 0, custom = (hit && hit.custom) || null, ai = (hit && hit.ai) || null, first = hit ? hit.first : undefined, pr = (hit && hit.pr) || null, asked = (hit && hit.asked) || 0, plan = (hit && hit.plan) || null, say = '', err = ''; // say: the first text since the last call or message of yours, the start of what closes the turn; err: an error that closed it
|
|
416
433
|
for (const l of lines) try { // one odd record costs that record, not the whole card
|
|
417
434
|
if (!l) continue; let r; try { r = JSON.parse(l); } catch { continue; }
|
|
418
435
|
const a = typedAt(r); if (a > asked) asked = a;
|
|
@@ -421,6 +438,8 @@ function parseTail(file, st) {
|
|
|
421
438
|
const t = Date.parse(r.timestamp) || 0, bl = blocks(r);
|
|
422
439
|
if (r.type === 'assistant' || r.type === 'user') { lastType = r.type; lastTool = bl.some((b) => b.type === 'tool_use'); lastStop = (r.type === 'assistant' && r.message && r.message.stop_reason) || null; if (lastStop) stops = true; if (t) lastTs = t;
|
|
423
440
|
esc = r.type === 'user' && bl.some((b) => b.type === 'text' && /^\s*\[Request interrupted/i.test(b.text || '')); if (esc) pend.clear(); } // Esc: the turn stops there, and no call is waited for any more
|
|
441
|
+
if (r.type === 'user' || (r.type === 'assistant' && lastTool)) { say = ''; err = ''; }
|
|
442
|
+
else if (r.type === 'assistant' && !r.isSidechain) { const tx = bl.filter((b) => b.type === 'text' && typeof b.text === 'string').map((b) => b.text).join('\n').trim(), m = r.message || {}; err = (r.isApiErrorMessage || m.model === '<synthetic>') && tx && !/^No response requested/i.test(tx) ? tx : ''; if (tx && !say) say = tx; }
|
|
424
443
|
for (const b of bl) if (b.type === 'tool_use' && /^(Write|Edit|MultiEdit)$/.test(b.name) && b.input && planFile(String(b.input.file_path || ''))) plan = { file: String(b.input.file_path), ts: t }; // the plan, written in its own file before it is shown for approval
|
|
425
444
|
for (const b of bl) { if (b.type === 'tool_use') pend.set(b.id, { id: String(b.id || ''), name: b.name, ts: t, q: askOf(b), c: callOf(b), m: menuOf(b) }); else if (b.type === 'tool_result') pend.delete(b.tool_use_id); }
|
|
426
445
|
} catch {}
|
|
@@ -430,7 +449,7 @@ function parseTail(file, st) {
|
|
|
430
449
|
}
|
|
431
450
|
if (!custom && !ai && first == null) first = firstPrompt(file) || (st.size > 64 * 1024 ? '' : null); // '' = looked for and not there; a file that has just been created is looked at again
|
|
432
451
|
if (!hit && !asked && cut) asked = typedBefore(file);
|
|
433
|
-
const out = { sig, title: custom || ai || first || null, custom, ai, first, pr, lastType, lastTool, lastStop, stops, esc, lastTs, pending: [...pend.values()] }; // a title the person typed wins over the generated one, and both over the first prompt
|
|
452
|
+
const out = { sig, title: custom || ai || first || null, custom, ai, first, pr, lastType, lastTool, lastStop, stops, esc, lastTs, pending: [...pend.values()], ...(lastType === 'assistant' && (err || gaveUp(say)) ? { gave: (err || gaveUp(say)).replace(/\s+/g, ' ').slice(0, 240) } : {}) }; // a title the person typed wins over the generated one, and both over the first prompt
|
|
434
453
|
out.asked = asked; out.plan = plan; boardCache.set(file, out); if (boardCache.size > 3 * ROWS_MAX) boardCache.delete(boardCache.keys().next().value); return out; // more than the list can hold: a full list never pushes its own rows out, which read every row again at each scan
|
|
435
454
|
}
|
|
436
455
|
function firstPrompt(file) { // the first thing the person typed, read record by record: a pattern over the raw text ran from a user record into the assistant's first answer and took that as the title
|
|
@@ -482,7 +501,7 @@ function boardRows0() {
|
|
|
482
501
|
let subActive = 0, subTotal = 0;
|
|
483
502
|
for (const x of subFiles(proj, id)) { subTotal++; if (now - mtimeOf(x.file) < 90e3) subActive++; }
|
|
484
503
|
const ran = since && p.asked && p.asked < since ? since - p.asked : 0, ask = state === 'blocked' && lp ? lp.q || lp.c : ''; // since: when it started to wait on you; ran: how long it worked, from your last order to then
|
|
485
|
-
return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime: st.mtimeMs, state, tool, ageMs, subActive, subTotal, asked: p.asked || 0, ...(since ? { since } : {}), ...(ran ? { ran } : {}), ...(p.pr ? { pr: p.pr } : {}), ...(ask ? { ask } : {}), ...(open ? { menu: open } : state === 'blocked' && lp && lp.m && !SUBTOOL.test(lp.name) ? { menu: { id: lp.id, tool: lp.name, ...lp.m, ...(w && w.status === 'waiting' ? { sure: 1 } : {}) } } : {}), ...(p.esc ? { cut: 1 } : {}), ...(tmpKey(proj) ? { tmp: 1 } : {}) }; // cut: stopped by you, which is no news to tell you
|
|
504
|
+
return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime: st.mtimeMs, state, tool, ageMs, subActive, subTotal, asked: p.asked || 0, ...(since ? { since } : {}), ...(ran ? { ran } : {}), ...(p.pr ? { pr: p.pr } : {}), ...(ask ? { ask } : {}), ...(state === 'blocked' && w && w.status === 'waiting' ? { sure: 1 } : {}), ...(open ? { menu: open } : state === 'blocked' && lp && lp.m && !SUBTOOL.test(lp.name) ? { menu: { id: lp.id, tool: lp.name, ...lp.m, ...(w && w.status === 'waiting' ? { sure: 1 } : {}) } } : {}), ...(state === 'turn' && p.gave ? { gave: p.gave } : {}), ...(p.esc ? { cut: 1 } : {}), ...(tmpKey(proj) ? { tmp: 1 } : {}) }; // cut: stopped by you, which is no news to tell you
|
|
486
505
|
}).filter(Boolean);
|
|
487
506
|
}
|
|
488
507
|
// Settings live in a file, not only in the page's localStorage: the port changes between VS Code windows and reloads, and localStorage is per origin (port included).
|
|
@@ -544,8 +563,30 @@ function logError(where, e) {
|
|
|
544
563
|
const RATE_STORES = /^https:\/\/(marketplace\.visualstudio\.com|open-vsx\.org)\//, GITHUB_REPO = 'https://github.com/Atoll92/agent-standup';
|
|
545
564
|
function appKind() {
|
|
546
565
|
const h = String(process.env.AGENT_STANDUP_HOST || ''), rate = String(process.env.AGENT_STANDUP_RATE || '');
|
|
547
|
-
const kind = h === 'desktop app' ? 'desktop' : h === 'command line' ? 'cli' : h ? 'editor' : '';
|
|
548
|
-
return { kind, rate: kind === 'editor' && RATE_STORES.test(rate) ? rate : GITHUB_REPO };
|
|
566
|
+
const kind = h === 'desktop app' ? 'desktop' : h === 'command line' ? 'cli' : h === 'claude code plugin' ? 'plugin' : h ? 'editor' : '';
|
|
567
|
+
return { kind, rate: kind === 'editor' && RATE_STORES.test(rate) ? rate : GITHUB_REPO, track: !noTrack() }; // track: false when DO_NOT_TRACK is set, and the page does not ask about usage
|
|
568
|
+
}
|
|
569
|
+
// Usage, counted only for those who said yes, in the desktop app, the command line and the Claude Code plugin (the editor counts itself: extension.js, pingWeek). The page asks once
|
|
570
|
+
// (prefs.shareUsage, which this server reads again in the settings file before it sends anything); when the call is opened it asks this server, which sends at most one empty request a week (weeks from Monday, UTC) for the 1-pixel file of its kind in the "stats"
|
|
571
|
+
// release on GitHub: the requests of a week are the people who opened the call that week from there. Nothing is sent in a request: no id, no path, no content. Never with DO_NOT_TRACK set.
|
|
572
|
+
// A file per week beside the settings (sent-<kind>-week-<monday>) makes several servers and pages send it once. AGENT_STANDUP_PING_BASE: where the tests receive it.
|
|
573
|
+
const USAGE_PIXELS = { desktop: 'desktop-week.gif', cli: 'cli-week.gif', plugin: 'plugin-week.gif' };
|
|
574
|
+
const noTrack = () => /^(1|true|yes)$/i.test(String(process.env.DO_NOT_TRACK || '').trim());
|
|
575
|
+
const mondayOf = (d) => new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() - ((d.getUTCDay() + 6) % 7))).toISOString().slice(0, 10);
|
|
576
|
+
function usageWeek(now = new Date()) {
|
|
577
|
+
const kind = appKind().kind, name = USAGE_PIXELS[kind]; if (!name || noTrack() || (readPrefs() || {}).shareUsage !== true) return { sent: false }; // the answer is read here too, from the settings file: the page asking is not enough
|
|
578
|
+
const week = mondayOf(now), dir = path.dirname(PREFS), mine = 'sent-' + kind + '-week-' + week;
|
|
579
|
+
try {
|
|
580
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
581
|
+
for (const f of fs.readdirSync(dir)) if (f.startsWith('sent-' + kind + '-week-') && f !== mine) try { fs.unlinkSync(path.join(dir, f)); } catch {}
|
|
582
|
+
fs.closeSync(fs.openSync(path.join(dir, mine), 'wx'));
|
|
583
|
+
} catch (e) { if (!(e && e.code === 'EEXIST')) logError('usage', e); return { sent: false, week }; }
|
|
584
|
+
try {
|
|
585
|
+
const u = new URL(name, process.env.AGENT_STANDUP_PING_BASE || 'https://github.com/Atoll92/agent-standup/releases/download/stats/');
|
|
586
|
+
const r = require(u.protocol === 'http:' ? 'http' : 'https').get(u, { headers: { 'user-agent': 'agent-standup' }, timeout: 5000 }, (m) => { m.resume(); m.destroy(); });
|
|
587
|
+
r.on('error', () => {}); r.on('timeout', () => r.destroy());
|
|
588
|
+
} catch (e) { logError('usage', e); }
|
|
589
|
+
return { sent: true, week };
|
|
549
590
|
}
|
|
550
591
|
function errorReport() { // what ⚙ › Report a problem shows: the app, the system and the last errors of the log
|
|
551
592
|
let errors = []; try { errors = fs.readFileSync(ERRLOG, 'utf8').split('\n').filter(Boolean).slice(-40).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter((x) => x && typeof x === 'object'); } catch {}
|
|
@@ -590,11 +631,11 @@ function currentSession(projFilter, pick, stick, anyTmp) { // pick: { proj, id
|
|
|
590
631
|
const rows = all.filter(inScope), mine = there(pick) ? all.find((r) => same(r, pick)) : null;
|
|
591
632
|
const asked = Math.max(0, (mine && mine.asked) || 0, ...rows.map((r) => r.asked || 0)); // the latest order, in the folder the call follows or in the session you went to
|
|
592
633
|
const moved = pick && pick.pin ? Math.max(0, ...rows.filter((r) => !same(r, pick)).map((r) => r.asked || 0)) : asked; // pick.pin: a call pinned by a click on its tab (📌) is left for an order typed in another session only; what you type in it keeps it there
|
|
593
|
-
if (there(pick) && !(moved > pick.since)) return { proj: pick.proj, id: pick.id, mtime: now, asked, pick: 1 }; // no "since" on the first question after a pick: the answer gives it (asked), and the page sends it back from then on
|
|
634
|
+
if (there(pick) && !(moved > pick.since)) return { proj: pick.proj, id: pick.id, mtime: now, asked, pick: 1, why: pick.pin ? 'pin' : 'pick' }; // no "since" on the first question after a pick: the answer gives it (asked), and the page sends it back from then on
|
|
594
635
|
const live = rows.filter((r) => /^(working|waiting)$/.test(r.state) || (r.state === 'blocked' && !(now - (r.since || now) > MENU_LIVE_MS)) || r.subActive > 0 || now - r.mtime < STICK_MS), last = Math.max(0, ...live.map((r) => r.asked || 0)), top = live.filter((r) => (r.asked || 0) === last);
|
|
595
636
|
const to = top.find((r) => same(r, stick)) || top.sort((a, b) => b.mtime - a.mtime)[0]; // two sessions whose last order is not known (or of the same instant): the call stays where it is
|
|
596
|
-
if (to) return { proj: to.proj, id: to.id, mtime: to.mtime, asked };
|
|
597
|
-
if (there(stick) && inScope(stick)) return { proj: stick.proj, id: stick.id, mtime: sessionMtime(stick.proj, stick.id), asked }; // nobody is at work: the call stays where it is
|
|
637
|
+
if (to) return { proj: to.proj, id: to.id, mtime: to.mtime, asked, why: last ? 'typed' : 'busy' }; // why: shown by the page, in the row of tabs
|
|
638
|
+
if (there(stick) && inScope(stick)) return { proj: stick.proj, id: stick.id, mtime: sessionMtime(stick.proj, stick.id), asked, why: 'stay' }; // nobody is at work: the call stays where it is
|
|
598
639
|
let best = null;
|
|
599
640
|
const consider = (proj, id, m) => { if (!best || m > best.mtime) best = { proj, id, mtime: m }; };
|
|
600
641
|
for (const m of SOURCES) for (const r of guard(() => m.sessions(), [])) if (inScope({ proj: m.PROJ, id: r.id })) consider(m.PROJ, r.id, r.mtime);
|
|
@@ -604,7 +645,7 @@ function currentSession(projFilter, pick, stick, anyTmp) { // pick: { proj, id
|
|
|
604
645
|
}
|
|
605
646
|
if (!best && projFilter) return { ...currentSession('', null, stick), wide: 1 };
|
|
606
647
|
if (!best && !projFilter && !anyTmp) return currentSession('', pick, stick, true); // nothing but sessions in the temporary folder: one of them rather than an empty call // nothing in that folder (an editor open on another one than the sessions): the latest of anywhere, and the page is told, so its tabs follow the same rule
|
|
607
|
-
return best ? { ...best, asked } : {}; // a call that is opened while nobody is at work: the session that was written to last
|
|
648
|
+
return best ? { ...best, asked, why: 'latest' } : {}; // a call that is opened while nobody is at work: the session that was written to last
|
|
608
649
|
}
|
|
609
650
|
|
|
610
651
|
// ---- Incremental transcript reader: each .jsonl is parsed once, then only the bytes appended since are read.
|
|
@@ -1112,7 +1153,7 @@ function start(port = PORT) {
|
|
|
1112
1153
|
if (url.searchParams.get('engine') === 'kokoro') { const st = kokoro.status(); if (st.installed && !st.gaveUp) kokoro.warm(); return json({ available: st.installed && !st.gaveUp, ready: st.ready, voices: kokoro.voices(), platform: process.platform, engine: 'kokoro' }); }
|
|
1113
1154
|
return loadVoices().then((v) => json(v));
|
|
1114
1155
|
}
|
|
1115
|
-
if (url.pathname === '/api/kokoro/install' && req.method === 'POST') return json(kokoro.install());
|
|
1156
|
+
if (url.pathname === '/api/kokoro/install' && req.method === 'POST') return json(kokoro.install()); if (url.pathname === '/api/usage' && req.method === 'POST') return json(usageWeek());
|
|
1116
1157
|
if (url.pathname === '/api/kokoro') return json(kokoro.status());
|
|
1117
1158
|
if (url.pathname === '/api/tts') {
|
|
1118
1159
|
return tts(url.searchParams.get('text') || '', url.searchParams.get('voice'), url.searchParams.get('rate'), url.searchParams.get('engine'), url.searchParams.get('fb'))
|
|
@@ -1120,7 +1161,7 @@ function start(port = PORT) {
|
|
|
1120
1161
|
.catch((e) => json({ error: String(e.message) }, 400));
|
|
1121
1162
|
}
|
|
1122
1163
|
if (url.pathname === '/api/prefs.js') { res.writeHead(200, { 'content-type': 'application/javascript', 'cache-control': 'no-store' }); return res.end('window.SAVED_PREFS = ' + JSON.stringify(readPrefs()).replace(/</g, '\\u003c') + '; window.AS_APP = ' + JSON.stringify(appKind()).replace(/</g, '\\u003c') + ';'); }
|
|
1123
|
-
if (url.pathname === '/api/prefs' && req.method === 'PUT') return readBody((body) => { try { const v = JSON.parse(body); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('prefs must be an object'); writePrefs(v); json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } });
|
|
1164
|
+
if (url.pathname === '/api/prefs' && req.method === 'PUT') return readBody((body) => { try { const v = JSON.parse(body); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('prefs must be an object'); const cur = readPrefs() || {}; if ((+cur.shareUsageT || 0) > (+v.shareUsageT || 0)) { v.shareUsage = cur.shareUsage; v.shareUsageT = cur.shareUsageT; v.usageAsked = cur.usageAsked; } writePrefs(v); /* the usage answer: a page opened before it was changed elsewhere (another tab, the desktop app) writes back its old settings, not its old answer */ json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } });
|
|
1124
1165
|
if (url.pathname === '/api/prefs') return json(readPrefs() || {});
|
|
1125
1166
|
if (url.pathname === '/api/done' && req.method === 'POST') return readBody((body) => { try { const v = JSON.parse(body); json({ ok: setDone(String(v.proj || ''), String(v.id || ''), v.on !== false) }); } catch (e) { logError('done', e); json({ error: String(e.message || e) }, 400); } });
|
|
1126
1167
|
if (url.pathname === '/api/errors' && req.method === 'POST') return readBody((body) => { try { const b = JSON.parse(body) || {}; logError('page' + (typeof b.where === 'string' && b.where ? ' ' + b.where.slice(0, 40) : ''), { message: String(b.msg || ''), stack: String(b.stack || '') }); json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } }); // an error of the page, written to the local log
|