feat: full system update — cockpit, local-first extraction, self-learning, self-update

- cockpit/ UI (FastAPI): live agent switching, sequential chat, Femida goddess voice, Apple aesthetics, generic Themis branding
- extraction: Apple Vision OCR + markitdown + whisper, mixed-PDF, requisites sidecar, adaptive OCR (Ollama removed)
- self-learning: redline (baseline diff → knowledge/redlines.md) + error analysis
- /themis-update skill: pull latest logic from GitHub without touching cases/ or knowledge/
- portable paths (THEMIS_HOME env), bundled vision-ocr.swift built by install.sh
- comprehensive install.sh, README with screenshot, LICENSE (MIT), CONTRIBUTING
- synthetic example case (ivanov-ivan); zero client data
This commit is contained in:
tv5171621-source
2026-06-15 01:44:47 +03:00
parent bc4818376d
commit 1ba62e59eb
76 changed files with 2913 additions and 395 deletions
+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none" stroke="#16243B" stroke-width="4" stroke-linecap="round">
<line x1="50" y1="20" x2="50" y2="70"/><circle cx="50" cy="16" r="5" fill="#16243B" stroke="none"/>
<line x1="20" y1="32" x2="80" y2="32"/>
<path d="M20 32 L10 56 M20 32 L30 56 M10 56 a10 6 0 0 0 20 0"/>
<path d="M80 32 L70 56 M80 32 L90 56 M70 56 a10 6 0 0 0 20 0"/>
<line x1="36" y1="74" x2="64" y2="74"/>
</svg>

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

