Compare commits
8 Commits
app-v0.1.1
...
app-v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cdfbf5151 | ||
|
|
b2b6f92943 | ||
|
|
1f2a8ec05e | ||
|
|
04b516dbc1 | ||
|
|
b386c905b2 | ||
|
|
b29150a767 | ||
|
|
6fc3ad3d57 | ||
|
|
fd7ccab55b |
2
app/Cargo.lock
generated
2
app/Cargo.lock
generated
@@ -1520,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.11"
|
||||
version = "0.1.15"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.11"
|
||||
version = "0.1.15"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
||||
|
||||
4
app/shell/Cargo.lock
generated
4
app/shell/Cargo.lock
generated
@@ -2637,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.11"
|
||||
version = "0.1.15"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -2666,7 +2666,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.11"
|
||||
version = "0.1.15"
|
||||
dependencies = [
|
||||
"jarvis-app",
|
||||
"serde_json",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.11"
|
||||
version = "0.1.15"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
||||
|
||||
@@ -19,7 +19,6 @@ SetCompressor /SOLID lzma
|
||||
Name "Jarvis"
|
||||
OutFile "${OUT}"
|
||||
InstallDir "$PROGRAMFILES64\Jarvis"
|
||||
InstallDirRegKey HKLM "Software\JarvisBot" "InstallDir"
|
||||
RequestExecutionLevel admin
|
||||
BrandingText "Jarvis ${VERSION}"
|
||||
VIProductVersion "${VERSION}.0"
|
||||
@@ -149,6 +148,13 @@ Function .onInit
|
||||
Abort
|
||||
${EndIf}
|
||||
SetRegView 64
|
||||
; An update goes where Jarvis is installed (the key is in the 64-bit view, which InstallDirRegKey
|
||||
; would not read); a folder given with /D wins.
|
||||
ReadRegStr $0 HKLM "Software\JarvisBot" "InstallDir"
|
||||
${If} $0 != ""
|
||||
${AndIf} $INSTDIR == "$PROGRAMFILES64\Jarvis"
|
||||
StrCpy $INSTDIR $0
|
||||
${EndIf}
|
||||
; Shortcuts for every user of the PC, like the Program Files install itself.
|
||||
SetShellVarContext all
|
||||
!insertmacro TakeLock
|
||||
@@ -248,13 +254,24 @@ Section /o "바탕 화면 바로 가기" SecDesktop
|
||||
CreateShortCut "$DESKTOP\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
|
||||
SectionEnd
|
||||
|
||||
; Every shortcut to jarvis.exe on the desktops and in the start menus (the person's own too, and the
|
||||
; installer's from an earlier version, which an update does not make again) shows this version's
|
||||
; icon file; then Explorer redraws its icons. The 64-bit PowerShell (SysNative from this 32-bit
|
||||
; installer): a 32-bit one reads a link to Program Files as one to Program Files (x86).
|
||||
; Every shortcut to jarvis.exe on the desktops and in the start menus, their folders included (the
|
||||
; person's own too, and the installer's from an earlier version, which an update does not make
|
||||
; again) shows this version's icon file; then Explorer redraws its icons. A shortcut to another
|
||||
; Jarvis install's jarvis.exe (a folder with uninstall.exe and python-src, left behind when an
|
||||
; earlier update installed into Program Files instead) starts this one instead, so it opens the
|
||||
; Jarvis that runs, not an old copy. The paths go in through
|
||||
; the environment, so no install folder name can break the command. The 64-bit PowerShell
|
||||
; (SysNative from this 32-bit installer): a 32-bit one reads a link to Program Files as one to
|
||||
; Program Files (x86).
|
||||
Section "-Icons"
|
||||
nsExec::Exec `"$WINDIR\SysNative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -Command "$$w = New-Object -ComObject WScript.Shell; foreach ($$d in 'Desktop', 'CommonDesktopDirectory', 'Programs', 'CommonPrograms') { Get-ChildItem -LiteralPath ([Environment]::GetFolderPath($$d)) -Filter *.lnk -EA 0 | ForEach-Object { $$l = $$w.CreateShortcut($$_.FullName); if ($$l.TargetPath -ieq '$INSTDIR\jarvis.exe') { $$l.IconLocation = '$INSTDIR\${ICON_FILE},0'; $$l.Save() } } }"`
|
||||
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_EXE", t "$INSTDIR\jarvis.exe")'
|
||||
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_ICON", t "$INSTDIR\${ICON_FILE},0")'
|
||||
System::Call 'kernel32::SetEnvironmentVariable(t "JARVIS_DIR", t "$INSTDIR")'
|
||||
nsExec::Exec `"$WINDIR\SysNative\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -Command "$$w = New-Object -ComObject WScript.Shell; foreach ($$d in 'Desktop', 'CommonDesktopDirectory', 'Programs', 'CommonPrograms') { Get-ChildItem -LiteralPath ([Environment]::GetFolderPath($$d)) -Filter *.lnk -Recurse:($$d -like '*Programs') -EA 0 | ForEach-Object { $$l = $$w.CreateShortcut($$_.FullName); $$t = $$l.TargetPath; if ($$t -and (Split-Path -Leaf $$t) -ieq 'jarvis.exe' -and (Test-Path -LiteralPath (Join-Path (Split-Path $$t) 'uninstall.exe')) -and (Test-Path -LiteralPath (Join-Path (Split-Path $$t) 'python-src'))) { if ($$t -ine $$env:JARVIS_EXE) { $$l.TargetPath = $$env:JARVIS_EXE; $$l.WorkingDirectory = $$env:JARVIS_DIR }; $$l.IconLocation = $$env:JARVIS_ICON; $$l.Save() } } }"`
|
||||
Pop $0
|
||||
${If} $0 != 0
|
||||
DetailPrint "바로 가기 아이콘을 바꾸지 못했습니다 ($0)"
|
||||
${EndIf}
|
||||
System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)' ; SHCNE_ASSOCCHANGED
|
||||
SectionEnd
|
||||
|
||||
|
||||
@@ -229,7 +229,8 @@ records and "Traces"), so it works while the services are stopped. Nothing it re
|
||||
|
||||
- Each item is `said` (a voice transcript, or a chat message by someone other than Jarvis),
|
||||
`answered` (a spoken answer, or Jarvis's own chat message; to whom, when it answers someone) or
|
||||
`thought` (a trace: the question, the answer or none, how long it took and its steps). Jarvis's
|
||||
`thought` (a trace: the question, the answer or none, how long it took and its steps so far, at
|
||||
the time it was asked; `pending` while the answer is being made, with `ms` 0 until it ends). Jarvis's
|
||||
chat messages are known by the bot's user id (the first part of the stored token is that id in
|
||||
base64) and by the author of any chat answer to someone.
|
||||
- `history_query` `{said, answered, thought, via, person, channel, find, since, until, session, before, from, limit}`: the
|
||||
@@ -245,10 +246,13 @@ records and "Traces"), so it works while the services are stopped. Nothing it re
|
||||
were left out, the people who spoke (their latest name) and the channels with records (with the
|
||||
name given a chat channel in the settings), and `session`, when the latest start began (Unix
|
||||
seconds, null before the first). Without the file: no items and `missing: true`.
|
||||
- `history_stamp`: `{stamp}`, a string that changes when a record or trace is added and as a trace
|
||||
still being made gets a step or ends (the newest ids, and the number and length of the steps of
|
||||
the traces being made), cheap enough to ask twice a second; not logged.
|
||||
|
||||
## Activity (`app/src/activity.rs`)
|
||||
|
||||
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 한 일 screen: each chat
|
||||
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 로그 screen's 한 일 view: each chat
|
||||
channel action the brain's tool asked for (`chat.send`, `chat.edit`, `chat.react`, `chat.delete`,
|
||||
`chat.pin`, `chat.unpin`), each schedule delivery (`schedule.remind`, `schedule.task`) and each
|
||||
news notification (`collect.notify`), each screen capture (`screen.view`, "Screen viewing"), done or failed. The other PC control actions join it with M7. Ordinary answers are not recorded.
|
||||
@@ -690,6 +694,7 @@ back as Korean messages for the screen. The Tauri shell passes the screens' `inv
|
||||
| `discord_channel_info` `{id}` / `channel_sync_status` | a channel's Discord name and topic / each synced chat channel's last result (above) |
|
||||
| `notes_list` / `note_update` `{id, text}` / `note_delete` `{id}` | everyone's personal notes (above) / change one's text / delete one |
|
||||
| `history_query` `{said, answered, thought, via, person, channel, find, since, until, session, before, from, limit}` | the 대화 screen's records and answer traces (above, "Conversations") |
|
||||
| `history_stamp` | `{stamp}`: changes when what the 대화 screen shows may have changed (above, "Conversations") |
|
||||
| `activity_list` `{limit}` | what Jarvis did (above, "Activity"), newest first |
|
||||
| `schedules_list` / `schedule_delete` `{id}` | every person's schedules (above), soonest first, with IDs as strings / delete one |
|
||||
| `collect_results` `{target, limit}` | `{targets, items}`: every target folder with results, and the collected items newest first (`target` null: every target; `limit` 1-500, default 100) |
|
||||
@@ -708,7 +713,8 @@ its data folder, and again after each one is saved. The log hub writes to the da
|
||||
## Screens (`app/ui/`)
|
||||
|
||||
Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. All text is Korean.
|
||||
The side menu has 대화 right under 대시보드 and 앱 last.
|
||||
The side menu has 대화 right under 대시보드 and 앱 last; there is no separate update screen (updates
|
||||
are on the 앱 screen) and no separate 한 일 screen (it is a view of the 로그 screen).
|
||||
|
||||
- **First-run wizard** (while `firstRun`): data folder (free space, warning under 200 GB), PC check,
|
||||
the model to download, Discord bot (token check with the
|
||||
@@ -733,20 +739,26 @@ The side menu has 대화 right under 대시보드 and 앱 last.
|
||||
newest 100, filtered by any target that has results, each with its time, title, link and the start of its text shown
|
||||
as plain text). The 예약 screen has `schedule.chatChannel` and every person's schedules (next time
|
||||
or "다시 울리지 않음", repeat, who and how they asked, kind and text as plain text, the last
|
||||
outcome, delete). The 앱 screen has `app.closeButton` (완전 종료 or 트레이로 최소화) with a note
|
||||
that the tray icon opens the window again and its menu quits; saving it needs no restart.
|
||||
outcome, delete). The 앱 screen has the update card (below) first, then `app.closeButton` (완전 종료
|
||||
or 트레이로 최소화) with a note that the tray icon opens the window again and its menu quits;
|
||||
saving it needs no restart.
|
||||
- **사람별 지침**: every person's notes (name and ID, the text in a box, save and delete).
|
||||
- **대화**: what people said, Jarvis's answers and how each answer was made, in time order with a
|
||||
date line between days; people's words on the left, Jarvis's on the right with whom it answered,
|
||||
each with its time, voice or chat and channel, and a copy button. A trace is a closed card (whose
|
||||
question, how many tool calls, seconds, no answer) that opens to the question, the records and
|
||||
notes it was given, the tools offered, the plan, the model's thinking, each tool call (name,
|
||||
arguments, success, failure or skipped and why, its result) and the answer. Filters: the three
|
||||
arguments, success, failure or skipped and why, its result) and the answer. A trace sits at the
|
||||
time it was asked and is there while the answer is made (`pending`, "답을 만드는 중"): it fills in
|
||||
step by step, and one seen being made is open and stays open with its answer unless the user
|
||||
closes it. Filters: the three
|
||||
kinds as chips, "현재 세션" (off by default: only items since the bot was last started, `session`;
|
||||
the count line starts with that start's date and time, and with no start yet in this app run the
|
||||
list says so; a new start while it is on starts the list over from that start), where (음성,
|
||||
채팅, 정기 작업), person, channel, one day and text; "실시간" (on by
|
||||
default) re-reads the live window every 3 seconds: every item from its first one on (`from`, up to
|
||||
default) asks for `history_stamp` twice a second and re-reads the live window at once when it
|
||||
changed (so a trace shows from its question on, before a quick answer ends), and every 3 seconds
|
||||
anyway: every item from its first one on (`from`, up to
|
||||
2,000). Only items in that window change on screen, an edited message included; items paged back
|
||||
past it stay as they were loaded (edits and deletes there show after a reload of the screen). The
|
||||
screen redraws only when an item changed, keeping the cards the user opened open and the scroll
|
||||
@@ -757,12 +769,13 @@ The side menu has 대화 right under 대시보드 and 앱 last.
|
||||
how far back it goes; a filter change drops every answer to a request made before it, and a live
|
||||
answer older than the newest one asked is dropped; "생각 모두 펼치기/접기"; a count of each kind
|
||||
shown. The paging is `app/ui/talk.js`, pure, checked by `node --test app/tests/ui/talk.test.mjs`.
|
||||
- **한 일**: the activity (time, kind, target, who asked, outcome and why it failed), newest 200,
|
||||
with a refresh button.
|
||||
- **업데이트**: the version here, the state, "다시 확인", "받기" (with its percentage) and "설치하고
|
||||
다시 시작", and the release's notes as plain text. The app checks once when the main screens open;
|
||||
a newer release renames the button "업데이트 (새 버전)" and says so once.
|
||||
- **Logs**: tab, level and text filters, pause, live follow (lines after the last seen), "최근 오류
|
||||
- **업데이트** (a card on the 앱 screen, re-read every second while it is shown): the version here,
|
||||
the state, "다시 확인", "받기" (with its percentage) and "설치하고 다시 시작", and the release's
|
||||
notes as plain text. The app checks once when the main screens open; a newer release renames the
|
||||
앱 button "앱 (새 버전)" and says so once.
|
||||
- **Logs** (로그): two views switched at the top, 로그 and 한 일. 한 일 is the activity (time, kind,
|
||||
target, who asked, outcome and why it failed), newest 200, read when the view opens, with a
|
||||
refresh button; there is no separate 한 일 screen. 로그 has tab, level and text filters, pause, live follow (lines after the last seen), "최근 오류
|
||||
복사" (to the clipboard; over 2,000 characters it suggests the zip), and the zip export by days.
|
||||
|
||||
`jarvis-admin-dev [--port N] [--ui DIR] [--location FILE]` (development only) serves `app/ui` and
|
||||
@@ -834,7 +847,9 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a
|
||||
`Jarvis-Setup-<version>.exe` with its `.sha256`. The installer is about 10 MB; models and runtimes
|
||||
come with the first-run wizard into the data folder, which the installer never touches.
|
||||
|
||||
- Program Files (`Jarvis`), one administrator prompt, 64-bit Windows 10/11 only; Korean pages:
|
||||
- Program Files (`Jarvis`), or where Jarvis is already installed (`HKLM\Software\JarvisBot`
|
||||
`InstallDir`, 64-bit view; a folder given with `/D` wins), one administrator prompt, 64-bit
|
||||
Windows 10/11 only; Korean pages:
|
||||
folder, components, progress, finish ("Jarvis 실행", started through Explorer so the app runs as
|
||||
the signed-in user, not as administrator).
|
||||
- Components: Jarvis (always), start menu shortcut (on), desktop shortcut (off), the virtual
|
||||
@@ -847,8 +862,14 @@ come with the first-run wizard into the data folder, which the installer never t
|
||||
content (`jarvis-<sha256 prefix>.ico`; the old one is deleted), because Windows keeps an icon it
|
||||
has shown by its path and a changed icon under the old path stays old on the desktop and in
|
||||
search. After the shortcuts, every `.lnk` to `jarvis.exe` on the desktops and in the start menus
|
||||
(the installing user's and every user's, the person's own and an earlier version's included)
|
||||
gets this icon file, and Explorer is told to redraw (`SHCNE_ASSOCCHANGED`).
|
||||
and their folders (the installing user's and every user's, the person's own and an earlier
|
||||
version's included) gets this icon file (the paths reach PowerShell through the environment, so
|
||||
any folder name works; a failure is a line in the details), and Explorer is told to redraw (`SHCNE_ASSOCCHANGED`).
|
||||
A shortcut to the `jarvis.exe` of another folder that holds a Jarvis install (`uninstall.exe` and
|
||||
`python-src` next to it: a copy left behind when an update before 0.1.12 installed into Program
|
||||
Files instead of the chosen folder) is pointed at this install's `jarvis.exe` (and its working
|
||||
folder at this folder), so it starts the Jarvis that is kept up to date, and a start while it runs
|
||||
shows the running window instead of a second, old Jarvis. The old copy itself is not touched.
|
||||
- The WebView2 runtime is installed with Microsoft's bootstrapper (inside the installer) only when
|
||||
the PC has none, before any file is copied. When it is still missing afterwards the installer
|
||||
asks to retry or cancel; silently it stops with exit code 3, nothing installed and nothing
|
||||
|
||||
@@ -189,7 +189,10 @@ impl AdminApi {
|
||||
}
|
||||
|
||||
pub async fn call(&self, command: &str, args: Value) -> Result<Value, String> {
|
||||
crate::debug_log!("admin", "command {command}");
|
||||
// The 대화 screen asks for the stamp twice a second: a line each time would bury the log.
|
||||
if command != "history_stamp" {
|
||||
crate::debug_log!("admin", "command {command}");
|
||||
}
|
||||
match command {
|
||||
"app_status" => {
|
||||
let dir = self.dir.lock().unwrap().clone();
|
||||
@@ -405,6 +408,13 @@ impl AdminApi {
|
||||
crate::info_log!("admin", "note {id} deleted");
|
||||
Ok(json!({"deleted": id.to_string()}))
|
||||
}
|
||||
// The 대화 screen (admin.spec.md, "Conversations"): whether what it shows changed.
|
||||
"history_stamp" => {
|
||||
let path = self.dir()?.path().join("memory").join("history.sqlite");
|
||||
let stamp = tokio::task::spawn_blocking(move || crate::history_view::stamp(&path))
|
||||
.await.map_err(|e| e.to_string())??;
|
||||
Ok(json!({"stamp": stamp}))
|
||||
}
|
||||
// The 대화 screen (admin.spec.md, "Conversations"): records and answer traces.
|
||||
"history_query" => {
|
||||
let dir = self.dir()?;
|
||||
@@ -603,6 +613,7 @@ mod tests {
|
||||
let data = base.join("d");
|
||||
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
|
||||
assert_eq!(a.call("history_query", json!({})).await.unwrap()["missing"], true);
|
||||
let before = a.call("history_stamp", json!({})).await.unwrap();
|
||||
std::fs::create_dir_all(data.join("memory")).unwrap();
|
||||
let c = rusqlite::Connection::open(data.join("memory").join("history.sqlite")).unwrap();
|
||||
c.execute_batch(crate::history_view::TEST_SCHEMA).unwrap();
|
||||
@@ -617,6 +628,10 @@ mod tests {
|
||||
assert_eq!(v["channels"][0]["name"], "잡담");
|
||||
let v = a.call("history_query", json!({"said": false, "find": "반가"})).await.unwrap();
|
||||
assert_eq!(v["items"][0]["type"], "thought");
|
||||
// The screen polls the stamp and reads again only when it changed.
|
||||
let now = a.call("history_stamp", json!({})).await.unwrap();
|
||||
assert_ne!(now["stamp"], before["stamp"]);
|
||||
assert_eq!(a.call("history_stamp", json!({})).await.unwrap(), now);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -215,11 +215,13 @@ pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String>
|
||||
let (id, ts): (i64, f64) = (r.get(0)?, r.get(1)?);
|
||||
let user: String = r.get(4)?;
|
||||
let steps: String = r.get(8)?;
|
||||
let ms: i64 = r.get(7)?;
|
||||
Ok(((ts, 1, id), json!({
|
||||
"key": format!("t{id}"), "type": "thought", "at": ts, "via": r.get::<_, String>(2)?,
|
||||
"channel": r.get::<_, Option<String>>(3)?,
|
||||
"who": {"id": user.clone(), "name": name_of(&user)},
|
||||
"question": r.get::<_, String>(5)?, "answer": r.get::<_, String>(6)?, "ms": r.get::<_, i64>(7)?,
|
||||
"question": r.get::<_, String>(5)?, "answer": r.get::<_, String>(6)?, "ms": ms.max(0),
|
||||
"pending": ms < 0,
|
||||
"steps": serde_json::from_str::<Value>(&steps).unwrap_or(json!([])),
|
||||
})))
|
||||
}).map_err(err)?;
|
||||
@@ -252,6 +254,26 @@ pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String>
|
||||
"people": people, "channels": channels}))
|
||||
}
|
||||
|
||||
/// A cheap mark of what the 대화 screen shows that changes when something is said or a question
|
||||
/// arrives (the newest record and trace), and as an answer is made (its steps) and ends, so the
|
||||
/// screen can poll it often and read the items again only when it changed.
|
||||
pub fn stamp(path: &Path) -> Result<String, String> {
|
||||
if !path.is_file() {
|
||||
return Ok("missing".into());
|
||||
}
|
||||
let c = open(path)?;
|
||||
let err = |e: rusqlite::Error| format!("대화 기록을 읽지 못했습니다: {e}");
|
||||
let said: Option<i64> = c.query_row("SELECT MAX(id) FROM history", [], |r| r.get(0)).map_err(err)?;
|
||||
let thought: (Option<i64>, i64, Option<i64>) = if has_traces(&c) {
|
||||
c.query_row("SELECT MAX(id), (SELECT COUNT(*) FROM traces WHERE ms < 0), \
|
||||
(SELECT SUM(LENGTH(steps)) FROM traces WHERE ms < 0) FROM traces", [], |r| Ok((r.get(0)?, r.get(1)?, r.get(2)?)))
|
||||
.map_err(err)?
|
||||
} else {
|
||||
(None, 0, None)
|
||||
};
|
||||
Ok(format!("{said:?}/{thought:?}"))
|
||||
}
|
||||
|
||||
/// The history store's tables as `src/jarvis/memory/history.py` makes them, for tests.
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_SCHEMA: &str = "
|
||||
@@ -384,6 +406,43 @@ mod tests {
|
||||
assert!(Cursor::of(&json!({"at": 1.0, "key": "x1"})).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_trace_still_being_made_reads_as_pending_with_its_steps_so_far() {
|
||||
let (path, c) = db("pending");
|
||||
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
|
||||
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
|
||||
rusqlite::params![10.5, "voice", "vc", "1", "서울 날씨 어때", "", -1, r#"[{"kind":"tools","names":["getWeather"]}]"#])
|
||||
.unwrap();
|
||||
let v = query(&path, None, &Query::default()).unwrap();
|
||||
let t = &v["items"][1];
|
||||
assert_eq!((t["type"].as_str(), t["pending"].as_bool()), (Some("thought"), Some(true)));
|
||||
assert_eq!(t["steps"][0]["names"], json!(["getWeather"]));
|
||||
let done = query(&sample("pending-done"), None, &Query::default()).unwrap();
|
||||
assert_eq!(done["items"][1]["pending"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_stamp_changes_when_a_question_is_answered_step_by_step_and_only_then() {
|
||||
let (path, c) = db("stamp");
|
||||
let now = || stamp(&path).unwrap();
|
||||
let empty = now();
|
||||
assert_eq!(now(), empty, "nothing changed");
|
||||
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
|
||||
let said = now();
|
||||
assert_ne!(said, empty);
|
||||
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) \
|
||||
VALUES (10.5, 'voice', 'vc', '1', '서울 날씨 어때', '', -1, '[]')", []).unwrap();
|
||||
let asked = now();
|
||||
assert_ne!(asked, said, "a trace still being made");
|
||||
c.execute("UPDATE traces SET steps = '[{\"kind\":\"tools\",\"names\":[\"getWeather\"]}]'", []).unwrap();
|
||||
let step = now();
|
||||
assert_ne!(step, asked, "a step added");
|
||||
c.execute("UPDATE traces SET answer = '맑습니다', ms = 900", []).unwrap();
|
||||
assert_ne!(now(), step, "the answer");
|
||||
let dir = std::env::temp_dir().join(format!("jarvis-history-view-nostamp-{}", std::process::id()));
|
||||
assert!(stamp(&dir.join("history.sqlite")).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bot_id_comes_from_its_token() {
|
||||
assert_eq!(bot_id_of_token("MTIzNDU2Nzg5MDEyMzQ1Njc4.GxYzAb.abcdef").as_deref(), Some("123456789012345678"));
|
||||
|
||||
@@ -385,7 +385,8 @@ const ACTIVITY = { "chat.send": "채팅 보내기", "chat.edit": "채팅 고치
|
||||
"chat.delete": "채팅 지우기", "chat.pin": "고정", "chat.unpin": "고정 풀기",
|
||||
"schedule.remind": "예약 알림 전달", "schedule.task": "정기 작업 전달", "collect.notify": "수집 소식 알림" };
|
||||
/** What Jarvis did outside its answers (admin.spec.md, "Activity"): kind, target, who asked, outcome. */
|
||||
function activityScreen() {
|
||||
/** The 로그 screen's 한 일 view: what Jarvis did in chat channels and schedule deliveries. */
|
||||
function activityView() {
|
||||
const list = h("div");
|
||||
const load = async () => {
|
||||
try {
|
||||
@@ -400,9 +401,9 @@ function activityScreen() {
|
||||
} catch (err) { fail(err); }
|
||||
};
|
||||
load();
|
||||
return h("div", {}, h("h1", {}, "한 일"), h("div", { class: "card" },
|
||||
return h("div", { class: "card" },
|
||||
h("div", { class: "hint" }, "자비스가 채팅 채널에서 한 동작과 예약 전달을 종류, 대상, 시킨 사람, 결과만 남깁니다. 내용은 남기지 않고 30일 뒤 지웁니다."),
|
||||
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list));
|
||||
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list);
|
||||
}
|
||||
|
||||
// ---- conversations ------------------------------------------------------------------------------
|
||||
@@ -449,7 +450,9 @@ function conversationScreen() {
|
||||
const day = h("input", { type: "date" });
|
||||
const find = h("input", { type: "text", placeholder: "찾기 (말, 답, 생각)", style: "max-width:220px" });
|
||||
const live = h("input", { type: "checkbox", class: "switch", checked: true });
|
||||
const open = new Set(); // traces the user opened stay open across refreshes
|
||||
// Traces the user opened stay open across refreshes, and so does one seen while being made
|
||||
// unless the user closed it.
|
||||
const open = new Set(), shut = new Set();
|
||||
// `page`: the live window and the older pages (talk.js). Each filter change starts a new epoch;
|
||||
// answers from an earlier epoch, and live answers older than the newest one asked, are dropped.
|
||||
let expandAll = false, sig = null, page = empty(), missing = false, sessionAt = null;
|
||||
@@ -474,15 +477,20 @@ function conversationScreen() {
|
||||
const where = h("span", { class: "small muted" }, timeOf(i.at), " · ", VIA[i.via] || i.via, i.channel ? " · " + channelName(i.channel) : "");
|
||||
if (i.type === "thought") {
|
||||
const tools = (i.steps || []).filter((s) => s.kind === "tool" && !s.skipped).length;
|
||||
const summary = h("summary", {}, h("span", { class: "who" }, "자비스 생각"), " ",
|
||||
h("span", { class: "small muted" }, `${i.who.name || i.who.id}의 말에 답하며`, tools ? ` · 도구 ${tools}번` : "",
|
||||
i.pending ? " · 답을 만드는 중" : ` · ${(i.ms / 1000).toFixed(1)}초${i.answer ? "" : " · 답 없음"}`), " ", where);
|
||||
if (i.pending && !shut.has(i.key)) open.add(i.key); // stays open with its answer once done
|
||||
const d = h("details", { class: "msg thought", open: expandAll || open.has(i.key) },
|
||||
h("summary", {}, h("span", { class: "who" }, "자비스 생각"), " ",
|
||||
h("span", { class: "small muted" }, `${i.who.name || i.who.id}의 말에 답하며`, tools ? ` · 도구 ${tools}번` : "",
|
||||
` · ${(i.ms / 1000).toFixed(1)}초`, i.answer ? "" : " · 답 없음"), " ", where),
|
||||
summary,
|
||||
h("div", { class: "steps" },
|
||||
h("div", { class: "step-row" }, h("div", { class: "k" }, "받은 말"), h("div", {}, i.question)),
|
||||
(i.steps || []).map(traceStep),
|
||||
h("div", { class: "step-row" }, h("div", { class: "k" }, "답"), i.answer ? h("div", {}, i.answer) : h("span", { class: "badge bad" }, "답하지 못함"))));
|
||||
d.addEventListener("toggle", () => (d.open ? open.add(i.key) : open.delete(i.key)));
|
||||
h("div", { class: "step-row" }, h("div", { class: "k" }, "답"), i.pending ? h("div", {}, h("span", { class: "badge warn" }, "만드는 중"))
|
||||
: i.answer ? h("div", {}, i.answer) : h("span", { class: "badge bad" }, "답하지 못함"))));
|
||||
summary.addEventListener("click", () => {
|
||||
if (d.open) { open.delete(i.key); shut.add(i.key); } else { open.add(i.key); shut.delete(i.key); }
|
||||
});
|
||||
return d;
|
||||
}
|
||||
const mine = i.type === "answered";
|
||||
@@ -576,12 +584,26 @@ function conversationScreen() {
|
||||
h("div", { class: "row" }, saidChip, answeredChip, thoughtChip, sessionChip),
|
||||
h("div", { class: "row" }, via, person, channel, day, find),
|
||||
h("div", { class: "row" }, h("label", { class: "row small muted" }, live, "실시간"),
|
||||
h("button", { class: "btn", onclick: () => { expandAll = !expandAll; if (!expandAll) open.clear(); sig = null; load(); } }, "생각 모두 펼치기/접기"),
|
||||
h("button", { class: "btn", onclick: () => { expandAll = !expandAll; open.clear(); shut.clear(); sig = null; load(); } }, "생각 모두 펼치기/접기"),
|
||||
h("button", { class: "btn", onclick: () => { sig = null; load(); } }, "새로 고침"), summary)),
|
||||
h("div", { class: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다. 실시간으로 다시 읽는 것은 최근 2,000개까지이고, 그보다 앞서 불러온 기록의 수정과 삭제는 화면을 다시 열면 보입니다."),
|
||||
h("div", { class: "hint", style: "margin:8px 0" }, "사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보여 줍니다. 자비스가 말을 알아들은 순간 생각이 나타나고, 답을 만드는 동안 단계가 하나씩 채워집니다. 모델 생각은 생각 모드가 켜진 답에만 있습니다. 생각 기록은 30일 동안 둡니다. 실시간으로 다시 읽는 것은 최근 2,000개까지이고, 그보다 앞서 불러온 기록의 수정과 삭제는 화면을 다시 열면 보입니다."),
|
||||
h("div", { class: "row", style: "justify-content:center" }, more), box);
|
||||
load();
|
||||
return { view, tick: () => live.checked && load() };
|
||||
// Twice a second the store's stamp (cheap): when something was said, a question arrived or an
|
||||
// answer moved on, the window is read again at once, so a trace shows from its question on and
|
||||
// fills in as it goes. Every 3 seconds it is read anyway (an edited message changes no stamp).
|
||||
let ticks = 0, stamp = null, asking = false;
|
||||
const tick = async () => {
|
||||
if (!live.checked) return;
|
||||
if (++ticks % 6 === 0) return load();
|
||||
if (asking) return;
|
||||
asking = true;
|
||||
try {
|
||||
const s = (await api("history_stamp")).stamp;
|
||||
if (s !== stamp) { stamp = s; load(); }
|
||||
} catch (e) { /* the next tick tries again */ } finally { asking = false; }
|
||||
};
|
||||
return { view, tick };
|
||||
}
|
||||
|
||||
async function settingsScreen(screen, title, extra) {
|
||||
@@ -801,7 +823,7 @@ function logsScreen() {
|
||||
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const from = h("input", { type: "date", value: today }), to = h("input", { type: "date", value: today });
|
||||
const view = h("div", {}, h("h1", {}, "로그"),
|
||||
const logs = h("div", {},
|
||||
h("div", { class: "row", style: "margin-bottom:10px" }, tab, level, find, h("label", { class: "row small muted" }, pause, "일시정지"),
|
||||
h("button", { class: "btn", onclick: async () => {
|
||||
try {
|
||||
@@ -819,14 +841,25 @@ function logsScreen() {
|
||||
toast(`${r.path}에 저장했습니다${r.droppedLines ? ` (10MB를 넘어 오래된 ${r.droppedLines}줄은 뺐습니다)` : ""}`);
|
||||
} catch (e) { fail(e); }
|
||||
} }, "zip으로 저장")));
|
||||
// 로그 and 한 일 (the activity) on one screen; 한 일 is read again each time it is opened.
|
||||
const body = h("div");
|
||||
const switches = [["로그", () => logs], ["한 일", activityView]].map(([label, make]) => {
|
||||
const b = h("button", { class: "btn", onclick: () => {
|
||||
for (const x of switches) x.classList.toggle("primary", x === b);
|
||||
body.replaceChildren(make());
|
||||
} }, label);
|
||||
return b;
|
||||
});
|
||||
const view = h("div", {}, h("h1", {}, "로그"), h("div", { class: "row", style: "margin-bottom:12px" }, switches), body);
|
||||
switches[0].click();
|
||||
reload();
|
||||
return { view, tick: poll };
|
||||
return { view, tick: () => logs.isConnected && poll() };
|
||||
}
|
||||
|
||||
// ---- update -------------------------------------------------------------------------------------
|
||||
|
||||
/** The update screen: the version here, the newest release, its download and install. */
|
||||
function updateScreen() {
|
||||
/** The 앱 screen's update card: the version here, the newest release, its download and install. */
|
||||
function updateCard() {
|
||||
const body = h("div");
|
||||
let key = null;
|
||||
async function tick() {
|
||||
@@ -844,7 +877,7 @@ function updateScreen() {
|
||||
const line = { idle: "아직 확인하지 않았습니다", checking: "확인하는 중…", upToDate: "최신 버전입니다",
|
||||
available: `새 버전 ${u.latest?.version}이 있습니다`, downloading: `받는 중${pct != null ? ` ${pct}%` : ""}`,
|
||||
ready: `${u.latest?.version}을 설치할 준비가 됐습니다`, failed: u.error ?? "실패했습니다" }[u.phase] ?? u.phase;
|
||||
body.replaceChildren(h("div", { class: "card" },
|
||||
body.replaceChildren(h("div", { class: "card" }, h("h2", {}, "업데이트"),
|
||||
h("div", { class: "kv" }, h("span", { class: "k" }, "현재 버전"), h("span", {}, u.current),
|
||||
h("span", { class: "k" }, "상태"), h("span", { style: u.phase === "failed" ? "color:var(--bad)" : "" }, line)),
|
||||
h("div", { class: "row", style: "margin-top:12px" },
|
||||
@@ -856,15 +889,15 @@ function updateScreen() {
|
||||
h("pre", { class: "small", style: "white-space:pre-wrap" }, u.latest.notes)) : "");
|
||||
}
|
||||
tick();
|
||||
return { view: h("div", {}, h("h1", {}, "업데이트"), body), tick };
|
||||
return { view: body, tick };
|
||||
}
|
||||
|
||||
/** Look for a new version once when the app opens; the nav button says so when there is one. */
|
||||
async function checkUpdate() {
|
||||
try {
|
||||
const u = await api("update_check");
|
||||
if (u.latest) { $("#nav-update").textContent = "업데이트 (새 버전)"; toast(`새 버전 ${u.latest.version}이 있습니다. 업데이트 화면에서 설치할 수 있습니다.`); }
|
||||
} catch (e) { /* offline: the update screen shows why */ }
|
||||
if (u.latest) { $("#nav-app").textContent = "앱 (새 버전)"; toast(`새 버전 ${u.latest.version}이 있습니다. 앱 화면에서 설치할 수 있습니다.`); }
|
||||
} catch (e) { /* offline: the 앱 screen shows why */ }
|
||||
}
|
||||
|
||||
// ---- navigation ---------------------------------------------------------------------------------
|
||||
@@ -900,19 +933,20 @@ async function show(name) {
|
||||
try {
|
||||
if (name === "dashboard") { screen.replaceChildren(); await refresh(); ticker = setInterval(refresh, 1000); return; }
|
||||
if (name === "logs") { const l = logsScreen(); screen.replaceChildren(l.view); ticker = setInterval(l.tick, 1000); return; }
|
||||
if (name === "activity") { screen.replaceChildren(activityScreen()); return; }
|
||||
if (name === "conversations") { const c = conversationScreen(); screen.replaceChildren(c.view); ticker = setInterval(c.tick, 3000); return; }
|
||||
if (name === "conversations") { const c = conversationScreen(); screen.replaceChildren(c.view); ticker = setInterval(c.tick, 500); return; }
|
||||
if (name === "notes") { screen.replaceChildren(notesScreen()); return; }
|
||||
if (name === "update") { const u = updateScreen(); screen.replaceChildren(u.view); ticker = setInterval(u.tick, 1000); return; }
|
||||
const titles = { bot: "봇", channels: "채널·호출", chat: "채팅 채널", memory: "대화 기억", model: "모델", features: "기능",
|
||||
collect: "백그라운드 수집", game: "게임 모드", schedule: "예약", pcControl: "PC 제어", app: "앱" };
|
||||
const update = name === "app" ? updateCard() : null;
|
||||
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard()
|
||||
: name === "app" ? h("div", { class: "hint", style: "margin-bottom:12px" }, "트레이로 최소화하면 창만 숨고 봇과 서비스는 계속 돕니다. 작업 표시줄 오른쪽의 Jarvis 아이콘을 누르면 창이 다시 열리고, 아이콘의 오른쪽 클릭 메뉴에서 완전 종료할 수 있습니다. 저장하면 바로 적용됩니다.") : null;
|
||||
: name === "app" ? h("div", {}, update.view, h("div", { class: "hint", style: "margin:12px 0" }, "트레이로 최소화하면 창만 숨고 봇과 서비스는 계속 돕니다. 작업 표시줄 오른쪽의 Jarvis 아이콘을 누르면 창이 다시 열리고, 아이콘의 오른쪽 클릭 메뉴에서 완전 종료할 수 있습니다. 저장하면 바로 적용됩니다.")) : null;
|
||||
const view = await settingsScreen(name, titles[name], extra);
|
||||
if (name === "collect") view.append(await collectResults());
|
||||
if (name === "schedule") view.append(await scheduleList());
|
||||
if (name === "pcControl") view.append(await permissionsCard());
|
||||
if (my === gen) screen.replaceChildren(view);
|
||||
if (my !== gen) return;
|
||||
screen.replaceChildren(view);
|
||||
if (update) ticker = setInterval(update.tick, 1000);
|
||||
} catch (e) { fail(e); }
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,9 @@
|
||||
<button data-screen="schedule" class="nav">예약</button>
|
||||
<button data-screen="pcControl" class="nav">PC 제어</button>
|
||||
<button data-screen="notes" class="nav">사람별 지침</button>
|
||||
<button data-screen="activity" class="nav">한 일</button>
|
||||
<button data-screen="game" class="nav">게임 모드</button>
|
||||
<button data-screen="logs" class="nav">로그</button>
|
||||
<button data-screen="update" class="nav" id="nav-update">업데이트</button>
|
||||
<button data-screen="app" class="nav">앱</button>
|
||||
<button data-screen="app" class="nav" id="nav-app">앱</button>
|
||||
<div class="side-foot" id="version"></div>
|
||||
</nav>
|
||||
<main id="screen" class="screen"></main>
|
||||
|
||||
@@ -44,13 +44,13 @@ CREATE TABLE IF NOT EXISTS presence (
|
||||
CREATE INDEX IF NOT EXISTS presence_user ON presence(user_id, channel_id);
|
||||
CREATE TABLE IF NOT EXISTS traces (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ts REAL NOT NULL, -- when the answer was ready
|
||||
ts REAL NOT NULL, -- when it was asked
|
||||
via TEXT NOT NULL, -- voice | chat | task
|
||||
channel_id TEXT, -- where it was asked; none for a task
|
||||
user_id TEXT NOT NULL,
|
||||
question TEXT NOT NULL,
|
||||
answer TEXT NOT NULL, -- empty when the brain gave none
|
||||
ms INTEGER NOT NULL,
|
||||
ms INTEGER NOT NULL, -- -1 while the answer is being made
|
||||
steps TEXT NOT NULL -- JSON list (history.spec.md, "Traces")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS traces_ts ON traces(ts);
|
||||
@@ -107,6 +107,10 @@ class HistoryContext:
|
||||
matches: List[str] = field(default_factory=list)
|
||||
|
||||
|
||||
def _steps_json(steps: list) -> str:
|
||||
return json.dumps(steps, ensure_ascii=False, default=str)
|
||||
|
||||
|
||||
def _fold(text: str) -> str:
|
||||
"""One Unicode folding for stored text and query words alike (NFKC, then case folding),
|
||||
so matching does not depend on SQLite's ASCII-only lower()."""
|
||||
@@ -225,16 +229,34 @@ class HistoryStore:
|
||||
|
||||
# -- maintenance --------------------------------------------------------
|
||||
|
||||
def add_trace(self, via: str, channel_id: Optional[str], user_id: str, question: str, answer: str,
|
||||
steps: list, ms: int, ts: float) -> int:
|
||||
def start_trace(self, via: str, channel_id: Optional[str], user_id: str, question: str, ts: float) -> int:
|
||||
"""A trace from the moment it was asked: no answer yet and ``ms`` -1."""
|
||||
with self._lock:
|
||||
cur = self._conn.execute(
|
||||
"INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
|
||||
(ts, via, channel_id, user_id, question, answer or "", int(ms),
|
||||
json.dumps(steps, ensure_ascii=False, default=str)))
|
||||
"INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,'',-1,'[]')",
|
||||
(ts, via, channel_id, user_id, question))
|
||||
self._conn.commit()
|
||||
return int(cur.lastrowid)
|
||||
|
||||
def trace_steps(self, trace_id: int, steps: list) -> None:
|
||||
"""The steps so far of a trace still being made."""
|
||||
with self._lock:
|
||||
self._conn.execute("UPDATE traces SET steps=? WHERE id=?", (_steps_json(steps), trace_id))
|
||||
self._conn.commit()
|
||||
|
||||
def finish_trace(self, trace_id: int, answer: str, steps: list, ms: int) -> None:
|
||||
with self._lock:
|
||||
self._conn.execute("UPDATE traces SET answer=?, steps=?, ms=? WHERE id=?",
|
||||
(answer or "", _steps_json(steps), max(0, int(ms)), trace_id))
|
||||
self._conn.commit()
|
||||
|
||||
def close_unfinished_traces(self) -> int:
|
||||
"""End, with no answer, the traces a killed run left being made (the host calls it at start)."""
|
||||
with self._lock:
|
||||
n = self._conn.execute("UPDATE traces SET ms=0 WHERE ms < 0").rowcount
|
||||
self._conn.commit()
|
||||
return n
|
||||
|
||||
def traces_of(self, person: str) -> List[Trace]:
|
||||
with self._lock:
|
||||
rows = self._conn.execute(
|
||||
|
||||
@@ -73,10 +73,13 @@ Setting `since` (default none, meaning the whole history) drops records older th
|
||||
How each answer was made, for the management app's 대화 screen (`app/src/admin.spec.md`,
|
||||
"Conversations"). A trace is never a record: no read above returns it and it never reaches a prompt.
|
||||
|
||||
- `add_trace(via, channel_id, user_id, question, answer, steps, ms, ts)`: one per `reply` the brain
|
||||
ran (`via` `voice`, `chat` or `task`; `channel_id` where it was asked, none for a task; `answer`
|
||||
empty when the brain gave none; `ts` when it was ready; `ms` how long it took). `steps` is a JSON
|
||||
list in the order they happened:
|
||||
- One per `reply` the brain ran, kept from the moment it was asked so the screen can show it while
|
||||
the answer is made: `start_trace(via, channel_id, user_id, question, ts)` (`via` `voice`, `chat` or
|
||||
`task`; `channel_id` where it was asked, none for a task; `ts` when it was asked) stores it with no
|
||||
answer and `ms` -1, `trace_steps(id, steps)` stores the steps so far, and
|
||||
`finish_trace(id, answer, steps, ms)` the end (`answer` empty when the brain gave none; `ms` how
|
||||
long it took). `close_unfinished_traces()`, which the host calls at start, ends with no answer the
|
||||
traces a killed run left at -1. `steps` is a JSON list in the order they happened:
|
||||
- `{"kind": "records", "recent": [...], "matches": [...], "notes": n}`: the history lines and the
|
||||
number of personal notes the brain was given (the voice worker adds it first),
|
||||
- `{"kind": "tools", "names": [...]}`: the tools the turn was offered after routing,
|
||||
@@ -87,7 +90,7 @@ How each answer was made, for the management app's 대화 screen (`app/src/admin
|
||||
error (at most 2,000 characters), or `"skipped": "not_allowed" | "duplicate"` with `ok` false
|
||||
for a call the engine refused.
|
||||
The engine writes them through `turn_state.trace` (`reply/turn_state.py`), which does nothing when
|
||||
no trace list was set (v1, evals).
|
||||
no trace list was set (v1, evals); the voice worker's list stores the steps as each is added.
|
||||
- `traces_of(person)`: the person's traces, oldest first. `forget_person` deletes them too.
|
||||
- `purge_traces_older_than(ts)`: the voice worker keeps traces 30 days (`TRACE_KEEP_DAYS`) and
|
||||
removes older ones when it starts. `purge_older_than` removes old traces with the records.
|
||||
|
||||
@@ -55,6 +55,37 @@ MAX_NOTE_CHARS = 300
|
||||
TRACE_KEEP_DAYS = 30
|
||||
|
||||
|
||||
class _LiveTrace(list):
|
||||
"""A reply's trace (history.spec.md, "Traces"): stored as soon as the request arrives and again
|
||||
as each step is added, so the 대화 screen fills it in while the answer is made. The engine adds
|
||||
steps from the brain's thread. Storing never stops the answer."""
|
||||
|
||||
def __init__(self, store, via: str, channel: str | None, user: str, question: str):
|
||||
super().__init__()
|
||||
self.store, self.began, self.id = store, time.time(), None
|
||||
if store is not None:
|
||||
self.id = self._keep(store.start_trace, via, channel, user, question, ts=self.began)
|
||||
|
||||
@staticmethod
|
||||
def _keep(write, *args, **kw):
|
||||
try:
|
||||
return write(*args, **kw)
|
||||
except Exception as e: # noqa: BLE001 - a trace is a view, not part of the answer
|
||||
debug_log(f"trace not kept: {type(e).__name__}", "llm")
|
||||
return None
|
||||
|
||||
def append(self, step) -> None:
|
||||
super().append(step)
|
||||
if self.id is not None:
|
||||
self._keep(self.store.trace_steps, self.id, list(self))
|
||||
|
||||
def finish(self, answer: str) -> None:
|
||||
if self.id is not None:
|
||||
self._keep(self.store.finish_trace, self.id, answer, list(self),
|
||||
ms=round((time.time() - self.began) * 1000))
|
||||
self.id = None
|
||||
|
||||
|
||||
class VoiceWorker:
|
||||
def _partials_held(self) -> bool:
|
||||
return self.llm_game and self.answering > 0
|
||||
@@ -118,6 +149,9 @@ class VoiceWorker:
|
||||
n = self.history.close_open_presence(time.time())
|
||||
if n:
|
||||
debug_log(f"closed {n} presence intervals left open by a previous run", "voice_worker")
|
||||
n = self.history.close_unfinished_traces()
|
||||
if n:
|
||||
debug_log(f"closed {n} answer traces left unfinished by a previous run", "voice_worker")
|
||||
n = self.history.purge_traces_older_than(time.time() - TRACE_KEEP_DAYS * 86400)
|
||||
if n:
|
||||
debug_log(f"removed {n} answer traces older than {TRACE_KEEP_DAYS} days", "voice_worker")
|
||||
@@ -609,26 +643,22 @@ class Session:
|
||||
asyncio.get_running_loop().create_task(self._reply(rid, user, text, via, speak, early, channel, notes))
|
||||
|
||||
@staticmethod
|
||||
def _trace_start(history, notes: list | None) -> list:
|
||||
def _records_step(history, notes: list | None) -> dict:
|
||||
"""The first step of an answer's trace: the records and notes it was given."""
|
||||
return [{"kind": "records", "recent": list(history.recent), "matches": list(history.matches),
|
||||
"notes": len(notes or [])}]
|
||||
|
||||
def _trace_end(self, via: str, channel: str | None, user: str, question: str, answer: str,
|
||||
steps: list, began: float) -> None:
|
||||
"""Keep how this answer was made (history.spec.md, "Traces"); never stops the answer."""
|
||||
if self.worker.history is None:
|
||||
return
|
||||
try:
|
||||
self.worker.history.add_trace(via, channel, user, question, answer, steps,
|
||||
ms=round((time.time() - began) * 1000), ts=time.time())
|
||||
except Exception as e: # noqa: BLE001 - a trace is a view, not part of the answer
|
||||
debug_log(f"trace not kept: {type(e).__name__}", "llm")
|
||||
return {"kind": "records", "recent": list(history.recent), "matches": list(history.matches),
|
||||
"notes": len(notes or [])}
|
||||
|
||||
async def _task(self, rid: str, user: str, text: str, notes: list | None = None) -> None:
|
||||
"""A scheduled task (schedule.spec.md, "Tasks"): answered in the chat lane with the read-only
|
||||
tools, its own short-term memory and the person's history scope. It is not a turn of their
|
||||
conversation, so their turn count and delete confirmations stay as they are."""
|
||||
trace = _LiveTrace(self.worker.history, "task", None, user, text)
|
||||
try:
|
||||
await self._task_inner(rid, user, text, notes, trace)
|
||||
finally:
|
||||
trace.finish("") # only when it did not get to its answer
|
||||
|
||||
async def _task_inner(self, rid: str, user: str, text: str, notes: list | None, trace: _LiveTrace) -> None:
|
||||
w = self.worker
|
||||
answer = None
|
||||
async with w.brain_people.setdefault(user, asyncio.Lock()), w.brain_lanes["chat"]:
|
||||
@@ -644,14 +674,14 @@ class Session:
|
||||
from jarvis.memory.history import HistoryContext
|
||||
history = HistoryContext()
|
||||
try:
|
||||
steps = self._trace_start(history, notes)
|
||||
trace.append(self._records_step(history, notes))
|
||||
async with self._llm():
|
||||
answer = await asyncio.to_thread(w.brain.reply, user, text, history, task=True,
|
||||
notes=notes or [], trace=steps)
|
||||
notes=notes or [], trace=trace)
|
||||
except Exception as e: # the brain must never take the session down
|
||||
debug_log(f"brain task {rid} failed: {type(e).__name__}", "llm")
|
||||
answer = (answer or "").strip()
|
||||
self._trace_end("task", None, user, text, answer, steps, now)
|
||||
trace.finish(answer)
|
||||
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})
|
||||
|
||||
def _on_llm(self, msg: dict) -> None:
|
||||
@@ -791,9 +821,11 @@ class Session:
|
||||
|
||||
async def _reply(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool = False,
|
||||
channel: str | None = None, notes: list | None = None) -> None:
|
||||
trace = _LiveTrace(self.worker.history, via, self.voice_channel if via == "voice" else channel, user, text)
|
||||
try:
|
||||
await self._reply_inner(rid, user, text, via, speak, early, channel, notes or [])
|
||||
await self._reply_inner(rid, user, text, via, speak, early, channel, notes or [], trace=trace)
|
||||
finally:
|
||||
trace.finish("") # only when it did not get to its answer
|
||||
self.thinking_replies.discard(rid)
|
||||
self.cancelled_replies.discard(rid)
|
||||
if not self._handed_over.pop(rid, False): # else _delivered counts it
|
||||
@@ -830,7 +862,8 @@ class Session:
|
||||
self._delivered(rid, ok)
|
||||
|
||||
async def _reply_inner(self, rid: str, user: str, text: str, via: str, speak: bool, early: bool,
|
||||
chat_channel: str | None = None, notes: list | None = None) -> None:
|
||||
chat_channel: str | None = None, notes: list | None = None, *,
|
||||
trace: _LiveTrace) -> None:
|
||||
w = self.worker
|
||||
channel = self.voice_channel
|
||||
# Person first, then lane: a reply waiting for its asker's other answer holds no lane.
|
||||
@@ -858,7 +891,7 @@ class Session:
|
||||
schedule = AppBridge(self, asyncio.get_running_loop(), "schedule", *origin)
|
||||
notes_backend = AppBridge(self, asyncio.get_running_loop(), "note", *origin)
|
||||
screen = AppBridge(self, asyncio.get_running_loop(), "screen", *origin)
|
||||
steps = self._trace_start(history, notes)
|
||||
trace.append(self._records_step(history, notes))
|
||||
try:
|
||||
async with self._llm(rid if speak else None):
|
||||
w.answering += 1
|
||||
@@ -866,7 +899,7 @@ class Session:
|
||||
answer = await asyncio.to_thread(w.brain.reply, user, text, history, chat=chat,
|
||||
schedule=schedule, notes=notes or [],
|
||||
notes_backend=notes_backend, screen=screen,
|
||||
trace=steps)
|
||||
trace=trace)
|
||||
finally:
|
||||
w.answering -= 1
|
||||
if not w.answering and w.scheduler:
|
||||
@@ -875,7 +908,7 @@ class Session:
|
||||
debug_log(f"brain reply {rid} failed: {type(e).__name__}", "llm")
|
||||
answer = None
|
||||
answer = (answer or "").strip()
|
||||
self._trace_end(via, channel if via == "voice" else chat_channel, user, text, answer, steps, now)
|
||||
trace.finish(answer)
|
||||
if not answer and rid in self.tts_requests:
|
||||
self._on_tts({"type": "tts", "id": rid, "text": "", "more": False}) # ends the notice's speech
|
||||
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})
|
||||
|
||||
@@ -248,8 +248,11 @@ which carry Discord's own time.
|
||||
still answering means the answer is not spoken: `reply_text` still comes, then `tts_done` with
|
||||
`cancelled: true` and no audio. Every reply, a task's too and one that failed, leaves a trace of
|
||||
how it was made (`history.spec.md`, "Traces"): the history lines and number of notes it was given,
|
||||
then what the engine wrote down; a trace that cannot be stored never stops the answer. Traces older
|
||||
than 30 days are removed when the worker starts. Each user keeps their own short-term dialogue
|
||||
then what the engine wrote down. It is stored as soon as the request arrives (before it waits for
|
||||
the asker's previous answer) and again as each step is added, then ends with the answer, or with
|
||||
none when the reply fails, the session closes or the reply is cancelled; a trace that cannot be
|
||||
stored never stops the answer. At start the worker ends the traces a killed run left unfinished
|
||||
and removes those older than 30 days. Each user keeps their own short-term dialogue
|
||||
memory (tool carry-over) across replies. The brain runs the reply engine with v1's single-user
|
||||
memory off (`legacy_memory=False`: no warm profile, diary or graph), because several people share
|
||||
this assistant and only the asker's scoped history may reach the prompt. It answers in Korean
|
||||
|
||||
@@ -243,10 +243,11 @@ def test_chat_tool_reads_and_searches_one_channels_messages(store):
|
||||
def test_how_an_answer_was_made_is_kept_per_person_and_never_searched(store):
|
||||
steps = [{"kind": "tools", "names": ["getWeather"]},
|
||||
{"kind": "tool", "name": "getWeather", "args": {"location": "서울"}, "ok": True, "result": "맑음"}]
|
||||
store.add_trace("voice", VC, "a", "서울 날씨 어때", "맑습니다", steps, ms=1200, ts=T0)
|
||||
store.add_trace("chat", CHAT, "b", "안녕", "", [], ms=50, ts=T0 + 1)
|
||||
store.finish_trace(store.start_trace("voice", VC, "a", "서울 날씨 어때", ts=T0), "맑습니다", steps, ms=1200)
|
||||
store.finish_trace(store.start_trace("chat", CHAT, "b", "안녕", ts=T0 + 1), "", [], ms=50)
|
||||
[t] = store.traces_of("a")
|
||||
assert (t.via, t.channel_id, t.question, t.answer, t.ms, t.steps) == ("voice", VC, "서울 날씨 어때", "맑습니다", 1200, steps)
|
||||
assert t.ts == T0 # when it was asked, not when the answer was ready
|
||||
# A trace is no record: the brain never reads it back as history.
|
||||
assert store.search("a", "날씨", scope=Scope()) == []
|
||||
assert store.recent("a", T0 + 2, scope=Scope()) == []
|
||||
@@ -255,9 +256,30 @@ def test_how_an_answer_was_made_is_kept_per_person_and_never_searched(store):
|
||||
|
||||
|
||||
def test_traces_have_their_own_retention_and_follow_the_history_retention(store):
|
||||
store.add_trace("voice", VC, "a", "옛 질문", "옛 답", [], ms=1, ts=T0)
|
||||
store.add_trace("voice", VC, "a", "새 질문", "새 답", [], ms=1, ts=T0 + 100)
|
||||
store.finish_trace(store.start_trace("voice", VC, "a", "옛 질문", ts=T0), "옛 답", [], ms=1)
|
||||
store.finish_trace(store.start_trace("voice", VC, "a", "새 질문", ts=T0 + 100), "새 답", [], ms=1)
|
||||
store.purge_traces_older_than(T0 + 50)
|
||||
assert [t.question for t in store.traces_of("a")] == ["새 질문"]
|
||||
store.purge_older_than(T0 + 200)
|
||||
assert store.traces_of("a") == []
|
||||
|
||||
|
||||
def test_a_trace_is_kept_from_the_question_on_and_filled_in_as_the_answer_is_made(store):
|
||||
tid = store.start_trace("voice", VC, "a", "서울 날씨 어때", ts=T0)
|
||||
[t] = store.traces_of("a")
|
||||
assert (t.question, t.answer, t.ms, t.steps) == ("서울 날씨 어때", "", -1, []) # -1: still being made
|
||||
store.trace_steps(tid, [{"kind": "tools", "names": ["getWeather"]}])
|
||||
assert store.traces_of("a")[0].steps == [{"kind": "tools", "names": ["getWeather"]}]
|
||||
assert store.traces_of("a")[0].ms == -1
|
||||
store.finish_trace(tid, "맑습니다", [{"kind": "tools", "names": ["getWeather"]}], ms=900)
|
||||
[t] = store.traces_of("a")
|
||||
assert (t.answer, t.ms, t.ts) == ("맑습니다", 900, T0)
|
||||
|
||||
|
||||
def test_traces_a_killed_run_left_unfinished_are_closed_without_an_answer(store):
|
||||
store.start_trace("voice", VC, "a", "끊긴 질문", ts=T0)
|
||||
store.finish_trace(store.start_trace("voice", VC, "a", "끝난 질문", ts=T0 + 1), "답", [], ms=5)
|
||||
assert store.close_unfinished_traces() == 1
|
||||
cut, done = store.traces_of("a")
|
||||
assert (cut.answer, cut.ms >= 0) == ("", True)
|
||||
assert (done.answer, done.ms) == ("답", 5)
|
||||
|
||||
@@ -244,6 +244,32 @@ def test_each_answer_keeps_how_it_was_made_with_the_records_it_was_given(store):
|
||||
assert (task.via, task.channel_id, task.answer) == ("task", None, "answer for task")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_trace_is_stored_from_the_request_on_and_fills_in_while_the_answer_is_made(store):
|
||||
import time
|
||||
during = []
|
||||
|
||||
def answer(user, text):
|
||||
during.append((store.traces_of(user), time.time())) # the engine has added its steps
|
||||
return "answer"
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
await send(ws, type="voice_join", channel="vc1")
|
||||
await send(ws, type="reply", id="r1", user="100", text="q", via="voice", speak=False)
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "r1")
|
||||
|
||||
asyncio.run(with_worker(body, store=store, brain=FakeBrain(answer)))
|
||||
[(traces, answering_at)] = during
|
||||
[t] = traces
|
||||
assert (t.question, t.answer, t.ms) == ("q", "", -1) # -1: still being made
|
||||
assert [s["kind"] for s in t.steps] == ["records", "tools"]
|
||||
assert t.ts <= answering_at
|
||||
[t] = store.traces_of("100")
|
||||
assert (t.answer, t.ms >= 0, t.ts) == ("answer", True, traces[0].ts)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_without_a_brain_reply_is_an_error():
|
||||
async def body(url):
|
||||
@@ -337,15 +363,16 @@ def test_presence_left_open_by_a_previous_run_is_closed_at_start(store):
|
||||
def test_traces_older_than_thirty_days_are_removed_at_start(store):
|
||||
import time
|
||||
now = time.time()
|
||||
store.add_trace("voice", "vc1", "100", "old", "a", [], ms=1, ts=now - 31 * 86400)
|
||||
store.add_trace("voice", "vc1", "100", "new", "a", [], ms=1, ts=now - 29 * 86400)
|
||||
store.finish_trace(store.start_trace("voice", "vc1", "100", "old", ts=now - 31 * 86400), "a", [], ms=1)
|
||||
store.finish_trace(store.start_trace("voice", "vc1", "100", "new", ts=now - 29 * 86400), "a", [], ms=1)
|
||||
store.start_trace("voice", "vc1", "100", "cut off", ts=now - 60) # a killed run never finished it
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
|
||||
asyncio.run(with_worker(body, store=store))
|
||||
assert [t.question for t in store.traces_of("100")] == ["new"]
|
||||
assert [(t.question, t.ms >= 0) for t in store.traces_of("100")] == [("new", True), ("cut off", True)]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
Reference in New Issue
Block a user