+424
View File
@@ -0,0 +1,424 @@
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Themis · юридический ассистент</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,500;0,8..60,600&family=Onest:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root{
/* светлый Apple Liquid Glass · флаг РФ: чернила/бумага/красный · бронза на гербе */
--ink:#16243B; --ink-soft:#46566f; --faint:#8a93a3;
--red:#D11A2A; --red-soft:rgba(209,26,42,.12); --red-glow:rgba(209,26,42,.28);
--blue:#1B3A8C; --blue-soft:rgba(27,58,140,.12); --blue-glow:rgba(27,58,140,.26);
--glass:rgba(255,255,255,.55); --glass-2:rgba(255,255,255,.72); --glass-line:rgba(255,255,255,.7);
--hair:rgba(22,36,59,.10);
--sh:0 1px 1px rgba(22,36,59,.04), 0 8px 28px rgba(22,36,59,.10);
--sh-lg:0 2px 4px rgba(22,36,59,.06), 0 20px 50px rgba(22,36,59,.16);
--spec:inset 0 1px 0 rgba(255,255,255,.85);
--serif:"Source Serif 4",Georgia,serif; --sans:"Onest",system-ui,sans-serif;
--r:18px; --ease:cubic-bezier(.23,1,.32,1);
}
*{box-sizing:border-box;margin:0;padding:0}
/* картинки (лица, лого, герб) нельзя перетаскивать — чтобы случайно не уронить в drop-зону */
img{-webkit-user-drag:none;-khtml-user-drag:none;user-select:none;-webkit-user-select:none}
html,body{height:100%}
body{
font-family:var(--sans); color:var(--ink); overflow:hidden;
background:
radial-gradient(40vw 40vw at 8% 0%, var(--red-soft), transparent 60%),
radial-gradient(45vw 45vw at 100% 10%, var(--blue-soft), transparent 60%),
radial-gradient(50vw 50vw at 50% 120%, rgba(22,36,59,.07), transparent 60%),
#eef0f4;
-webkit-font-smoothing:antialiased; line-height:1.5;
}
.glass{background:var(--glass); backdrop-filter:blur(14px) saturate(150%); -webkit-backdrop-filter:blur(14px) saturate(150%);
border:1px solid var(--glass-line); box-shadow:var(--sh), var(--spec)}
.app{height:100vh; display:grid; grid-template-columns:264px 1fr; grid-template-rows:auto 1fr;
grid-template-areas:"head head" "rail main"; gap:14px; padding:14px}
/* шапка */
header{grid-area:head; display:flex; align-items:center; gap:15px; padding:12px 20px; border-radius:var(--r)}
.logo{height:40px; width:auto; display:block}
.brand{display:flex; align-items:baseline; gap:10px; padding-left:15px; border-left:1px solid var(--hair)}
.brand .mark{font-family:var(--serif); font-weight:600; font-size:21px}
.brand .mark em{font-style:normal; color:var(--red)}
.brand .sub{font-size:12px; color:var(--faint)}
.status{margin-left:auto; display:flex; align-items:center; gap:8px; font-size:12.5px; color:var(--ink-soft)}
.dot{width:7px; height:7px; border-radius:50%; background:var(--faint); transition:background .4s var(--ease)}
.dot.live{background:var(--red); animation:pulse 1.8s var(--ease) infinite}
@keyframes pulse{0%{box-shadow:0 0 0 0 rgba(209,26,42,.5)}70%{box-shadow:0 0 0 8px rgba(209,26,42,0)}100%{box-shadow:0 0 0 0 transparent}}
/* рейл — drill-down клиенты→дела */
.rail{grid-area:rail; border-radius:var(--r); padding:14px 11px; overflow-y:auto; display:flex; flex-direction:column; gap:3px; contain:layout style paint}
.rail .head{display:flex; align-items:center; gap:8px; margin-bottom:8px; padding:0 5px}
.rail .head h2{font-family:var(--serif); font-weight:500; font-size:11.5px; text-transform:uppercase; letter-spacing:1.2px; color:var(--faint)}
.back{border:none; background:transparent; color:var(--red); font-family:var(--sans); font-size:12.5px; cursor:pointer; padding:2px 6px; border-radius:8px; transition:background .15s}
.back:hover{background:var(--red-soft)}
.newbtn{margin-left:auto; border:1px solid var(--hair); background:var(--glass-2); color:var(--ink); width:26px; height:26px; border-radius:9px; cursor:pointer; font-size:16px; line-height:1; transition:transform .14s var(--ease), background .15s; box-shadow:var(--spec)}
.newbtn:hover{background:#fff} .newbtn:active{transform:scale(.92)}
.row{display:flex; justify-content:space-between; align-items:center; gap:8px; padding:9px 11px; border-radius:12px;
font-size:13.5px; color:var(--ink-soft); cursor:pointer; transition:background .16s var(--ease), color .16s, transform .12s var(--ease); animation:rise .3s var(--ease) backwards}
.row:hover{background:var(--glass-2); color:var(--ink)} .row:active{transform:scale(.99)}
.row.sel{background:var(--glass-2); color:var(--ink); box-shadow:var(--spec)}
.row .n{flex:0 0 auto; font-size:11px; color:var(--faint); background:rgba(22,36,59,.06); border-radius:999px; padding:1px 8px}
.row .n.has{color:var(--blue); background:var(--blue-soft)}
.rail .empty{font-size:12.5px; color:var(--faint); font-style:italic; padding:8px 6px}
/* main: ВЕРХ разговор (над логотипом), НИЗ юристы + ввод */
.main{grid-area:main; display:grid; grid-template-rows:1fr auto; gap:14px; min-height:0}
.stage{position:relative; border-radius:var(--r); padding:22px 26px; overflow:hidden; display:grid; grid-template-rows:auto 1fr; min-height:0}
.crest{position:absolute; inset:0; display:flex; align-items:center; justify-content:center; pointer-events:none}
.crest img{width:min(440px,50%); opacity:.07}
.stage > *:not(.crest){position:relative; z-index:1}
.deck{border-radius:var(--r); padding:22px 22px 16px; display:flex; flex-direction:column; gap:18px}
/* релей + путь дела */
.relayWrap{position:relative}
.relayWrap h2,.ctx h2{font-family:var(--serif); font-weight:500; font-size:11.5px; text-transform:uppercase; letter-spacing:1.2px; color:var(--faint); margin-bottom:16px}
.lane{display:grid; grid-template-columns:repeat(9,1fr); position:relative}
.lane::before{content:""; position:absolute; top:41px; left:5.5%; right:5.5%; height:2px; background:var(--hair)}
.lane .progress{position:absolute; top:41px; left:5.5%; height:2px; width:0; background:linear-gradient(90deg,var(--blue),var(--red)); transition:width .6s var(--ease); border-radius:2px}
.token{position:absolute; top:29px; left:5.5%; width:24px; height:24px; border-radius:7px; background:#fff; box-shadow:var(--sh);
display:flex; align-items:center; justify-content:center; font-size:12px; color:var(--red); transform:translateX(-50%);
transition:left .6s var(--ease); opacity:0}
.token.on{opacity:1}
.station{position:relative; display:flex; flex-direction:column; align-items:center; gap:9px; text-align:center; z-index:1; animation:rise .4s var(--ease) backwards}
.node{position:relative; width:84px; height:84px; border-radius:50%; overflow:hidden; background:var(--glass-2); border:2px solid var(--hair);
display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-size:24px; color:var(--faint);
box-shadow:var(--spec); transition:border-color .35s var(--ease), transform .35s var(--ease), box-shadow .35s}
.node img{position:absolute; inset:0; width:100%; height:100%; object-fit:cover; filter:grayscale(1) brightness(.99); transition:filter .5s var(--ease)}
.node .fb{position:relative; z-index:0}
.station .who{font-size:12.5px; font-weight:600; color:var(--faint); line-height:1.15; transition:color .35s}
.station .role{font-size:10.5px; color:var(--faint)}
/* отработавшие — в цвете, синяя рамка */
.station.done .node{border-color:var(--blue)}
.station.done .node img{filter:none}
.station.done .who{color:var(--ink)}
/* работает сейчас — цвет + пульсирующее свечение */
.station.active .node{border-color:var(--red); transform:scale(1.08); animation:glow 3s ease-in-out infinite}
.station.active .node img{filter:none}
.station.active .who{color:var(--red)}
@keyframes glow{0%,100%{box-shadow:0 0 6px 0 var(--red-glow), var(--spec)}50%{box-shadow:0 0 16px 3px var(--red-glow), var(--spec)}}
/* группа — кластер лиц, раскрывается в работе */
.cluster{display:flex; align-items:center; justify-content:center; height:84px}
.cluster .mem{width:58px; height:58px; border-radius:50%; object-fit:cover; background:var(--glass-2);
border:2px solid var(--glass-line); box-shadow:var(--spec); filter:grayscale(1) brightness(.99);
margin-left:-26px; transition:margin .45s var(--ease), filter .5s var(--ease), transform .35s var(--ease), box-shadow .4s}
.cluster .mem:first-child{margin-left:0}
.station.done .cluster .mem{filter:none}
.station.active .cluster .mem{margin-left:-2px; filter:none; transform:translateY(-2px); transition-delay:calc(var(--i)*70ms);
box-shadow:0 0 12px 1px var(--red-glow), var(--spec); animation:glow 3s ease-in-out infinite}
.station.active .cluster .mem:first-child{margin-left:0}
/* контекст дела + docx */
.ctx{display:none; grid-row:1}
.ctx.show{display:block; animation:rise .35s var(--ease)}
.ctx .title{font-family:var(--serif); font-size:19px; color:var(--ink); margin-bottom:3px; font-weight:600}
.ctx .meta{font-size:12.5px; color:var(--faint); margin-bottom:16px}
.docs{display:grid; grid-template-columns:repeat(auto-fill,minmax(230px,1fr)); gap:10px}
.doc{display:flex; align-items:center; gap:11px; padding:12px 13px; border-radius:13px; cursor:pointer;
background:var(--glass-2); border:1px solid var(--glass-line); box-shadow:var(--spec); transition:transform .12s var(--ease), box-shadow .16s; animation:rise .3s var(--ease) backwards}
.doc:hover{box-shadow:var(--sh-lg), var(--spec)} .doc:active{transform:scale(.99)}
.doc .ic{flex:0 0 36px; height:36px; border-radius:9px; background:var(--red-soft); color:var(--red); display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-size:11px; font-weight:600}
.doc .dn{font-size:13px; color:var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.doc .dd{font-size:11px; color:var(--faint)}
.ctx .empty{font-size:13px; color:var(--faint); font-style:italic}
/* чат снизу */
.chat{border-radius:var(--r); display:flex; flex-direction:column; overflow:hidden; min-height:0}
.chat.over{outline:2px dashed var(--red); outline-offset:-6px}
.stream{grid-row:2; min-height:0; overflow-y:auto; padding:16px 18px; display:flex; flex-direction:column; gap:10px; contain:layout style paint; overflow-anchor:none}
.msg{display:flex; gap:9px; animation:slide .32s var(--ease) backwards}
.msg .av{position:relative; flex:0 0 30px; width:30px; height:30px; border-radius:50%; overflow:hidden; background:rgba(22,36,59,.08); color:var(--ink-soft);
display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-size:12px; font-weight:600}
.msg .av img{position:absolute; inset:0; width:100%; height:100%; object-fit:cover}
/* мои реплики — справа, чужие — слева */
.msg.me{flex-direction:row-reverse}
.msg.me .av{background:#fff}
.msg.me .av img{object-fit:contain; padding:3px}
.msg.me .bub{background:var(--blue-soft); border-color:rgba(27,58,140,.20)}
.msg.me .text{color:var(--ink)}
.msg .bub{background:var(--glass-2); border:1px solid var(--glass-line); border-radius:14px; padding:8px 12px; max-width:80%; box-shadow:var(--spec)}
.msg .name{font-size:11px; font-weight:600; color:var(--ink); margin-bottom:1px}
.msg .name .r{font-weight:400; color:var(--faint); margin-left:6px}
.msg .text{font-size:13px; color:var(--ink-soft); overflow-wrap:anywhere}
.msg.gate .text{color:var(--blue); font-weight:500}
.stream .empty{margin:auto; text-align:center; padding:0 30px; color:var(--faint)}
/* индикатор «печатает» */
.typing{display:flex; gap:9px; align-items:center; animation:slide .3s var(--ease)}
.typing .av{position:relative; flex:0 0 30px; width:30px; height:30px; border-radius:50%; overflow:hidden; background:var(--red-soft)}
.typing .av img{position:absolute; inset:0; width:100%; height:100%; object-fit:cover}
.dots{display:inline-flex; gap:5px; align-items:center; padding:11px 14px; background:var(--glass-2); border:1px solid var(--glass-line); border-radius:14px; box-shadow:var(--spec)}
.dots i{width:6px; height:6px; border-radius:50%; background:var(--faint); animation:blink 1.4s ease-in-out infinite}
.dots i:nth-child(2){animation-delay:.18s} .dots i:nth-child(3){animation-delay:.36s}
@keyframes blink{0%,70%,100%{opacity:.25; transform:translateY(0)} 35%{opacity:.9; transform:translateY(-3px)}}
/* карточка документа в чате */
.doccard{display:flex; align-items:center; gap:11px; margin-top:8px; padding:11px 13px; border-radius:12px; cursor:pointer;
background:var(--surface); border:1px solid var(--glass-line); box-shadow:var(--spec); transition:transform .12s var(--ease), box-shadow .16s}
.doccard:hover{box-shadow:var(--sh-lg), var(--spec)} .doccard:active{transform:scale(.99)}
.doccard .ic{flex:0 0 36px; height:36px; border-radius:9px; background:var(--red-soft); color:var(--red); display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-size:11px; font-weight:600}
.doccard .dn{font-size:13px; color:var(--ink); font-weight:600} .doccard .dd{font-size:11px; color:var(--faint)}
/* кнопка самообучения по правкам */
.learn{margin-left:auto; flex:0 0 auto; border:1px solid var(--glass-line); background:var(--glass-2); color:var(--blue);
font-family:var(--sans); font-size:11.5px; font-weight:600; padding:6px 11px; border-radius:10px; cursor:pointer;
box-shadow:var(--spec); transition:background .15s var(--ease), color .15s, transform .12s var(--ease); white-space:nowrap}
.learn:hover{background:#fff; color:var(--red)} .learn:active{transform:scale(.95)} .learn:disabled{opacity:.5; cursor:default}
/* кнопки выбора (вопрос к пользователю) */
.opts{display:flex; flex-wrap:wrap; gap:8px; margin-top:9px}
.opt{padding:8px 14px; border-radius:999px; border:1px solid var(--glass-line); background:var(--surface); color:var(--ink);
font-family:var(--sans); font-size:13px; font-weight:500; cursor:pointer; box-shadow:var(--spec); transition:background .16s var(--ease), transform .12s var(--ease), color .16s}
.opt:hover{background:var(--red); color:#fff; transform:translateY(-1px)} .opt:active{transform:scale(.96)} .opt:disabled{opacity:.45; cursor:default}
.composer{padding:16px 18px 18px; border-top:1px solid var(--hair); display:flex; flex-direction:column; align-items:center}
.cbox{width:100%; max-width:720px; display:flex; gap:12px; align-items:center; background:var(--glass-2); border:1px solid var(--glass-line);
border-radius:20px; padding:8px 8px 8px 18px; box-shadow:var(--spec); transition:border-color .18s var(--ease), box-shadow .18s}
.cbox:focus-within{border-color:var(--blue); box-shadow:0 0 18px 2px var(--blue-glow), var(--spec)}
.cbox textarea{flex:1; resize:none; border:none; outline:none; background:transparent; color:var(--ink); font-family:var(--sans);
font-size:14px; line-height:1.55; min-height:44px; max-height:150px; padding:11px 0; display:block; align-self:center}
.cbox textarea::placeholder{color:var(--faint)}
.send{align-self:center; height:44px; padding:0 22px; border-radius:999px; border:1px solid var(--glass-line); cursor:pointer;
background:var(--glass); color:var(--ink-soft); display:flex; align-items:center; gap:8px; font-family:var(--sans); font-size:13.5px; font-weight:600;
box-shadow:var(--spec); transition:background .2s var(--ease), color .2s, transform .14s var(--ease), box-shadow .2s}
.send svg{width:16px; height:16px; display:block}
.send:hover{background:#fff; color:var(--red); box-shadow:var(--sh-lg), var(--spec); transform:translateY(-1px)}
.send:active{transform:scale(.96)} .send:disabled{opacity:.4; cursor:not-allowed; transform:none}
.hint{font-size:11px; color:var(--faint); padding:9px 4px 0; text-align:center; max-width:720px}
.toast{position:fixed; left:50%; bottom:28px; transform:translate(-50%,20px); opacity:0; pointer-events:none;
background:var(--glass-2); -webkit-backdrop-filter:blur(20px) saturate(180%); backdrop-filter:blur(20px) saturate(180%);
border:1px solid var(--glass-line); box-shadow:var(--sh-lg), var(--spec); border-radius:999px; padding:11px 20px 11px 13px;
display:flex; align-items:center; gap:10px; font-size:13.5px; font-weight:600; color:var(--ink); z-index:100;
transition:opacity .25s var(--ease), transform .3s var(--ease)}
.toast.show{opacity:1; transform:translate(-50%,0)}
.toast .mk{width:22px; height:22px; border-radius:50%; background:var(--blue); color:#fff; display:flex; align-items:center; justify-content:center; font-size:12px; box-shadow:0 0 14px var(--blue-glow)}
.toast.err .mk{background:var(--red); box-shadow:0 0 14px var(--red-glow)}
body.drag::after{content:"Отпустите — документы уйдут в работу"; position:fixed; inset:14px; border-radius:22px;
border:2px dashed var(--red); background:rgba(177,30,47,.05); -webkit-backdrop-filter:blur(2px); backdrop-filter:blur(2px);
display:flex; align-items:center; justify-content:center; font-family:var(--serif); font-size:20px; color:var(--red); z-index:90; pointer-events:none}
@keyframes rise{from{opacity:0; transform:translateY(8px)}to{opacity:1; transform:none}}
@keyframes slide{from{opacity:0; transform:translateY(6px)}to{opacity:1; transform:none}}
@media (prefers-reduced-motion:reduce){*{animation:none!important; transition:none!important}}
::-webkit-scrollbar{width:9px}::-webkit-scrollbar-thumb{background:rgba(22,36,59,.16); border-radius:6px; border:3px solid transparent; background-clip:padding-box}
</style>
</head>
<body>
<div class="app">
<header class="glass">
<img class="logo" src="/logo.png" alt="Themis">
<div class="brand"><span class="mark">Фемида<em>.</em></span><span class="sub">подготовка процессуальных документов</span></div>
<div class="status"><span class="dot" id="dot"></span><span id="statusText">в покое</span></div>
</header>
<aside class="rail glass">
<div class="head" id="railHead">
<h2 id="railTitle">Клиенты</h2>
<button class="newbtn" id="newBtn" title="Новое дело">+</button>
</div>
<div id="railBody"><div class="empty">загрузка…</div></div>
</aside>
<main class="main">
<!-- ВЕРХ: разговор юристов между собой, на фоне логотип -->
<section class="stage glass">
<div class="crest"><img src="/logo.png" alt=""></div>
<div class="ctx" id="ctx">
<div class="title" id="ctxTitle"></div>
<div class="meta" id="ctxMeta"></div>
<div class="docs" id="docs"></div>
</div>
<div class="stream" id="stream"><div class="empty">Здесь юристы обсуждают дело.<br>Дайте задачу ниже — или перетащите документы.</div></div>
</section>
<!-- НИЗ: юристы + ввод -->
<section class="deck glass">
<div class="lane" id="lane"><div class="progress" id="prog"></div><div class="token" id="token"></div></div>
<div class="composer">
<div class="cbox">
<textarea id="msg" rows="1" placeholder="Новое дело: клиент …, нужен документ …"></textarea>
<button class="send" id="send" aria-label="Отправить"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 19V5M6 11l6-6 6 6"/></svg><span>Отправить</span></button>
</div>
</div>
</section>
</main>
</div>
<div id="toast" class="toast"></div>
<script>
const $=s=>document.querySelector(s);
// полное экранирование любых данных, попадающих в innerHTML (тексты, имена, заголовки дел)
const esc=s=>String(s==null?'':s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
let OFFICE=[], curClient=null, curCase=null;
const SAY={
gruzenberg:"Бумаги принял. Опись готова. Господин Мейер, дело ваше.",
lokhvitsky:"Разложил по делам. Каждое — своему клиенту. Порядок есть.",
meyer:"Картирую дело, господа. Поднимаю читателей.",
readers:"Читаем. Скан — в текст, фото — в дело. Доложим точно.",
shershenevich:"Сверил. Противоречий нет. Карта готова.",
hunters:"Ищем практику. За нас, против нас, по процессу.",
areopag:"Совет заседает. Спорим до согласия.",
speransky:"Составляю документ. Слово к слову, факт к факту.",
koni:"Проверяю по семи блокам. Вердикт дам честно."};
async function loadOffice(){
OFFICE=await (await fetch('/api/office')).json();
const lane=$('#lane');
OFFICE.forEach((a,i)=>{
const el=document.createElement('div'); el.className='station'+(a.members?' grp':''); el.id='st-'+a.id; el.style.animationDelay=(i*45)+'ms';
if(a.members){
const imgs=a.members.map((m,j)=>`<img class="mem" src="/faces/${m.id}.png" alt="${m.name}" title="${m.name}" style="--i:${j}" decoding="async" onerror="this.remove()">`).join('');
el.innerHTML=`<div class="cluster">${imgs}</div><div class="who">${a.name}</div><div class="role">${a.role}</div>`;
} else {
el.innerHTML=`<div class="node"><img src="/faces/${a.id}.png" alt="" decoding="async" onload="this.nextElementSibling.style.display='none'" onerror="this.remove()"><span class="fb">${a.name[0]}</span></div>
<div class="who">${a.name}</div><div class="role">${a.role}</div>`;
}
lane.appendChild(el);
});
}
const agentById=id=>OFFICE.find(a=>a.id===id);
// рейл drill-down
function hideCtx(){curCase=null; $('#ctx').classList.remove('show'); document.querySelectorAll('.row.sel').forEach(x=>x.classList.remove('sel'));}
async function showClients(){
curClient=null; hideCtx(); $('#railTitle').textContent='Клиенты';
const c=await (await fetch('/api/clients')).json();
const b=$('#railBody');
if(!c.length){b.innerHTML='<div class="empty">клиентов нет</div>';return;}
b.innerHTML=''; c.forEach((cl,i)=>{
const r=document.createElement('div'); r.className='row'; r.style.animationDelay=(i*18)+'ms';
r.innerHTML=`<span>${esc(cl.name)}</span><span class="n ${cl.cases?'has':''}">${cl.cases|0}</span>`;
r.onclick=()=>showCases(cl); b.appendChild(r);
});
}
async function showCases(cl){
curClient=cl; hideCtx(); $('#railTitle').innerHTML=`<button class="back" onclick="showClients()">← ${esc(cl.name)}</button>`;
const cs=await (await fetch('/api/client/'+encodeURIComponent(cl.slug)+'/cases')).json();
const b=$('#railBody');
if(!cs.length){b.innerHTML='<div class="empty">дел нет</div>';return;}
b.innerHTML=''; cs.forEach((c,i)=>{
const r=document.createElement('div'); r.className='row'; r.style.animationDelay=(i*22)+'ms';
r.innerHTML=`<span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis">${esc(c.title)}</span><span class="n ${c.docx?'has':''}">${c.docx|0}</span>`;
r.onclick=()=>openCase(cl,c,r); b.appendChild(r);
});
}
async function openCase(cl,c,el){
curCase=c; document.querySelectorAll('.row').forEach(x=>x.classList.remove('sel')); el.classList.add('sel');
$('#ctx').classList.add('show'); $('#ctxTitle').textContent=c.title; $('#ctxMeta').textContent=cl.name+' · контекст дела';
const docs=await (await fetch(`/api/case-docs?client=${encodeURIComponent(cl.slug)}&case=${encodeURIComponent(c.slug)}`)).json();
const box=$('#docs');
if(!docs.length){box.innerHTML='<div class="empty">готовых .docx пока нет</div>';return;}
box.innerHTML=''; docs.forEach((d,i)=>{const date=new Date(d.mtime*1000).toLocaleDateString('ru-RU');
const el=document.createElement('div'); el.className='doc'; el.style.animationDelay=(i*30)+'ms';
el.innerHTML=`<span class="ic">DOCX</span><div style="min-width:0;flex:1"><div class="dn">${esc(d.name)}</div><div class="dd">${date} · ${(d.size/1024|0)} КБ</div></div><button class="learn" title="Сравнить мои правки с черновиком Фемиды">📝 Изучить правки</button>`;
el.onclick=ev=>{if(ev.target.closest('.learn'))return; openDoc(d.path);};
el.querySelector('.learn').onclick=ev=>{ev.stopPropagation(); learnRedline(d.path, ev.currentTarget);};
box.appendChild(el);});
}
window.showClients=showClients;
function openDoc(path){fetch('/api/open',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({path})});}
async function learnRedline(path, btn){
if(btn){btn.disabled=true; btn.textContent='Изучаю…';}
await fetch('/api/learn-redline',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({path})});
}
// чат + drag-drop в чат
const chat=$('#chat'),msg=$('#msg'),send=$('#send');
msg.addEventListener('input',()=>{msg.style.height='auto';msg.style.height=Math.min(msg.scrollHeight,120)+'px';});
msg.addEventListener('keydown',e=>{if(e.key==='Enter'&&!e.shiftKey){e.preventDefault();sendTask();}});
send.onclick=sendTask;
// drag-drop по ВСЕМУ окну → сообщением в диалог (верхняя зона)
async function uploadFiles(f){if(!f||!f.length)return;
const fd=new FormData();[...f].forEach(x=>fd.append('files',x));
await fetch('/api/upload',{method:'POST',body:fd}); /* сервер сам впишет в диалог */}
// перетаскивание любых картинок запрещаем на корню (Firefox не слушает CSS user-drag)
document.addEventListener('dragstart',e=>{if(e.target&&e.target.tagName==='IMG')e.preventDefault();});
// drop-зона реагирует ТОЛЬКО на реальные файлы, не на внутренние перетаскивания
const hasFiles=e=>!!(e.dataTransfer&&[...(e.dataTransfer.types||[])].includes('Files'));
['dragenter','dragover'].forEach(ev=>document.addEventListener(ev,e=>{if(!hasFiles(e))return;e.preventDefault();document.body.classList.add('drag');}));
document.addEventListener('dragleave',e=>{if(!e.relatedTarget)document.body.classList.remove('drag');});
document.addEventListener('drop',e=>{document.body.classList.remove('drag');if(!hasFiles(e))return;e.preventDefault();uploadFiles(e.dataTransfer.files);});
async function sendTask(){const t=msg.value.trim();if(!t)return;
msg.value='';msg.style.height='auto';
await fetch('/api/task',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({text:t})});}
async function sendAnswer(t){ if(!t)return;
await fetch('/api/task',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({text:t})});}
$('#newBtn').onclick=async()=>{
const t=prompt('Новое дело — опишите: клиент (ФИО), суть спора, что нужно сделать.');
if(!t||!t.trim())return;
await fetch('/api/new-case',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({text:t})});
};
let lastFace='femida';
function showTyping(on){
let t=$('#typing'); const stream=$('#stream');
if(on){
if(!t){t=document.createElement('div');t.id='typing';t.className='typing';}
t.innerHTML=`<div class="av"><img src="/faces/${lastFace}.png" alt="" onerror="this.remove()"></div><div class="dots"><i></i><i></i><i></i></div>`;
stream.appendChild(t); stream.scrollTop=stream.scrollHeight;
} else if(t){ t.remove(); }
}
function setLive(on){$('#dot').classList.toggle('live',on);$('#statusText').textContent=on?'работает':'в покое';
showTyping(on);
if(!on){$('#token').classList.remove('on');}}
function lightStation(id){
document.querySelectorAll('.station').forEach(s=>s.classList.remove('active'));
const cur=$('#st-'+id);if(!cur)return;cur.classList.add('active');
const idx=OFFICE.findIndex(a=>a.id===id);OFFICE.forEach((a,i)=>{if(i<idx)$('#st-'+a.id)?.classList.add('done');});
const pct=5.5+(idx/(OFFICE.length-1))*89;
$('#token').classList.add('on'); $('#token').style.left=pct+'%'; $('#prog').style.width=(pct-5.5)+'%';
}
function renderMsg(m){
const stream=$('#stream');const e=stream.querySelector('.empty');if(e)e.remove();
const isAgent=m.role==='agent'&&m.face;
const el=document.createElement('div');el.className='msg'+(m.role==='sys'?' sys':'')+(m.role==='me'?' me':'');
if(/✓|ГОТОВ|СОГЛАСОВАНО|ЗАВЕРШ|КАРТА ГОТОВА/i.test(m.text))el.classList.add('gate');
const av=isAgent?`<img src="/faces/${encodeURIComponent(m.face)}.png" alt="" decoding="async" onerror="this.remove()">${esc((m.name||'·')[0])}`:(m.role==='me'?'<img src="/crest.svg" alt="">':'·');
const head=isAgent?`<div class="name">${esc(m.name)}<span class="r">${esc(m.prole)}</span></div>`:'';
let extra='';
if(m.doc){const nm=m.doc.split('/').pop(); extra=`<div class="doccard" data-path="${esc(m.doc)}"><span class="ic">DOCX</span><div style="min-width:0;flex:1"><div class="dn">${esc(nm)}</div><div class="dd">нажмите — открыть</div></div><button class="learn" data-path="${esc(m.doc)}" title="Сравнить мои правки с черновиком Фемиды">📝 Изучить правки</button></div>`;}
if(m.options&&m.options.length){extra+='<div class="opts">'+m.options.map(o=>`<button class="opt">${esc(o)}</button>`).join('')+'</div>';}
el.innerHTML=`<div class="av">${av}</div><div class="bub">${head}<div class="text">${esc(m.text)}</div>${extra}</div>`;
if(m.doc){const card=el.querySelector('.doccard');
card.onclick=ev=>{if(ev.target.closest('.learn'))return; openDoc(card.dataset.path);};
const lb=card.querySelector('.learn'); if(lb)lb.onclick=ev=>{ev.stopPropagation(); learnRedline(lb.dataset.path, lb);};}
if(m.options){el.querySelectorAll('.opt').forEach(btn=>btn.onclick=()=>{el.querySelectorAll('.opt').forEach(b=>b.disabled=true);sendAnswer(btn.textContent);});}
stream.appendChild(el);
if(isAgent&&m.face)lastFace=m.face;
// потолок DOM: держим последние 200 реплик, старые выкидываем — иначе reflow пухнет
let msgs=stream.querySelectorAll('.msg');
while(msgs.length>200){msgs[0].remove();msgs=stream.querySelectorAll('.msg');}
const tp=$('#typing'); if(tp)stream.appendChild(tp); // индикатор всегда внизу
stream.scrollTop=stream.scrollHeight;
if(isAgent&&m.station)lightStation(m.station);
}
let cursor=0, es=null, retry=0;
// Реконнект вручную: EventSource при авто-реконнекте переоткрывал тот же ?after=<старый>
// и сервер реплеил ВСЮ историю заново → дубли-флуд. Теперь переподключаемся со СВЕЖИМ
// cursor + бэкофф; id-guard делает рендер идемпотентным на любой случай.
function connect(){
es=new EventSource('/api/stream?after='+cursor);
es.onopen=()=>{retry=0;};
es.onmessage=e=>{const d=JSON.parse(e.data);
if(d._status){setLive(d.active);return;}
if(d.id<=cursor)return; // уже видели — пропускаем
cursor=d.id; renderMsg(d);
};
es.onerror=()=>{es.close(); retry=Math.min(retry+1,6);
setTimeout(connect, 400*retry);};
}
async function boot(){
await loadOffice(); showClients();
// история — переживает перезагрузку
const h=await (await fetch('/api/history')).json();
(h.msgs||[]).forEach(m=>{renderMsg(m);cursor=m.id;});
setLive(h.active);
connect();
}
boot();
</script>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill="none" stroke="#FFFFFF" stroke-width="4" stroke-linecap="round">
<line x1="50" y1="20" x2="50" y2="70"/><circle cx="50" cy="16" r="5" fill="#FFFFFF" stroke="none"/>
<line x1="20" y1="32" x2="80" y2="32"/>
<path d="M20 32 L10 56 M20 32 L30 56 M10 56 a10 6 0 0 0 20 0"/>
<path d="M80 32 L70 56 M80 32 L90 56 M70 56 a10 6 0 0 0 20 0"/>
<line x1="36" y1="74" x2="64" y2="74"/>
</svg>

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB