Compare commits
14 Commits
app-v0.1.3
...
app-v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b832c1c3b | ||
|
|
3d8801b691 | ||
|
|
1a12755649 | ||
|
|
fbdf274b9d | ||
|
|
2a6b350079 | ||
|
|
53d522db69 | ||
|
|
6c1bc31236 | ||
|
|
27fcea4e3d | ||
|
|
46f71e7f03 | ||
|
|
a20ebe4eae | ||
|
|
2a140d8490 | ||
|
|
27eb1315b9 | ||
|
|
8a37144cd8 | ||
|
|
dbe5c617bc |
@@ -32,7 +32,7 @@ Any code change must either adhere to our spec files perfectly or you should ask
|
||||
| `src/jarvis/tools/builtin/nutrition/log_meal.spec.md` | logMeal tool: single-property schema for planner fast-path, internal nutrition extraction, untrusted-data fence, follow-ups | Public schema is a single optional `meal` string; nutrition fields are internal; user text is fenced as data |
|
||||
| `src/jarvis/utils/location.spec.md` | GeoIP location detection | Privacy-first; local GeoLite2 DB only |
|
||||
| `src/jarvis/memory/graph.spec.md` | Node graph memory (v2), self-organising tree, UI explorer | Dynamic structure; access-aware; auto-split/merge (future) |
|
||||
| `src/jarvis/memory/history.spec.md` | v2 conversation history store: voice transcripts, answers and registered chat channel messages; per-asker scope (own, chat channels, others only while co-present); language-agnostic prefix search; size-budgeted context for the reply engine | Only what the asker may see; logs carry no record text; whole history searched, little sent |
|
||||
| `src/jarvis/memory/history.spec.md` | v2 conversation history store: voice transcripts, answers and registered chat channel messages; per-asker scope (own, chat channels, others only while co-present); language-agnostic prefix search; size-budgeted context for the reply engine; answer traces (how each answer was made) for the 대화 screen | Only what the asker may see; traces never reach a prompt; logs carry no record text; whole history searched, little sent |
|
||||
| `src/jarvis/memory/summariser.spec.md` | Diary summariser prompt contract, hygiene rules (deflection, attribution, topic separation), post-process scrub, and bulk-sweep clean button | Two-layer defence: prompt + deterministic scrub; corrupted summaries poison every downstream consumer |
|
||||
| `src/jarvis/memory/recall_gate.spec.md` | Deterministic skip-enrichment heuristic when the hot window covers a follow-up | Fail-open; language-agnostic via `\w{3,}` + `re.UNICODE`; planner intent always wins |
|
||||
| `src/voice_worker/voice_worker.spec.md` | v2 voice worker: multi-speaker streaming STT (shared Whisper, batched) and sentence TTS over a local WebSocket | Loopback only with an app token; no transcript text in logs; finals before partials; language-agnostic |
|
||||
|
||||
70
app/Cargo.lock
generated
70
app/Cargo.lock
generated
@@ -744,6 +744,18 @@ version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-streaming-iterator"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
@@ -816,6 +828,12 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.2"
|
||||
@@ -1024,12 +1042,30 @@ version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashmap_derive"
|
||||
version = "0.1.0"
|
||||
@@ -1484,7 +1520,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.3"
|
||||
version = "0.1.11"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -1497,6 +1533,7 @@ dependencies = [
|
||||
"opus2",
|
||||
"rand 0.9.5",
|
||||
"reqwest",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
@@ -1786,6 +1823,17 @@ dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.35.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
@@ -2756,6 +2804,20 @@ dependencies = [
|
||||
"realfft",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.3"
|
||||
@@ -4108,6 +4170,12 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.3"
|
||||
version = "0.1.11"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 Windows app core: Discord voice, voice worker supervisor, chat channels"
|
||||
@@ -35,6 +35,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "std"
|
||||
zip = { version = "9", default-features = false, features = ["deflate"] }
|
||||
unicode-normalization = "0.1"
|
||||
jpeg-encoder = "0.6"
|
||||
rusqlite = { version = "0.37", features = ["bundled"] }
|
||||
|
||||
[dev-dependencies]
|
||||
jpeg-decoder = "0.3"
|
||||
|
||||
531
app/shell/Cargo.lock
generated
531
app/shell/Cargo.lock
generated
@@ -91,6 +91,126 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-broadcast"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
"event-listener-strategy",
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-channel"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2"
|
||||
dependencies = [
|
||||
"concurrent-queue",
|
||||
"event-listener-strategy",
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-executor"
|
||||
version = "1.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37"
|
||||
dependencies = [
|
||||
"async-task",
|
||||
"concurrent-queue",
|
||||
"fastrand",
|
||||
"futures-lite",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-io"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"futures-io",
|
||||
"futures-lite",
|
||||
"parking",
|
||||
"polling",
|
||||
"rustix",
|
||||
"slab",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-lock"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
"event-listener-strategy",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-process"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"async-signal",
|
||||
"async-task",
|
||||
"blocking",
|
||||
"cfg-if",
|
||||
"event-listener",
|
||||
"futures-lite",
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-signal"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485"
|
||||
dependencies = [
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"atomic-waker",
|
||||
"cfg-if",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"rustix",
|
||||
"signal-hook-registry",
|
||||
"slab",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-task"
|
||||
version = "4.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.92"
|
||||
@@ -230,6 +350,19 @@ dependencies = [
|
||||
"objc2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-task",
|
||||
"futures-io",
|
||||
"futures-lite",
|
||||
"piper",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "brotli"
|
||||
version = "9.1.1"
|
||||
@@ -278,6 +411,12 @@ version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder-lite"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.12.1"
|
||||
@@ -481,6 +620,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "concurrent-queue"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-oid"
|
||||
version = "0.9.6"
|
||||
@@ -1059,7 +1207,7 @@ checksum = "fac5fca71e65e94cc718a6e2af65d6e0f9c6027751c2aa562fbb5087fda639bc"
|
||||
dependencies = [
|
||||
"bit-set 0.8.0",
|
||||
"cssparser 0.37.0",
|
||||
"foldhash",
|
||||
"foldhash 0.2.0",
|
||||
"html5ever 0.39.0",
|
||||
"precomputed-hash",
|
||||
"selectors 0.38.0",
|
||||
@@ -1074,7 +1222,7 @@ checksum = "498c698ac51127148a3984450e51fca7f01805a91d7a1f7a24af0a5f761e3385"
|
||||
dependencies = [
|
||||
"bit-set 0.11.1",
|
||||
"cssparser 0.38.0",
|
||||
"foldhash",
|
||||
"foldhash 0.2.0",
|
||||
"html5ever 0.40.1",
|
||||
"precomputed-hash",
|
||||
"selectors 0.41.0",
|
||||
@@ -1217,6 +1365,12 @@ dependencies = [
|
||||
"simdutf8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "endi"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099"
|
||||
|
||||
[[package]]
|
||||
name = "enum-map"
|
||||
version = "2.7.3"
|
||||
@@ -1237,6 +1391,27 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enumflags2"
|
||||
version = "0.7.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef"
|
||||
dependencies = [
|
||||
"enumflags2_derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enumflags2_derive"
|
||||
version = "0.7.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.3"
|
||||
@@ -1264,12 +1439,44 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "5.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2"
|
||||
dependencies = [
|
||||
"parking",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener-strategy"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "extended"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af9673d8203fcb076b19dfd17e38b3d4ae9f44959416ea532ce72415a6020365"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-iterator"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||
|
||||
[[package]]
|
||||
name = "fallible-streaming-iterator"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
@@ -1361,6 +1568,12 @@ version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.2.0"
|
||||
@@ -1470,6 +1683,19 @@ version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed"
|
||||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"parking",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.34"
|
||||
@@ -1855,12 +2081,30 @@ version = "0.14.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash 0.1.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"
|
||||
dependencies = [
|
||||
"hashbrown 0.15.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashmap_derive"
|
||||
version = "0.1.0"
|
||||
@@ -2313,6 +2557,19 @@ dependencies = [
|
||||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.25.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
@@ -2380,7 +2637,7 @@ checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-app"
|
||||
version = "0.1.3"
|
||||
version = "0.1.11"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base64 0.22.1",
|
||||
@@ -2392,6 +2649,7 @@ dependencies = [
|
||||
"opus2",
|
||||
"rand 0.9.5",
|
||||
"reqwest 0.12.28",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
@@ -2408,12 +2666,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.3"
|
||||
version = "0.1.11"
|
||||
dependencies = [
|
||||
"jarvis-app",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-single-instance",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -2886,6 +3145,17 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.35.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
@@ -3027,6 +3297,16 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "moxcms"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"pxfm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "muda"
|
||||
version = "0.20.0"
|
||||
@@ -3542,6 +3822,16 @@ dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-stream"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "p256"
|
||||
version = "0.13.2"
|
||||
@@ -3589,6 +3879,12 @@ dependencies = [
|
||||
"system-deps",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.2"
|
||||
@@ -3815,6 +4111,17 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13bee6c73da26345c729282832b60b0363cf3dd9f4bfd81d8551b7a1c889a113"
|
||||
|
||||
[[package]]
|
||||
name = "piper"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1"
|
||||
dependencies = [
|
||||
"atomic-waker",
|
||||
"fastrand",
|
||||
"futures-io",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkcs8"
|
||||
version = "0.10.2"
|
||||
@@ -3887,6 +4194,20 @@ dependencies = [
|
||||
"miniz_oxide 0.8.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "3.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
"hermit-abi",
|
||||
"pin-project-lite",
|
||||
"rustix",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "poly1305"
|
||||
version = "0.8.0"
|
||||
@@ -3993,6 +4314,15 @@ dependencies = [
|
||||
"toml_edit 0.20.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f"
|
||||
dependencies = [
|
||||
"toml_edit 0.25.19+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
@@ -4048,6 +4378,12 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pxfm"
|
||||
version = "0.1.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f"
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.42.0"
|
||||
@@ -4464,6 +4800,20 @@ dependencies = [
|
||||
"realfft",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rusqlite"
|
||||
version = "0.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"fallible-iterator",
|
||||
"fallible-streaming-iterator",
|
||||
"hashlink",
|
||||
"libsqlite3-sys",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.3"
|
||||
@@ -5657,6 +6007,7 @@ dependencies = [
|
||||
"gtk",
|
||||
"heck 0.5.0",
|
||||
"http",
|
||||
"image",
|
||||
"jni",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -5755,6 +6106,22 @@ dependencies = [
|
||||
"tauri-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-single-instance"
|
||||
version = "2.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "726b6da0dd5bd1344f84f4108a622c07d01923baacb5c803a605189672c5352f"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"windows-sys 0.61.2",
|
||||
"zbus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "2.12.2"
|
||||
@@ -5854,6 +6221,19 @@ dependencies = [
|
||||
"toml 1.2.1+spec-1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tendril"
|
||||
version = "0.5.1"
|
||||
@@ -6189,6 +6569,18 @@ dependencies = [
|
||||
"winnow 0.5.40",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.25.19+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218"
|
||||
dependencies = [
|
||||
"indexmap 2.14.2",
|
||||
"toml_datetime 1.1.3+spec-1.1.0",
|
||||
"toml_parser",
|
||||
"winnow 1.0.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_parser"
|
||||
version = "1.1.5+spec-1.1.0"
|
||||
@@ -6466,6 +6858,17 @@ version = "1.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||
|
||||
[[package]]
|
||||
name = "uds_windows"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
|
||||
dependencies = [
|
||||
"memoffset",
|
||||
"tempfile",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.10.0"
|
||||
@@ -6573,6 +6976,12 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.2.1"
|
||||
@@ -7254,6 +7663,9 @@ name = "winnow"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
@@ -7376,6 +7788,76 @@ dependencies = [
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
version = "5.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-executor",
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"async-process",
|
||||
"async-recursion",
|
||||
"async-task",
|
||||
"async-trait",
|
||||
"blocking",
|
||||
"enumflags2",
|
||||
"event-listener",
|
||||
"futures-core",
|
||||
"futures-lite",
|
||||
"hex",
|
||||
"libc",
|
||||
"ordered-stream",
|
||||
"rustix",
|
||||
"serde",
|
||||
"serde_repr",
|
||||
"tracing",
|
||||
"uds_windows",
|
||||
"uuid",
|
||||
"windows-sys 0.61.2",
|
||||
"winnow 1.0.5",
|
||||
"zbus_macros",
|
||||
"zbus_names",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus_macros"
|
||||
version = "5.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40"
|
||||
dependencies = [
|
||||
"proc-macro-crate 3.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
"zbus_names",
|
||||
"zvariant",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus_names"
|
||||
version = "4.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"winnow 1.0.5",
|
||||
"zvariant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zcheapstr"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "939f186d9ecebe044315a5cb6d6f78568bbc21152adc954d5a0c2f58bdbc9920"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.63"
|
||||
@@ -7513,3 +7995,44 @@ dependencies = [
|
||||
"log",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant"
|
||||
version = "5.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7"
|
||||
dependencies = [
|
||||
"endi",
|
||||
"enumflags2",
|
||||
"serde",
|
||||
"winnow 1.0.5",
|
||||
"zcheapstr",
|
||||
"zvariant_derive",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant_derive"
|
||||
version = "5.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d"
|
||||
dependencies = [
|
||||
"proc-macro-crate 3.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
"zvariant_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zvariant_utils"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"syn 3.0.10",
|
||||
"winnow 1.0.5",
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "jarvis-shell"
|
||||
version = "0.1.3"
|
||||
version = "0.1.11"
|
||||
edition = "2021"
|
||||
rust-version = "1.85"
|
||||
description = "Jarvis v2 management app window (Tauri 2 over the app core's AdminApi)"
|
||||
@@ -16,7 +16,8 @@ tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
jarvis-app = { path = ".." }
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri = { version = "2", features = ["tray-icon", "image-png"] }
|
||||
tauri-plugin-single-instance = "2"
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 55 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 53 KiB |
BIN
app/shell/icons/tray.png
Normal file
BIN
app/shell/icons/tray.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -1,5 +1,5 @@
|
||||
; The Jarvis installer (admin.spec.md, "Installer"). Built on Linux by installer.sh with makensis:
|
||||
; makensis -DVERSION=0.1.0 -DSRC=<Jarvis folder> -DOUT=<setup.exe> -DICON=<icon.ico> -DWEBVIEW2=<bootstrapper>
|
||||
; makensis -DVERSION=0.1.0 -DSRC=<Jarvis folder> -DOUT=<setup.exe> -DICON=<icon.ico> -DICON_FILE=<jarvis-<hash>.ico> -DWEBVIEW2=<bootstrapper>
|
||||
; -DUNINSTALL_LIST=<the Delete/RMDir lines of the installed files> installer.nsi
|
||||
; Program Files, one administrator prompt; the data folder is chosen by the app's first-run wizard
|
||||
; and never touched here. /S installs silently (the app's updates: /S /RUN starts the app afterwards).
|
||||
@@ -220,6 +220,10 @@ Section "Jarvis (필수)" SecMain
|
||||
SetOutPath "$INSTDIR"
|
||||
File "${SRC}/jarvis.exe"
|
||||
File "${SRC}/WebView2Loader.dll"
|
||||
; The shortcuts' icon, named by its content: Windows keeps an icon it has shown by the file's path,
|
||||
; so a changed icon under the old path would stay the old one on the desktop and in search.
|
||||
Delete "$INSTDIR\jarvis-*.ico"
|
||||
File "/oname=${ICON_FILE}" "${ICON}"
|
||||
File /r "${SRC}/python-src"
|
||||
File /r "${SRC}/display-driver"
|
||||
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||
@@ -233,16 +237,25 @@ Section "Jarvis (필수)" SecMain
|
||||
WriteRegStr HKLM "${UNINST_KEY}" "QuietUninstallString" '"$INSTDIR\uninstall.exe" /S'
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "NoModify" 1
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "NoRepair" 1
|
||||
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" $0
|
||||
WriteRegDWORD HKLM "${UNINST_KEY}" "EstimatedSize" ${SIZE_KB}
|
||||
SectionEnd
|
||||
|
||||
Section "시작 메뉴 바로 가기" SecStart
|
||||
CreateShortCut "$SMPROGRAMS\Jarvis.lnk" "$INSTDIR\jarvis.exe"
|
||||
CreateShortCut "$SMPROGRAMS\Jarvis.lnk" "$INSTDIR\jarvis.exe" "" "$INSTDIR\${ICON_FILE}" 0
|
||||
SectionEnd
|
||||
|
||||
Section /o "바탕 화면 바로 가기" SecDesktop
|
||||
CreateShortCut "$DESKTOP\Jarvis.lnk" "$INSTDIR\jarvis.exe"
|
||||
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).
|
||||
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() } } }"`
|
||||
Pop $0
|
||||
System::Call 'shell32::SHChangeNotify(i 0x08000000, i 0, p 0, p 0)' ; SHCNE_ASSOCCHANGED
|
||||
SectionEnd
|
||||
|
||||
Section "가상 모니터 드라이버" SecDriver
|
||||
@@ -304,6 +317,7 @@ Section "Uninstall"
|
||||
; folder the person chose may hold other things; folders go only when empty.
|
||||
Delete "$INSTDIR\jarvis.exe"
|
||||
Delete "$INSTDIR\WebView2Loader.dll"
|
||||
Delete "$INSTDIR\jarvis-*.ico"
|
||||
!include "${UNINSTALL_LIST}"
|
||||
Delete "$INSTDIR\uninstall.exe"
|
||||
RMDir "$INSTDIR"
|
||||
|
||||
@@ -17,7 +17,12 @@ list="$target/uninstall-list.nsh"
|
||||
(cd "$out/Jarvis" && find python-src display-driver -type f | sort | sed 's|/|\\|g; s|^| Delete "$INSTDIR\\|; s|$|"|'
|
||||
cd "$out/Jarvis" && find python-src display-driver -type d | sort -r | sed 's|/|\\|g; s|^| RMDir "$INSTDIR\\|; s|$|"|') > "$list"
|
||||
setup="$out/Jarvis-Setup-$version.exe"
|
||||
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" \
|
||||
-DWEBVIEW2="$wv2" -DUNINSTALL_LIST="$list" ${NSIS_EXTRA:-} "$here/installer.nsi"
|
||||
# The uninstall entry's size: what this setup installs, counted here. Counting the install folder on
|
||||
# the user's PC would also walk a data folder kept inside it (models, runtime: many thousand files).
|
||||
size_kb=$(cd "$out/Jarvis" && du -sk --apparent-size -c jarvis.exe WebView2Loader.dll python-src display-driver | tail -1 | cut -f1)
|
||||
# The shortcuts' icon file is named by its content, so a new icon gets a path Windows has not seen.
|
||||
icon_file="jarvis-$(sha256sum "$here/icons/icon.ico" | cut -c1-12).ico"
|
||||
makensis -V2 -DVERSION="$version" -DSRC="$out/Jarvis" -DOUT="$setup" -DICON="$here/icons/icon.ico" -DICON_FILE="$icon_file" \
|
||||
-DWEBVIEW2="$wv2" -DUNINSTALL_LIST="$list" -DSIZE_KB="$size_kb" ${NSIS_EXTRA:-} "$here/installer.nsi"
|
||||
(cd "$out" && sha256sum "Jarvis-Setup-$version.exe" > "Jarvis-Setup-$version.exe.sha256")
|
||||
echo "$setup"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! Jarvis management app: one Tauri 2 window over the app core (`app/src/admin.spec.md`, "Window
|
||||
//! and Windows build"). The screens (`app/ui`) call `invoke("admin", {command, args})`, passed to the
|
||||
//! same `AdminApi` the development server uses. Closing the window first stops what the app started;
|
||||
//! if that cannot be confirmed the window stays open and says so, and closing it again quits.
|
||||
//! same `AdminApi` the development server uses. Quitting first stops what the app started; if that
|
||||
//! cannot be confirmed the window stays open and says so, and quitting again quits. The close button
|
||||
//! quits, or hides the window to the tray when `app.closeButton` is "tray"; the tray icon opens it
|
||||
//! again or quits. Starting Jarvis again while it runs shows the running one's window.
|
||||
//!
|
||||
//! jarvis [--location FILE]
|
||||
//! jarvis --display-driver install|uninstall --result FILE (elevated, started by the app)
|
||||
@@ -14,7 +16,9 @@ use std::sync::Arc;
|
||||
|
||||
use jarvis_app::admin_api::AdminApi;
|
||||
use serde_json::Value;
|
||||
use tauri::{Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
|
||||
use tauri::menu::{Menu, MenuItem};
|
||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||
use tauri::{AppHandle, Emitter, Manager, RunEvent, WebviewUrl, WebviewWindowBuilder, WindowEvent};
|
||||
|
||||
/// Where closing stands: open, closing (stopping what runs), or the stop could not be confirmed.
|
||||
const OPEN: u8 = 0;
|
||||
@@ -37,6 +41,45 @@ async fn admin(app: tauri::AppHandle, state: tauri::State<'_, Api>, command: Str
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Bring the window back: from the tray, or when Jarvis is started again.
|
||||
fn show_window(app: &AppHandle) {
|
||||
if let Some(w) = app.get_webview_window("main") {
|
||||
let _ = w.unminimize();
|
||||
let _ = w.show();
|
||||
let _ = w.set_focus();
|
||||
}
|
||||
}
|
||||
|
||||
/// Quit (the close button set to quit, or the tray's "완전 종료"): stop what the app started, then
|
||||
/// exit; the window shows while that runs. If the stop fails the window stays with the reason, and
|
||||
/// quitting again exits anyway.
|
||||
fn quit(app: &AppHandle) {
|
||||
let state = app.state::<Api>();
|
||||
match state.phase.load(Ordering::SeqCst) {
|
||||
CLOSE_FAILED => {
|
||||
jarvis_app::warn_log!("app", "quitting again: quitting although the stop was not confirmed");
|
||||
app.exit(0);
|
||||
}
|
||||
CLOSING => {}
|
||||
_ => {
|
||||
state.phase.store(CLOSING, Ordering::SeqCst);
|
||||
show_window(app);
|
||||
let _ = app.emit("closing", ());
|
||||
let (handle, api) = (app.clone(), state.api.clone());
|
||||
tauri::async_runtime::spawn(async move {
|
||||
jarvis_app::info_log!("app", "quitting: stopping what the app started");
|
||||
match api.shutdown().await {
|
||||
Ok(()) => handle.exit(0),
|
||||
Err(e) => {
|
||||
handle.state::<Api>().phase.store(CLOSE_FAILED, Ordering::SeqCst);
|
||||
let _ = handle.emit("close-failed", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn arg(name: &str) -> Option<String> {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
args.iter().position(|a| a == name).and_then(|i| args.get(i + 1).cloned())
|
||||
@@ -66,6 +109,8 @@ fn main() {
|
||||
let (webview_data, _) = jarvis_app::datadir::webview_data_dir(&location);
|
||||
|
||||
let app = tauri::Builder::default()
|
||||
// First, so a second start only shows this one's window and exits.
|
||||
.plugin(tauri_plugin_single_instance::init(|app, _, _| show_window(app)))
|
||||
.manage(Api { api, phase: AtomicU8::new(OPEN) })
|
||||
.invoke_handler(tauri::generate_handler![admin])
|
||||
.setup({
|
||||
@@ -76,6 +121,24 @@ fn main() {
|
||||
.min_inner_size(900.0, 600.0)
|
||||
.data_directory(webview_data)
|
||||
.build()?;
|
||||
let open = MenuItem::with_id(app, "open", "열기", true, None::<&str>)?;
|
||||
let quit_item = MenuItem::with_id(app, "quit", "완전 종료", true, None::<&str>)?;
|
||||
TrayIconBuilder::with_id("main")
|
||||
.tooltip("Jarvis")
|
||||
.menu(&Menu::with_items(app, &[&open, &quit_item])?)
|
||||
.show_menu_on_left_click(false)
|
||||
.on_menu_event(|app, e| match e.id.as_ref() {
|
||||
"open" => show_window(app),
|
||||
"quit" => quit(app),
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, e| {
|
||||
if let TrayIconEvent::Click { button: MouseButton::Left, button_state: MouseButtonState::Up, .. } = e {
|
||||
show_window(tray.app_handle());
|
||||
}
|
||||
})
|
||||
.icon(tauri::image::Image::from_bytes(include_bytes!("../icons/tray.png"))?)
|
||||
.build(app)?;
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
@@ -83,25 +146,17 @@ fn main() {
|
||||
let WindowEvent::CloseRequested { api: close, .. } = event else { return };
|
||||
let state = window.state::<Api>();
|
||||
match state.phase.load(Ordering::SeqCst) {
|
||||
CLOSE_FAILED => {
|
||||
jarvis_app::warn_log!("app", "window closed again: quitting although the stop was not confirmed");
|
||||
}
|
||||
// After a failed stop the window closes, and with it the app.
|
||||
CLOSE_FAILED => jarvis_app::warn_log!("app", "window closed again: quitting although the stop was not confirmed"),
|
||||
CLOSING => close.prevent_close(),
|
||||
_ if state.api.close_to_tray() => {
|
||||
close.prevent_close();
|
||||
let _ = window.hide();
|
||||
jarvis_app::info_log!("app", "window hidden to the tray");
|
||||
}
|
||||
_ => {
|
||||
close.prevent_close();
|
||||
state.phase.store(CLOSING, Ordering::SeqCst);
|
||||
let _ = window.emit("closing", ());
|
||||
let (handle, api) = (window.app_handle().clone(), state.api.clone());
|
||||
tauri::async_runtime::spawn(async move {
|
||||
jarvis_app::info_log!("app", "window closing: stopping what the app started");
|
||||
match api.shutdown().await {
|
||||
Ok(()) => handle.exit(0),
|
||||
Err(e) => {
|
||||
handle.state::<Api>().phase.store(CLOSE_FAILED, Ordering::SeqCst);
|
||||
let _ = handle.emit("close-failed", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
quit(window.app_handle());
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@ that is not absolute, or is a file, is refused with a message.
|
||||
`config/settings.json` keeps the format of `discord_core.spec.md` and `conversation.spec.md`.
|
||||
|
||||
- `fields()` describes every key the screens edit: its dotted path (`call.mode`), screen
|
||||
(`bot`, `channels`, `chat`, `memory`, `model`, `features`, `collect`), kind (bool, integer with a range, number with a
|
||||
(`bot`, `channels`, `chat`, `memory`, `model`, `features`, `collect`, `schedule`, `pcControl`, `game`, `app`), kind (bool, integer with a range, number with a
|
||||
range, text, text list, choice with its values, Discord ID, Discord ID list, ID to number map,
|
||||
chat channel list, MCP server list, collection target list, free object), its default and a Korean label. The screens are built from this
|
||||
list, so a key is added in one place.
|
||||
@@ -221,6 +221,31 @@ editable on the 사람별 지침 screen.
|
||||
- `notes_list` (everyone's, by person, IDs as strings), `note_update` `{id, text}` and `note_delete`
|
||||
`{id}` serve the screen. Logs carry note ids only, never their text.
|
||||
|
||||
## Conversations (`app/src/history_view.rs`)
|
||||
|
||||
What people said, what Jarvis answered and how it made each answer, for the 대화 screen. Read
|
||||
only, from the worker's history store `memory/history.sqlite` (`src/jarvis/memory/history.spec.md`,
|
||||
records and "Traces"), so it works while the services are stopped. Nothing it reads goes to a log.
|
||||
|
||||
- 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
|
||||
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
|
||||
three kinds (each on unless false), where (`voice`, `chat`, `task`; a task has traces only), a
|
||||
person (their records, answers to them and traces of their questions), a channel, text the record
|
||||
or the trace's question, answer or steps contains (records folded like the store: NFKC, lower
|
||||
case), Unix seconds from (inclusive) and to (exclusive), `session` (only items from when the
|
||||
latest service start of this app run began; none before the first start), the cursors `before` (only items older
|
||||
than it) and `from` (it and newer), each an item's `{at, key}`, and `limit` (1-2000, default 200).
|
||||
Items are ordered by time, then records before traces, then id, so paging by cursor never skips or
|
||||
repeats an item, even at equal times. Answers
|
||||
`{items, more, people, channels}`: the newest `limit` items in time order, whether older ones
|
||||
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`.
|
||||
|
||||
## Activity (`app/src/activity.rs`)
|
||||
|
||||
`docs/v2/proactive.md` (제안 5). What Jarvis did outside its answers, for the 한 일 screen: each chat
|
||||
@@ -660,10 +685,11 @@ back as Korean messages for the screen. The Tauri shell passes the screens' `inv
|
||||
| `token_check` `{token}` | the bot's tag and IDs, whether the Message Content intent is on, the invite link (REST only, nothing stored) |
|
||||
| `token_save` `{token}` / `token_status` | store it (masked from then on in logs) / `set` and the masked form, never the token |
|
||||
| `discord_guilds` / `discord_channels` `{guildId}` | the bot's servers / a server's voice and text channels, for the pickers |
|
||||
| `settings_fields` / `settings_view` / `settings_apply` `{changes}` | the settings editor above; `restartNeeded` when the services run; `sync` with the chat channels sent to Discord (below) |
|
||||
| `settings_fields` / `settings_view` / `settings_apply` `{changes}` | the settings editor above; `restartNeeded` when the services run and something other than `voice.tts.speed` changed (the speed reaches the running worker at once, `discord_core.spec.md`); `sync` with the chat channels sent to Discord (below) |
|
||||
| `service_start` / `service_stop` / `service_restart` / `dashboard` | the controller and its snapshot; start and restart run in the background, stop also cancels a start |
|
||||
| `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") |
|
||||
| `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) |
|
||||
@@ -682,6 +708,7 @@ 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.
|
||||
|
||||
- **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
|
||||
@@ -694,7 +721,7 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
|
||||
Strata's last line, and stop in the header; the header with start, restart and stop is rebuilt
|
||||
only when the state changes, so a click is never lost to the refresh. Every screen change starts
|
||||
a new generation: an answer that arrives after the user moved to another screen is dropped.
|
||||
- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, PC 제어, 게임 모드): built from `settings_fields`; only
|
||||
- **Settings screens** (봇, 채널·호출, 채팅 채널, 대화 기억, 모델, 기능, 백그라운드 수집, 예약, PC 제어, 게임 모드, 앱): built from `settings_fields`; only
|
||||
changed fields are sent; the server and voice channel are pickers (choosing another server clears
|
||||
the voice channel and lists only that server's channels); the chat channels are a table
|
||||
with their switches; the bot screen also changes the token; the 기능 screen has the feature
|
||||
@@ -706,8 +733,30 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
|
||||
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).
|
||||
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.
|
||||
- **사람별 지침**: 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
|
||||
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
|
||||
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
|
||||
where it was unless it was at the end. When more new items arrive than the window holds, the
|
||||
shown items it no longer reaches join the pages kept as loaded, so nothing on screen disappears.
|
||||
"이전 기록 더 보기" adds the 200 items before the oldest loaded (`before`), one request at a time
|
||||
(the button is off meanwhile, and an item already loaded is never added again), with no end to
|
||||
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 "설치하고
|
||||
@@ -760,6 +809,16 @@ both to a release with that tag. The repository's other releases (v1's `v1.x`) a
|
||||
left is cleared (`Controller::shutdown`: the LLM's server stopped and confirmed gone). While that
|
||||
runs the window says so; if it fails the window stays open with the reason, and closing it again
|
||||
quits anyway. Quitting another way (the system shutting down) runs the same shutdown.
|
||||
- The close button (X) quits as above, or, when `app.closeButton` is `"tray"` (`"quit"` by default,
|
||||
read each time it is pressed; no data folder or settings that do not parse: quit), only hides the
|
||||
window: the bot and services keep running. A tray icon (`icons/tray.png`, tooltip "Jarvis") is
|
||||
always there: a left click shows the window again, its menu has 열기 and 완전 종료 (the quit
|
||||
above, with the window shown while it runs).
|
||||
- One Jarvis at a time (`tauri-plugin-single-instance`): starting it again while it runs shows the
|
||||
running one's window (hidden or minimised) and the new start exits.
|
||||
- The icon (`icons/icon.ico` for the program file, window, taskbar and installer, 16-256 px;
|
||||
`icons/icon.png` 512 px): voice bars in a ring on the accent colour's gradient; at 32 px and below
|
||||
only three thicker bars, so it stays readable in the taskbar and tray.
|
||||
- `app/shell/package.sh <folder>` builds it on Linux (`x86_64-pc-windows-gnu`, mingw-w64) and lays
|
||||
out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll`, `python-src/` (the `voice_worker` and
|
||||
`jarvis` packages, no caches or specs) and `display-driver/` (the virtual monitor's driver). The worker's sources are `python-src` next to the
|
||||
@@ -784,7 +843,12 @@ come with the first-run wizard into the data folder, which the installer never t
|
||||
installed later from the features screen, with the reason the app wrote (UTF-8), and the app is
|
||||
installed all the same; never in a
|
||||
silent install, so an update neither asks nor brings back a driver the person removed).
|
||||
Shortcuts are for every user of the PC.
|
||||
Shortcuts are for every user of the PC. Their icon is a file next to `jarvis.exe` named by its
|
||||
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`).
|
||||
- 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
|
||||
|
||||
@@ -157,6 +157,14 @@ impl AdminApi {
|
||||
Ok(c.get_or_insert_with(|| Controller::new(ServicesHost::new(dir.path().to_path_buf()))).clone())
|
||||
}
|
||||
|
||||
/// Whether the window's close button hides it to the tray (`app.closeButton`) rather than
|
||||
/// quitting. Without a data folder or with settings that do not parse, closing quits.
|
||||
pub fn close_to_tray(&self) -> bool {
|
||||
self.dir.lock().unwrap().as_ref()
|
||||
.and_then(|d| crate::settings::load_settings(&d.settings_file()).ok())
|
||||
.is_some_and(|s| s.close_to_tray)
|
||||
}
|
||||
|
||||
/// The app is closing: cancel an install in progress and wait for it (its commands and their
|
||||
/// children end), stop the services (a start in progress is cancelled and waited for) and clear
|
||||
/// what a failed run may have left (the LLM's server). An error means something may still run;
|
||||
@@ -311,7 +319,16 @@ impl AdminApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(json!({"saved": changes.len(), "restartNeeded": self.controller()?.state() == crate::control::State::Running,
|
||||
// The speech speed reaches the running services at once; everything else waits for
|
||||
// a restart.
|
||||
if changes.contains_key("voice.tts.speed") {
|
||||
let speed = crate::settings::load_settings(&file).map_err(|e| e.0)?.voice.tts_speed;
|
||||
self.controller()?.set_tts_speed(speed);
|
||||
}
|
||||
// The close button's choice is read when it is pressed.
|
||||
let restart = changes.keys().any(|k| k != "voice.tts.speed" && k != "app.closeButton");
|
||||
Ok(json!({"saved": changes.len(),
|
||||
"restartNeeded": restart && self.controller()?.state() == crate::control::State::Running,
|
||||
"sync": sync}))
|
||||
}
|
||||
"mcp_env_status" => {
|
||||
@@ -388,6 +405,39 @@ impl AdminApi {
|
||||
crate::info_log!("admin", "note {id} deleted");
|
||||
Ok(json!({"deleted": id.to_string()}))
|
||||
}
|
||||
// The 대화 screen (admin.spec.md, "Conversations"): records and answer traces.
|
||||
"history_query" => {
|
||||
let dir = self.dir()?;
|
||||
let text = |k: &str| args.get(k).and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty()).map(String::from);
|
||||
let flag = |k: &str| args.get(k).and_then(Value::as_bool).unwrap_or(true);
|
||||
// The current session: from when the latest start began (none yet: nothing to show).
|
||||
let session = self.controller.lock().unwrap().as_ref().and_then(|c| c.session_start());
|
||||
let only_session = args.get("session").and_then(Value::as_bool).unwrap_or(false);
|
||||
let mut since = args.get("since").and_then(Value::as_f64);
|
||||
if only_session {
|
||||
since = Some(since.unwrap_or(f64::MIN).max(session.unwrap_or(f64::INFINITY)));
|
||||
}
|
||||
let q = crate::history_view::Query {
|
||||
said: flag("said"), answered: flag("answered"), thought: flag("thought"),
|
||||
via: text("via"), person: text("person"), channel: text("channel"), find: text("find"),
|
||||
since, until: args.get("until").and_then(Value::as_f64),
|
||||
before: args.get("before").and_then(crate::history_view::Cursor::of),
|
||||
from: args.get("from").and_then(crate::history_view::Cursor::of),
|
||||
limit: args.get("limit").and_then(Value::as_u64).map_or(crate::history_view::DEFAULT_LIMIT, |n| n as usize),
|
||||
};
|
||||
let bot = self.secrets()?.get(DISCORD_TOKEN).ok().flatten().and_then(|t| crate::history_view::bot_id_of_token(&t));
|
||||
let path = dir.path().join("memory").join("history.sqlite");
|
||||
let mut v = tokio::task::spawn_blocking(move || crate::history_view::query(&path, bot.as_deref(), &q))
|
||||
.await.map_err(|e| e.to_string())??;
|
||||
// Chat channels by the names given them in the settings.
|
||||
let named = crate::settings::load_settings(&dir.settings_file()).map(|s| s.chat_channels).unwrap_or_default();
|
||||
for ch in v["channels"].as_array_mut().into_iter().flatten() {
|
||||
let name = named.iter().find(|c| Some(c.id.to_string().as_str()) == ch["id"].as_str()).map(|c| c.name.clone());
|
||||
ch["name"] = json!(name.unwrap_or_default());
|
||||
}
|
||||
v["session"] = json!(session);
|
||||
Ok(v)
|
||||
}
|
||||
"activity_list" => {
|
||||
let limit = args.get("limit").and_then(Value::as_u64).unwrap_or(200).clamp(1, 1000) as usize;
|
||||
Ok(json!({"items": crate::activity::Activity::new(self.dir()?.path()).recent(limit)}))
|
||||
@@ -517,6 +567,20 @@ mod tests {
|
||||
assert!(a.call("nope", json!({})).await.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_close_button_follows_the_saved_choice() {
|
||||
let (a, base) = api("api-close");
|
||||
assert!(!a.close_to_tray(), "no data folder yet: closing quits");
|
||||
let data = base.join("d");
|
||||
a.call("folder_choose", json!({"path": data.to_string_lossy()})).await.unwrap();
|
||||
assert!(!a.close_to_tray());
|
||||
a.call("settings_apply", json!({"changes": {"app.closeButton": "tray"}})).await.unwrap();
|
||||
assert!(a.close_to_tray());
|
||||
// A settings file that does not parse never leaves the window unable to close.
|
||||
std::fs::write(data.join("config").join("settings.json"), "{").unwrap();
|
||||
assert!(!a.close_to_tray());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_notes_screen_lists_edits_and_deletes_anyones_notes() {
|
||||
let (a, base) = api("api-notes");
|
||||
@@ -533,6 +597,51 @@ mod tests {
|
||||
assert!(store.all().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_conversation_screen_reads_records_and_traces_with_channel_names() {
|
||||
let (a, base) = api("api-history");
|
||||
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);
|
||||
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();
|
||||
c.execute_batch("INSERT INTO history(ts, kind, channel_id, author_id, author_name, text, norm)
|
||||
VALUES (1, 'chat', '123456789012345678', '1', 'Alice', '안녕', '안녕');
|
||||
INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps)
|
||||
VALUES (2, 'chat', '123456789012345678', '1', '안녕', '반가워요', 5, '[]');").unwrap();
|
||||
a.call("settings_apply", json!({"changes": {"chatChannels": [{"id": "123456789012345678", "name": "잡담"}]}})).await.unwrap();
|
||||
let v = a.call("history_query", json!({"thought": false})).await.unwrap();
|
||||
assert_eq!(v["items"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(v["items"][0]["who"]["name"], "Alice");
|
||||
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");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_current_session_shows_only_what_came_since_the_latest_start() {
|
||||
let (a, base) = api("api-history-session");
|
||||
let data = base.join("d");
|
||||
a.call("folder_choose", json!({"path": data.to_string_lossy()})).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();
|
||||
let rec = |ts: f64, text: &str| c.execute("INSERT INTO history(ts, kind, channel_id, author_id, author_name, text, norm) \
|
||||
VALUES (?, 'voice', 'vc', '1', 'Alice', ?, ?)", rusqlite::params![ts, text, text]).unwrap();
|
||||
rec(1.0, "지난번 말");
|
||||
let texts = |v: &Value| v["items"].as_array().unwrap().iter().map(|i| i["text"].as_str().unwrap().to_string()).collect::<Vec<_>>();
|
||||
// Not started yet in this app run: no session, so nothing in it.
|
||||
let v = a.call("history_query", json!({"session": true})).await.unwrap();
|
||||
assert_eq!((texts(&v), v["session"].clone()), (Vec::<String>::new(), Value::Null));
|
||||
a.call("service_start", json!({})).await.unwrap();
|
||||
let started = a.call("history_query", json!({})).await.unwrap()["session"].as_f64().unwrap();
|
||||
rec(started + 1.0, "이번 말");
|
||||
assert_eq!(texts(&a.call("history_query", json!({"session": true})).await.unwrap()), ["이번 말"]);
|
||||
assert_eq!(texts(&a.call("history_query", json!({})).await.unwrap()), ["지난번 말", "이번 말"]);
|
||||
a.shutdown().await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_activity_screen_reads_the_newest_entries() {
|
||||
let (a, base) = api("api-activity");
|
||||
|
||||
@@ -30,6 +30,8 @@ pub trait Running: Send + Sync + 'static {
|
||||
async fn stop(&self) -> Result<(), String>;
|
||||
/// Worker, voice channel members and missed requests, for the snapshot.
|
||||
fn status(&self, now: Instant) -> Value;
|
||||
/// Speak at this speed (`voice.tts.speed`) from the next sentence on.
|
||||
fn set_tts_speed(&self, _speed: f64) {}
|
||||
}
|
||||
|
||||
/// What starts the services (the real ones, or a fake in tests).
|
||||
@@ -64,6 +66,11 @@ struct Inner {
|
||||
feeder: Option<tokio::task::JoinHandle<()>>,
|
||||
/// Stop was asked for while starting.
|
||||
stop_asked: bool,
|
||||
/// The latest speech speed saved (equal to the settings file's): a start may have read the
|
||||
/// settings before it was saved, so the services get it again once they run.
|
||||
tts_speed: Option<f64>,
|
||||
/// When the latest start began (Unix seconds): the 대화 screen's current session.
|
||||
session: Option<f64>,
|
||||
}
|
||||
|
||||
pub struct Controller {
|
||||
@@ -75,13 +82,18 @@ pub struct Controller {
|
||||
impl Controller {
|
||||
pub fn new(host: impl Host) -> Arc<Self> {
|
||||
Arc::new(Self { host: Box::new(host), inner: Mutex::new(Inner { state: State::Stopped, error: None, running: None,
|
||||
dashboard: Arc::default(), feeder: None, stop_asked: false }), usage: tokio::sync::Mutex::new(None) })
|
||||
dashboard: Arc::default(), feeder: None, stop_asked: false, tts_speed: None, session: None }), usage: tokio::sync::Mutex::new(None) })
|
||||
}
|
||||
|
||||
pub fn state(&self) -> State {
|
||||
self.inner.lock().unwrap().state
|
||||
}
|
||||
|
||||
/// When the latest start began (Unix seconds), none before the first start of this app run.
|
||||
pub fn session_start(&self) -> Option<f64> {
|
||||
self.inner.lock().unwrap().session
|
||||
}
|
||||
|
||||
/// Start from stopped or failed; a failed start leaves nothing running.
|
||||
pub async fn start(&self) -> Result<(), String> {
|
||||
self.begin_start()?;
|
||||
@@ -107,6 +119,7 @@ impl Controller {
|
||||
i.state = State::Starting;
|
||||
i.error = None;
|
||||
i.stop_asked = false;
|
||||
i.session = Some(chrono::Utc::now().timestamp_millis() as f64 / 1000.0);
|
||||
self.host.prepare_start();
|
||||
Ok(())
|
||||
}
|
||||
@@ -131,6 +144,9 @@ impl Controller {
|
||||
d2.lock().unwrap().on_event(&ev, Instant::now());
|
||||
}
|
||||
});
|
||||
if let Some(speed) = i.tts_speed {
|
||||
running.set_tts_speed(speed);
|
||||
}
|
||||
i.state = State::Running;
|
||||
i.running = Some(running);
|
||||
i.dashboard = dash;
|
||||
@@ -167,6 +183,17 @@ impl Controller {
|
||||
Err("cancelled".into())
|
||||
}
|
||||
|
||||
/// Give the running services a new speech speed. False when nothing runs yet; a start in
|
||||
/// progress passes it on once the services run.
|
||||
pub fn set_tts_speed(&self, speed: f64) -> bool {
|
||||
let running = {
|
||||
let mut i = self.inner.lock().unwrap();
|
||||
i.tts_speed = Some(speed);
|
||||
i.running.clone()
|
||||
};
|
||||
running.map(|r| r.set_tts_speed(speed)).is_some()
|
||||
}
|
||||
|
||||
/// Stop from running, or cancel a start; what was said is forgotten.
|
||||
pub async fn stop(&self) -> Result<(), String> {
|
||||
let running = {
|
||||
@@ -367,6 +394,10 @@ impl Running for crate::services::Services {
|
||||
"performance": self.llm.stage_view(),
|
||||
})
|
||||
}
|
||||
|
||||
fn set_tts_speed(&self, speed: f64) {
|
||||
self.worker.set_tts_speed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -381,6 +412,7 @@ mod tests {
|
||||
stop_fails: std::sync::atomic::AtomicBool,
|
||||
cleanups: AtomicU32,
|
||||
cleanup_fails: std::sync::atomic::AtomicBool,
|
||||
speeds: Mutex<Vec<f64>>,
|
||||
}
|
||||
|
||||
struct FakeRunning(Arc<Counts>);
|
||||
@@ -393,6 +425,9 @@ mod tests {
|
||||
fn status(&self, _: Instant) -> Value {
|
||||
json!({"worker": {"connected": true}, "voiceMembers": [{"id": "11", "name": "민수"}], "missed": []})
|
||||
}
|
||||
fn set_tts_speed(&self, speed: f64) {
|
||||
self.0.speeds.lock().unwrap().push(speed);
|
||||
}
|
||||
}
|
||||
|
||||
struct FakeHost {
|
||||
@@ -471,6 +506,31 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_new_speech_speed_reaches_the_running_services_without_a_restart() {
|
||||
let counts = Arc::new(Counts::default());
|
||||
let c = Controller::new(FakeHost { counts: counts.clone(), fail_first: AtomicU32::new(0), events: Mutex::new(None) });
|
||||
assert!(!c.set_tts_speed(1.7), "nothing runs: the next start reads the settings");
|
||||
c.start().await.unwrap();
|
||||
assert!(c.set_tts_speed(1.8));
|
||||
assert_eq!(counts.speeds.lock().unwrap().last(), Some(&1.8), "the latest speed is the one they use");
|
||||
assert_eq!(counts.starts.load(Ordering::SeqCst), 1, "no restart");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_speech_speed_saved_while_starting_reaches_the_services_once_they_run() {
|
||||
// The start read the settings before the save, so the new speed must follow it.
|
||||
let counts = Arc::new(Counts::default());
|
||||
let c = Controller::new(FakeHost { counts: counts.clone(), fail_first: AtomicU32::new(0), events: Mutex::new(None) });
|
||||
c.start_in_background().unwrap();
|
||||
assert_eq!(c.state(), State::Starting);
|
||||
assert!(!c.set_tts_speed(1.9), "not running yet");
|
||||
tokio::time::timeout(Duration::from_secs(2), async {
|
||||
while c.state() != State::Running { tokio::time::sleep(Duration::from_millis(5)).await; }
|
||||
}).await.unwrap();
|
||||
assert_eq!(*counts.speeds.lock().unwrap(), [1.9]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_stop_while_starting_cancels_the_start_or_stops_what_came_up() {
|
||||
for honours_cancel in [true, false] {
|
||||
|
||||
@@ -70,7 +70,7 @@ strings (numbers would lose precision).
|
||||
| `voice.wakeWords` | `["자비스"]` | Sent to the worker as STT `hotwords`, and the voice wake words of call detection. |
|
||||
| `voice.stt` | `{}` | Other worker STT settings (`partials`, `end_silence_ms`, `final_beam`, `language`, ...); the worker validates them. |
|
||||
| `chatChannels` | `[]` | `{id, name, description, read (true), send (true), edit (true), react (true), delete (false), pin (false), answer ("wakeWord"), syncDiscord (true)}` per channel; `answer` is in `conversation.spec.md`, `syncDiscord` (the channel's Discord name and topic follow `name` and `description`) in `admin.spec.md`. |
|
||||
| `voice.tts.speed` | `1.5` | How fast the voice speaks (MeloTTS `speed`, 0.5-2.0), passed to the worker as `--melo-speed` when it speaks (`--melo-python`) and its arguments set no speed. MeloTTS's Korean model has one voice, so there is no voice choice. |
|
||||
| `voice.tts.speed` | `1.5` | How fast the voice speaks, 0.5-2.0 (1.0 is MeloTTS's natural pace; MeloTTS speaks up to 1.25 itself and above that the worker stretches the speech and keeps its pitch, `voice_worker.spec.md`, "TTS"). Passed to the worker as `--melo-speed` when it speaks (`--melo-python`) and its arguments set no speed. A change saved while the services run goes to the worker at once (`tts_speed`) and applies from the next sentence, without a restart (saved while they start, it goes once they run, since the start may have read the settings before); it is sent again whenever the worker connects again. MeloTTS's Korean model has one voice, so there is no voice choice. |
|
||||
| `voiceWorker.python` | `python3` (`python.exe` on Windows) | Python of the worker venv. |
|
||||
| `voiceWorker.cwd` | `python-src` next to the app's executable when it is there (the Windows build), else the repo's `src/` | Folder holding the `voice_worker` package. |
|
||||
| `voiceWorker.args` | `[]` | Extra worker arguments, e.g. `["--melo-python", "<MeloTTS venv python>"]`. |
|
||||
|
||||
404
app/src/history_view.rs
Normal file
404
app/src/history_view.rs
Normal file
@@ -0,0 +1,404 @@
|
||||
//! The 대화 screen's reads (`app/src/admin.spec.md`, "Conversations"): what people said, what Jarvis
|
||||
//! answered and how each answer was made, from the worker's history store
|
||||
//! (`memory/history.sqlite`, schema owned by `src/jarvis/memory/history.py`). Read only; the
|
||||
//! screen is the only reader, and nothing it reads goes to a log.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
|
||||
use rusqlite::{params_from_iter, types::Value as Sql, Connection, OpenFlags};
|
||||
use serde_json::{json, Value};
|
||||
use unicode_normalization::UnicodeNormalization;
|
||||
|
||||
pub const DEFAULT_LIMIT: usize = 200;
|
||||
pub const MAX_LIMIT: usize = 2000;
|
||||
|
||||
/// What the screen asks for. `None` filters match everything.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Query {
|
||||
/// People's words (voice transcripts and chat messages).
|
||||
pub said: bool,
|
||||
/// Jarvis's answers and its own chat messages.
|
||||
pub answered: bool,
|
||||
/// How each answer was made (the traces).
|
||||
pub thought: bool,
|
||||
/// `voice`, `chat` or `task` (a task has traces only; its answer is a chat message).
|
||||
pub via: Option<String>,
|
||||
/// A person's records: written by them or answers to them.
|
||||
pub person: Option<String>,
|
||||
pub channel: Option<String>,
|
||||
/// Text the record (or the trace's question, answer or steps) contains, case folded.
|
||||
pub find: Option<String>,
|
||||
/// Unix seconds, inclusive / exclusive.
|
||||
pub since: Option<f64>,
|
||||
pub until: Option<f64>,
|
||||
/// Only items older than this one (paging back) / this one and newer (the window shown).
|
||||
pub before: Option<Cursor>,
|
||||
pub from: Option<Cursor>,
|
||||
pub limit: usize,
|
||||
}
|
||||
|
||||
/// An item's place in the order: time, then records before traces, then id. Items are ordered by
|
||||
/// it, so paging by it never skips or repeats one, even when two share a time.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Cursor {
|
||||
pub at: f64,
|
||||
/// 0: a record (`h<id>`), 1: a trace (`t<id>`).
|
||||
pub src: u8,
|
||||
pub id: i64,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
/// From `{at, key}`, as the screen sends an item back.
|
||||
pub fn of(v: &Value) -> Option<Self> {
|
||||
let at = v.get("at")?.as_f64()?;
|
||||
let key = v.get("key")?.as_str()?;
|
||||
let src = match key.get(..1)? { "h" => 0, "t" => 1, _ => return None };
|
||||
Some(Self { at, src, id: key[1..].parse().ok()? })
|
||||
}
|
||||
|
||||
/// SQL for "a row of table `src` comes before this cursor", over columns `{p}ts` and `{p}id`.
|
||||
fn before_sql(&self, src: u8, p: &str) -> (String, Vec<Sql>) {
|
||||
use std::cmp::Ordering::*;
|
||||
match src.cmp(&self.src) {
|
||||
Less => (format!("{p}ts <= ?"), vec![Sql::Real(self.at)]),
|
||||
Greater => (format!("{p}ts < ?"), vec![Sql::Real(self.at)]),
|
||||
Equal => (format!("({p}ts < ? OR ({p}ts = ? AND {p}id < ?))"),
|
||||
vec![Sql::Real(self.at), Sql::Real(self.at), Sql::Integer(self.id)]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The cursor conditions of `q` for table `src`, appended to `sql` and `args`.
|
||||
fn cursor_sql(q: &Query, src: u8, p: &str, sql: &mut String, args: &mut Vec<Sql>) {
|
||||
if let Some(c) = &q.before {
|
||||
let (cond, a) = c.before_sql(src, p);
|
||||
*sql += &format!(" AND {cond}");
|
||||
args.extend(a);
|
||||
}
|
||||
if let Some(c) = &q.from {
|
||||
let (cond, a) = c.before_sql(src, p);
|
||||
*sql += &format!(" AND NOT {cond}");
|
||||
args.extend(a);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Query {
|
||||
fn default() -> Self {
|
||||
Self { said: true, answered: true, thought: true, via: None, person: None, channel: None, find: None,
|
||||
since: None, until: None, before: None, from: None, limit: DEFAULT_LIMIT }
|
||||
}
|
||||
}
|
||||
|
||||
/// Jarvis's Discord user id, from its bot token: the token's first part is the id in base64.
|
||||
pub fn bot_id_of_token(token: &str) -> Option<String> {
|
||||
use base64::Engine;
|
||||
let first = token.trim().split('.').next()?.trim_end_matches('=');
|
||||
let raw = base64::engine::general_purpose::STANDARD_NO_PAD.decode(first)
|
||||
.or_else(|_| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(first)).ok()?;
|
||||
let id = String::from_utf8(raw).ok()?;
|
||||
(!id.is_empty() && id.len() <= 20 && id.bytes().all(|b| b.is_ascii_digit())).then_some(id)
|
||||
}
|
||||
|
||||
/// The history store's own text folding (`history.py`, `_fold`): NFKC, then lower case.
|
||||
fn fold(text: &str) -> String {
|
||||
text.nfkc().collect::<String>().to_lowercase()
|
||||
}
|
||||
|
||||
fn like(text: &str) -> String {
|
||||
let escaped = text.replace('\\', "\\\\").replace('%', "\\%").replace('_', "\\_");
|
||||
format!("%{escaped}%")
|
||||
}
|
||||
|
||||
fn open(path: &Path) -> Result<Connection, String> {
|
||||
// Read-write without create: a WAL database needs its shared-memory file, which a read-only
|
||||
// connection may not make. Only SELECTs run (query_only).
|
||||
let c = Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_NO_MUTEX)
|
||||
.map_err(|e| format!("대화 기록을 열 수 없습니다: {e}"))?;
|
||||
c.busy_timeout(std::time::Duration::from_secs(3)).map_err(|e| e.to_string())?;
|
||||
c.pragma_update(None, "query_only", true).map_err(|e| e.to_string())?;
|
||||
Ok(c)
|
||||
}
|
||||
|
||||
fn has_traces(c: &Connection) -> bool {
|
||||
c.query_row("SELECT 1 FROM sqlite_master WHERE type='table' AND name='traces'", [], |_| Ok(())).is_ok()
|
||||
}
|
||||
|
||||
/// The records and traces `q` asks for, newest `q.limit` of them in time order, with the people
|
||||
/// and channels the filters can pick from. `bot`: Jarvis's Discord user id, when known (its chat
|
||||
/// messages count as answers; without it only those that answer someone do, and the authors of those).
|
||||
pub fn query(path: &Path, bot: Option<&str>, q: &Query) -> Result<Value, String> {
|
||||
if !path.is_file() {
|
||||
return Ok(json!({"items": [], "more": false, "people": [], "channels": [], "missing": true}));
|
||||
}
|
||||
let c = open(path)?;
|
||||
let limit = q.limit.clamp(1, MAX_LIMIT);
|
||||
let bot = bot.unwrap_or("");
|
||||
let is_bot = "(h.to_id IS NOT NULL OR h.author_id = ?1 OR h.author_id IN \
|
||||
(SELECT author_id FROM history WHERE kind = 'chat' AND to_id IS NOT NULL))";
|
||||
let err = |e: rusqlite::Error| format!("대화 기록을 읽지 못했습니다: {e}");
|
||||
|
||||
let names: HashMap<String, String> = {
|
||||
let mut st = c.prepare("SELECT author_id, author_name, MAX(ts) FROM history \
|
||||
WHERE kind IN ('voice', 'chat') AND author_id != '' GROUP BY author_id").map_err(err)?;
|
||||
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?))).map_err(err)?;
|
||||
rows.collect::<Result<_, _>>().map_err(err)?
|
||||
};
|
||||
let name_of = |id: &str| names.get(id).cloned().unwrap_or_default();
|
||||
|
||||
let mut items: Vec<((f64, u8, i64), Value)> = Vec::new();
|
||||
let mut more = false;
|
||||
if q.said || q.answered {
|
||||
let mut sql = format!("SELECT h.id, h.ts, h.kind, h.channel_id, h.author_id, h.author_name, h.to_id, h.text, \
|
||||
({is_bot} AND h.kind = 'chat') OR h.kind = 'reply' FROM history h WHERE 1");
|
||||
let mut args: Vec<Sql> = vec![Sql::Text(bot.into())];
|
||||
match (q.said, q.answered) {
|
||||
(true, false) => sql += &format!(" AND (h.kind = 'voice' OR (h.kind = 'chat' AND NOT {is_bot}))"),
|
||||
(false, true) => sql += &format!(" AND (h.kind = 'reply' OR (h.kind = 'chat' AND {is_bot}))"),
|
||||
_ => {}
|
||||
}
|
||||
match q.via.as_deref() {
|
||||
Some("voice") => sql += " AND h.kind IN ('voice', 'reply')",
|
||||
Some("chat") => sql += " AND h.kind = 'chat'",
|
||||
Some(_) => sql += " AND 0",
|
||||
None => {}
|
||||
}
|
||||
if let Some(p) = &q.person {
|
||||
sql += " AND (h.author_id = ? OR h.to_id = ?)";
|
||||
args.extend([Sql::Text(p.clone()), Sql::Text(p.clone())]);
|
||||
}
|
||||
if let Some(ch) = &q.channel {
|
||||
sql += " AND h.channel_id = ?";
|
||||
args.push(Sql::Text(ch.clone()));
|
||||
}
|
||||
if let Some(f) = q.find.as_deref().map(str::trim).filter(|f| !f.is_empty()) {
|
||||
sql += " AND h.norm LIKE ? ESCAPE '\\'";
|
||||
args.push(Sql::Text(like(&fold(f))));
|
||||
}
|
||||
if let Some(t) = q.since { sql += " AND h.ts >= ?"; args.push(Sql::Real(t)); }
|
||||
if let Some(t) = q.until { sql += " AND h.ts < ?"; args.push(Sql::Real(t)); }
|
||||
cursor_sql(q, 0, "h.", &mut sql, &mut args);
|
||||
sql += &format!(" ORDER BY h.ts DESC, h.id DESC LIMIT {}", limit + 1);
|
||||
let mut st = c.prepare(&sql).map_err(err)?;
|
||||
let rows = st.query_map(params_from_iter(args), |r| {
|
||||
let (id, ts, kind): (i64, f64, String) = (r.get(0)?, r.get(1)?, r.get(2)?);
|
||||
let (author, author_name, to): (String, String, Option<String>) = (r.get(4)?, r.get(5)?, r.get(6)?);
|
||||
let answer: bool = r.get(8)?;
|
||||
Ok(((ts, 0, id), json!({
|
||||
"key": format!("h{id}"), "type": if answer { "answered" } else { "said" }, "at": ts,
|
||||
"via": if kind == "chat" { "chat" } else { "voice" }, "channel": r.get::<_, String>(3)?,
|
||||
"who": {"id": author, "name": author_name},
|
||||
"to": to.map(|t| json!({"id": t, "name": name_of(&t)})),
|
||||
"text": r.get::<_, String>(7)?,
|
||||
})))
|
||||
}).map_err(err)?;
|
||||
let got = rows.collect::<Result<Vec<_>, _>>().map_err(err)?;
|
||||
more |= got.len() > limit;
|
||||
items.extend(got.into_iter().take(limit));
|
||||
}
|
||||
if q.thought && has_traces(&c) {
|
||||
let mut sql = String::from("SELECT id, ts, via, channel_id, user_id, question, answer, ms, steps FROM traces WHERE 1");
|
||||
let mut args: Vec<Sql> = Vec::new();
|
||||
if let Some(v) = &q.via { sql += " AND via = ?"; args.push(Sql::Text(v.clone())); }
|
||||
if let Some(p) = &q.person { sql += " AND user_id = ?"; args.push(Sql::Text(p.clone())); }
|
||||
if let Some(ch) = &q.channel { sql += " AND channel_id = ?"; args.push(Sql::Text(ch.clone())); }
|
||||
if let Some(f) = q.find.as_deref().map(str::trim).filter(|f| !f.is_empty()) {
|
||||
sql += " AND (question LIKE ? ESCAPE '\\' OR answer LIKE ? ESCAPE '\\' OR steps LIKE ? ESCAPE '\\')";
|
||||
args.extend(std::iter::repeat_n(Sql::Text(like(f)), 3));
|
||||
}
|
||||
if let Some(t) = q.since { sql += " AND ts >= ?"; args.push(Sql::Real(t)); }
|
||||
if let Some(t) = q.until { sql += " AND ts < ?"; args.push(Sql::Real(t)); }
|
||||
cursor_sql(q, 1, "", &mut sql, &mut args);
|
||||
let sql = format!("{sql} ORDER BY ts DESC, id DESC LIMIT {}", limit + 1);
|
||||
let mut st = c.prepare(&sql).map_err(err)?;
|
||||
let rows = st.query_map(params_from_iter(args), |r| {
|
||||
let (id, ts): (i64, f64) = (r.get(0)?, r.get(1)?);
|
||||
let user: String = r.get(4)?;
|
||||
let steps: String = r.get(8)?;
|
||||
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)?,
|
||||
"steps": serde_json::from_str::<Value>(&steps).unwrap_or(json!([])),
|
||||
})))
|
||||
}).map_err(err)?;
|
||||
let got = rows.collect::<Result<Vec<_>, _>>().map_err(err)?;
|
||||
more |= got.len() > limit;
|
||||
items.extend(got.into_iter().take(limit));
|
||||
}
|
||||
items.sort_by(|a, b| b.0.0.total_cmp(&a.0.0).then(b.0.1.cmp(&a.0.1)).then(b.0.2.cmp(&a.0.2)));
|
||||
more |= items.len() > limit;
|
||||
items.truncate(limit);
|
||||
items.reverse();
|
||||
|
||||
let mut people: Vec<Value> = {
|
||||
let mut st = c.prepare(&format!("SELECT h.author_id, h.author_name, MAX(h.ts) FROM history h \
|
||||
WHERE (h.kind = 'voice' OR (h.kind = 'chat' AND NOT {is_bot})) AND h.author_id != '' GROUP BY h.author_id"))
|
||||
.map_err(err)?;
|
||||
let rows = st.query_map([bot], |r| Ok(json!({"id": r.get::<_, String>(0)?, "name": r.get::<_, String>(1)?})))
|
||||
.map_err(err)?;
|
||||
rows.collect::<Result<_, _>>().map_err(err)?
|
||||
};
|
||||
people.sort_by(|a, b| a["name"].as_str().cmp(&b["name"].as_str()));
|
||||
let channels: Vec<Value> = {
|
||||
let mut st = c.prepare("SELECT channel_id, MAX(kind = 'chat'), MAX(ts) FROM history GROUP BY channel_id \
|
||||
ORDER BY MAX(ts) DESC").map_err(err)?;
|
||||
let rows = st.query_map([], |r| Ok(json!({"id": r.get::<_, String>(0)?,
|
||||
"via": if r.get::<_, bool>(1)? { "chat" } else { "voice" }}))).map_err(err)?;
|
||||
rows.collect::<Result<_, _>>().map_err(err)?
|
||||
};
|
||||
Ok(json!({"items": items.into_iter().map(|(_, v)| v).collect::<Vec<_>>(), "more": more,
|
||||
"people": people, "channels": channels}))
|
||||
}
|
||||
|
||||
/// The history store's tables as `src/jarvis/memory/history.py` makes them, for tests.
|
||||
#[cfg(test)]
|
||||
pub(crate) const TEST_SCHEMA: &str = "
|
||||
CREATE TABLE history (id INTEGER PRIMARY KEY, ts REAL NOT NULL, kind TEXT NOT NULL, channel_id TEXT NOT NULL,
|
||||
author_id TEXT NOT NULL, author_name TEXT NOT NULL, to_id TEXT, message_id TEXT, text TEXT NOT NULL,
|
||||
norm TEXT NOT NULL);
|
||||
CREATE TABLE traces (id INTEGER PRIMARY KEY, ts REAL NOT NULL, via TEXT NOT NULL, channel_id TEXT,
|
||||
user_id TEXT NOT NULL, question TEXT NOT NULL, answer TEXT NOT NULL, ms INTEGER NOT NULL, steps TEXT NOT NULL);";
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn db(tag: &str) -> (PathBuf, Connection) {
|
||||
let dir = std::env::temp_dir().join(format!("jarvis-history-view-{tag}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("history.sqlite");
|
||||
let c = Connection::open(&path).unwrap();
|
||||
c.pragma_update(None, "journal_mode", "WAL").unwrap();
|
||||
c.execute_batch(TEST_SCHEMA).unwrap();
|
||||
(path, c)
|
||||
}
|
||||
|
||||
fn rec(c: &Connection, ts: f64, kind: &str, ch: &str, author: &str, name: &str, to: Option<&str>, text: &str) {
|
||||
c.execute("INSERT INTO history(ts, kind, channel_id, author_id, author_name, to_id, text, norm) VALUES (?,?,?,?,?,?,?,?)",
|
||||
rusqlite::params![ts, kind, ch, author, name, to, text, fold(text)]).unwrap();
|
||||
}
|
||||
|
||||
fn trace(c: &Connection, ts: f64, via: &str, ch: Option<&str>, user: &str, q: &str, a: &str, steps: &str) {
|
||||
c.execute("INSERT INTO traces(ts, via, channel_id, user_id, question, answer, ms, steps) VALUES (?,?,?,?,?,?,?,?)",
|
||||
rusqlite::params![ts, via, ch, user, q, a, 900, steps]).unwrap();
|
||||
}
|
||||
|
||||
/// Alice speaks and Jarvis answers by voice; Bob writes in chat and Jarvis (bot 900) answers there
|
||||
/// and also posts a reminder of its own.
|
||||
fn sample(tag: &str) -> PathBuf {
|
||||
let (path, c) = db(tag);
|
||||
rec(&c, 10.0, "voice", "vc", "1", "Alice", None, "서울 날씨 어때");
|
||||
trace(&c, 11.0, "voice", Some("vc"), "1", "서울 날씨 어때", "맑습니다",
|
||||
r#"[{"kind":"tools","names":["getWeather"]},{"kind":"think","text":"날씨 도구를 쓰자"}]"#);
|
||||
rec(&c, 12.0, "reply", "vc", "", "Jarvis", Some("1"), "맑습니다");
|
||||
rec(&c, 20.0, "chat", "ch", "2", "Bob", None, "Hello THERE");
|
||||
trace(&c, 21.0, "chat", Some("ch"), "2", "Hello THERE", "안녕하세요", "[]");
|
||||
rec(&c, 22.0, "chat", "ch", "900", "Jarvis", Some("2"), "안녕하세요");
|
||||
rec(&c, 30.0, "chat", "ch", "900", "Jarvis", None, "약속 알림");
|
||||
path
|
||||
}
|
||||
|
||||
fn kinds(v: &Value) -> Vec<(String, String)> {
|
||||
v["items"].as_array().unwrap().iter()
|
||||
.map(|i| (i["type"].as_str().unwrap().into(), i["text"].as_str().or(i["question"].as_str()).unwrap().into()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn everything_comes_in_time_order_with_who_said_it() {
|
||||
let path = sample("all");
|
||||
let v = query(&path, None, &Query::default()).unwrap();
|
||||
let k = kinds(&v);
|
||||
assert_eq!(k.iter().map(|(t, _)| t.as_str()).collect::<Vec<_>>(),
|
||||
["said", "thought", "answered", "said", "thought", "answered", "answered"]);
|
||||
let items = v["items"].as_array().unwrap();
|
||||
assert_eq!(items[2]["to"], json!({"id": "1", "name": "Alice"}));
|
||||
assert_eq!(items[1]["who"]["name"], "Alice");
|
||||
assert_eq!(items[1]["steps"][1]["text"], "날씨 도구를 쓰자");
|
||||
assert_eq!(items[1]["ms"], 900);
|
||||
// Jarvis's reminder counts as its own words because it answered in chat before.
|
||||
assert_eq!(k[6], ("answered".into(), "약속 알림".into()));
|
||||
assert_eq!(v["people"], json!([{"id": "1", "name": "Alice"}, {"id": "2", "name": "Bob"}]));
|
||||
assert_eq!(v["channels"], json!([{"id": "ch", "via": "chat"}, {"id": "vc", "via": "voice"}]));
|
||||
assert_eq!(v["more"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_filters_pick_kinds_people_places_text_and_time() {
|
||||
let path = sample("filters");
|
||||
let only = |q: Query| kinds(&query(&path, Some("900"), &q).unwrap());
|
||||
assert_eq!(only(Query { answered: false, thought: false, ..Query::default() }),
|
||||
[("said".into(), "서울 날씨 어때".into()), ("said".into(), "Hello THERE".into())]);
|
||||
assert_eq!(only(Query { said: false, answered: false, ..Query::default() }).len(), 2);
|
||||
assert_eq!(only(Query { via: Some("voice".into()), ..Query::default() }).len(), 3);
|
||||
assert_eq!(only(Query { via: Some("task".into()), ..Query::default() }), Vec::<(String, String)>::new());
|
||||
assert_eq!(only(Query { person: Some("2".into()), ..Query::default() }).len(), 3);
|
||||
assert_eq!(only(Query { channel: Some("vc".into()), ..Query::default() }).len(), 3);
|
||||
// Text search ignores case, and finds a trace by what it thought.
|
||||
assert_eq!(only(Query { find: Some("hello there".into()), thought: false, ..Query::default() }),
|
||||
[("said".into(), "Hello THERE".into())]);
|
||||
assert_eq!(only(Query { find: Some("도구를".into()), ..Query::default() }),
|
||||
[("thought".into(), "서울 날씨 어때".into())]);
|
||||
assert_eq!(only(Query { find: Some("100%".into()), ..Query::default() }).len(), 0);
|
||||
assert_eq!(only(Query { since: Some(20.0), until: Some(30.0), ..Query::default() }).len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_newest_come_first_when_there_are_more_than_asked() {
|
||||
let path = sample("limit");
|
||||
let v = query(&path, None, &Query { limit: 2, ..Query::default() }).unwrap();
|
||||
assert_eq!(kinds(&v), [("answered".into(), "안녕하세요".into()), ("answered".into(), "약속 알림".into())]);
|
||||
assert_eq!(v["more"], true);
|
||||
}
|
||||
|
||||
/// Every item, walking back page by page with the cursor of the oldest one shown.
|
||||
#[test]
|
||||
fn pages_walk_back_through_everything_past_any_limit_even_at_equal_times() {
|
||||
let (path, c) = db("pages");
|
||||
for i in 0..7 {
|
||||
// Records and traces at the same moments, so a page edge falls inside equal times.
|
||||
rec(&c, (i / 2) as f64, "voice", "vc", "1", "Alice", None, &format!("말 {i}"));
|
||||
trace(&c, (i / 2) as f64, "voice", Some("vc"), "1", &format!("생각 {i}"), "", "[]");
|
||||
}
|
||||
let all = query(&path, None, &Query { limit: MAX_LIMIT, ..Query::default() }).unwrap()["items"].clone();
|
||||
let all: Vec<Value> = all.as_array().unwrap().clone();
|
||||
assert_eq!(all.len(), 14);
|
||||
let cursor = |i: &Value| Cursor::of(&json!({"at": i["at"], "key": i["key"]})).unwrap();
|
||||
let mut got: Vec<Value> = Vec::new();
|
||||
let mut before = None;
|
||||
loop {
|
||||
let v = query(&path, None, &Query { limit: 3, before, ..Query::default() }).unwrap();
|
||||
let page = v["items"].as_array().unwrap().clone();
|
||||
before = page.first().map(cursor);
|
||||
got.splice(0..0, page);
|
||||
if v["more"] == false { break; }
|
||||
}
|
||||
assert_eq!(got, all);
|
||||
// From a cursor on: that item and everything newer, whatever the limit was before.
|
||||
let from = query(&path, None, &Query { limit: MAX_LIMIT, from: Some(cursor(&all[5])), ..Query::default() }).unwrap();
|
||||
assert_eq!(from["items"].as_array().unwrap()[..], all[5..]);
|
||||
assert!(Cursor::of(&json!({"at": 1.0, "key": "x1"})).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bot_id_comes_from_its_token() {
|
||||
assert_eq!(bot_id_of_token("MTIzNDU2Nzg5MDEyMzQ1Njc4.GxYzAb.abcdef").as_deref(), Some("123456789012345678"));
|
||||
assert_eq!(bot_id_of_token("bm90IGFuIGlk.x.y"), None);
|
||||
assert_eq!(bot_id_of_token(""), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_missing_store_or_one_without_traces_reads_as_empty() {
|
||||
let dir = std::env::temp_dir().join(format!("jarvis-history-view-none-{}", std::process::id()));
|
||||
let v = query(&dir.join("history.sqlite"), None, &Query::default()).unwrap();
|
||||
assert_eq!((v["items"].clone(), v["missing"].clone()), (json!([]), json!(true)));
|
||||
let (path, c) = db("old");
|
||||
c.execute_batch("DROP TABLE traces").unwrap();
|
||||
rec(&c, 1.0, "voice", "vc", "1", "Alice", None, "안녕");
|
||||
assert_eq!(kinds(&query(&path, None, &Query::default()).unwrap()), [("said".into(), "안녕".into())]);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ pub mod discord_setup;
|
||||
pub mod download;
|
||||
pub mod earcon;
|
||||
pub mod features;
|
||||
pub mod history_view;
|
||||
pub mod game;
|
||||
pub mod frames;
|
||||
pub mod install;
|
||||
|
||||
@@ -221,6 +221,9 @@ pub struct Settings {
|
||||
/// Jarvis's voice channel (admin.spec.md, "Schedules"); None: not delivered then.
|
||||
pub schedule_channel: Option<u64>,
|
||||
pub pc_control: PcControlSettings,
|
||||
/// The window's close button (X) hides it to the tray instead of quitting (`app.closeButton`:
|
||||
/// "tray" or "quit", default "quit"; admin.spec.md, "Window and Windows build").
|
||||
pub close_to_tray: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -272,6 +275,7 @@ impl Default for Settings {
|
||||
pc_control: PcControlSettings { allowed_users: vec![], view: Level::Auto, click: Level::Ask,
|
||||
type_text: Level::Ask, run: Level::Ask,
|
||||
screen_exclude: ["1Password", "Bitwarden", "KeePass", "KeePassXC"].map(String::from).into() },
|
||||
close_to_tray: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -618,6 +622,11 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
|
||||
game: parse_game(raw, &d.game)?,
|
||||
schedule_channel,
|
||||
pc_control: parse_pc_control(raw, &d.pc_control)?,
|
||||
close_to_tray: match get_str(section(raw, "app")?, "closeButton", "app", "quit")?.as_str() {
|
||||
"tray" => true,
|
||||
"quit" => false,
|
||||
_ => return err("app.closeButton must be tray or quit"),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -984,6 +993,16 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_close_button_choice_is_read_and_checked() {
|
||||
assert!(!parse_settings(&json!({})).unwrap().close_to_tray, "closing quits by default");
|
||||
assert!(parse_settings(&json!({"app": {"closeButton": "tray"}})).unwrap().close_to_tray);
|
||||
assert!(!parse_settings(&json!({"app": {"closeButton": "quit"}})).unwrap().close_to_tray);
|
||||
for bad in [json!({"app": {"closeButton": "hide"}}), json!({"app": {"closeButton": 1}}), json!({"app": 1})] {
|
||||
assert!(parse_settings(&bad).unwrap_err().0.contains("app"), "{bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn game_detection_settings_are_read_and_checked() {
|
||||
assert_eq!(parse_settings(&json!({})).unwrap().game, GameSettings { detect: true, games: vec![], not_games: vec![], other_room_gb: 1.0, reserve_gb: 8.0, revert_seconds: 30, pause_in_game: false });
|
||||
|
||||
@@ -24,6 +24,7 @@ pub enum Screen {
|
||||
Game,
|
||||
Schedule,
|
||||
PcControl,
|
||||
App,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize)]
|
||||
@@ -120,7 +121,7 @@ pub fn fields() -> Vec<Field> {
|
||||
f("voice.stt.final_beam", Model, Int { min: 1, max: 5 }, json!(2), "최종 전사 정확도(빔)"),
|
||||
f("voice.stt.language", Model, LanguageCode, json!("ko"), "받아 적을 언어(비우면 자동)"),
|
||||
// MeloTTS's Korean model has one voice (speaker "KR"), so only the speed is a choice.
|
||||
f("voice.tts.speed", Model, Number { min: 0.5, max: 2.0 }, json!(1.5), "말하기 속도(MeloTTS, 기본 1.5)"),
|
||||
f("voice.tts.speed", Model, Number { min: 0.5, max: 2.0 }, json!(1.5), "말하기 속도(1.0 보통, 기본 1.5, 저장하면 바로 적용)"),
|
||||
// The LLM (admin.spec.md, "LLM"); `llm.url` (a server the app does not start) is file-only.
|
||||
f("llm.context", Model, Int { min: 4096, max: 262144 }, json!(32768), "대화 모델이 한 번에 기억하는 양(토큰)"),
|
||||
f("llm.port", Model, Int { min: 1024, max: 65535 }, json!(8080), "대화 모델 포트"),
|
||||
@@ -159,6 +160,8 @@ pub fn fields() -> Vec<Field> {
|
||||
f("game.revertSeconds", Game, Int { min: 0, max: 600 }, json!(30), "게임이 끝난 뒤 평소 배치로 돌아가기까지(초)"),
|
||||
f("game.pauseInGame", Game, Bool, json!(false), "게임 중 일시정지(대답하지 않음)"),
|
||||
f("game.notGames", Game, TextList { max_items: 100, nullable: false }, json!([]), "게임이 아닌 프로그램(파일 이름)"),
|
||||
// The window (admin.spec.md, "Window and Windows build"): read when the close button is pressed.
|
||||
f("app.closeButton", App, Choice { values: &["quit", "tray"] }, json!("quit"), "창 닫기(X) 버튼을 누르면"),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -226,6 +226,9 @@ struct Inner {
|
||||
/// The LLM state the brain should have: sent again on every connection, so a worker that
|
||||
/// missed it (a dropped connection, a restarted worker) catches up.
|
||||
llm: Mutex<Option<Value>>,
|
||||
/// The latest speech speed set while running, sent again on every connection: a restarted worker
|
||||
/// starts with the speed of its arguments.
|
||||
tts_speed: Mutex<Option<f64>>,
|
||||
/// The number of the latest switch.
|
||||
llm_switches: std::sync::atomic::AtomicU64,
|
||||
}
|
||||
@@ -248,6 +251,7 @@ impl WorkerClient {
|
||||
wake: Notify::new(),
|
||||
llm_idle: watch::channel(0).0,
|
||||
llm: Mutex::new(None),
|
||||
tts_speed: Mutex::new(None),
|
||||
llm_switches: std::sync::atomic::AtomicU64::new(0),
|
||||
});
|
||||
(Self { inner }, rx)
|
||||
@@ -497,6 +501,14 @@ impl WorkerClient {
|
||||
self.set_llm(json!({"type": "llm", "state": "ready", "game": game}))
|
||||
}
|
||||
|
||||
/// Speak at `speed` from the next sentence on (`tts_speed`). False when not connected; it still
|
||||
/// goes out on the next connection.
|
||||
pub fn set_tts_speed(&self, speed: f64) -> bool {
|
||||
let mut s = self.inner.tts_speed.lock().unwrap();
|
||||
*s = Some(speed);
|
||||
self.send_json(json!({"type": "tts_speed", "speed": speed}))
|
||||
}
|
||||
|
||||
fn set_llm(&self, m: Value) -> bool {
|
||||
let mut llm = self.inner.llm.lock().unwrap();
|
||||
*llm = Some(m.clone());
|
||||
@@ -637,9 +649,11 @@ async fn connect_once(inner: &Arc<Inner>) -> bool {
|
||||
|
||||
let (tx, mut rx) = mpsc::unbounded_channel::<Message>();
|
||||
{
|
||||
// Locks in the order llm, then state (as `llm_state` takes them): the latest LLM state goes
|
||||
// first, and the connection is ready for sending before an LLM state set meanwhile is sent.
|
||||
// Locks in the order llm, tts_speed, then state (as `llm_state` and `set_tts_speed` take
|
||||
// them): the latest LLM state and speed go first, and the connection is ready for sending
|
||||
// before one set meanwhile is sent.
|
||||
let llm = inner.llm.lock().unwrap();
|
||||
let speed = inner.tts_speed.lock().unwrap();
|
||||
let mut st = inner.state.lock().unwrap();
|
||||
if st.closed {
|
||||
return true;
|
||||
@@ -647,6 +661,9 @@ async fn connect_once(inner: &Arc<Inner>) -> bool {
|
||||
if let Some(m) = llm.clone() {
|
||||
let _ = tx.send(Message::text(m.to_string()));
|
||||
}
|
||||
if let Some(s) = *speed {
|
||||
let _ = tx.send(Message::text(json!({"type": "tts_speed", "speed": s}).to_string()));
|
||||
}
|
||||
st.conn = Some(tx);
|
||||
inner.ready.send_replace(Some(hello_ok.clone()));
|
||||
}
|
||||
|
||||
48
app/tests/ui/talk.test.mjs
Normal file
48
app/tests/ui/talk.test.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
// The 대화 screen's paging (app/ui/talk.js; admin.spec.md, "Screens"). Run: node --test app/tests/ui/talk.test.mjs
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { PAGE, PAGE_MAX, compare, empty, withLive, withOlder } from "../../ui/talk.js";
|
||||
|
||||
const rec = (n) => ({ key: `h${n}`, at: n, type: "said", text: `말 ${n}` });
|
||||
const range = (a, b) => Array.from({ length: b - a }, (_, i) => rec(a + i));
|
||||
const keys = (s) => s.older.concat(s.shown).map((i) => i.key);
|
||||
|
||||
/** The screen's state after the first page and as many "이전 기록 더 보기" as the store allows. */
|
||||
function allLoaded(total) {
|
||||
const store = range(0, total);
|
||||
let s = withLive(empty(), store.slice(-PAGE), total > PAGE);
|
||||
while (s.hasOlder) {
|
||||
const oldest = (s.older[0] || s.shown[0]).at;
|
||||
const before = store.filter((i) => i.at < oldest);
|
||||
s = withOlder(s, before.slice(-PAGE), before.length > PAGE);
|
||||
}
|
||||
return { s, store };
|
||||
}
|
||||
|
||||
test("every older page joins once, past the live window", () => {
|
||||
const { s } = allLoaded(2501);
|
||||
assert.equal(s.shown.length, PAGE_MAX);
|
||||
assert.deepEqual(keys(s), range(0, 2501).map((i) => i.key));
|
||||
});
|
||||
|
||||
test("the same older page arriving twice is not added twice", () => {
|
||||
let s = withLive(empty(), range(300, 500), true);
|
||||
s = withOlder(s, range(100, 300), true);
|
||||
s = withOlder(s, range(100, 300), true);
|
||||
assert.deepEqual(keys(s), range(100, 500).map((i) => i.key));
|
||||
});
|
||||
|
||||
test("a new item on a full window keeps everything loaded, in order and once", () => {
|
||||
const { s, store } = allLoaded(2501);
|
||||
const now = store.concat(rec(2501));
|
||||
// The live answer: from the window's start, at most PAGE_MAX, newest first cut.
|
||||
const since = now.filter((i) => compare(i, s.shown[0]) >= 0);
|
||||
const next = withLive(s, since.slice(-PAGE_MAX), since.length > PAGE_MAX);
|
||||
assert.deepEqual(keys(next), range(0, 2502).map((i) => i.key));
|
||||
assert.equal(next.shown.length, PAGE_MAX);
|
||||
});
|
||||
|
||||
test("items are ordered by time, then records before traces, then id", () => {
|
||||
const items = [{ key: "t2", at: 1 }, { key: "h10", at: 1 }, { key: "h9", at: 1 }, { key: "h1", at: 0 }];
|
||||
assert.deepEqual(items.sort(compare).map((i) => i.key), ["h1", "h9", "h10", "t2"]);
|
||||
});
|
||||
@@ -503,3 +503,22 @@ async fn ready_tells_the_worker_whether_a_game_runs() {
|
||||
until(|| w.got().iter().any(|g| *g == Got::Json(json!({"type": "llm", "state": "ready", "game": true})))).await;
|
||||
c.close();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_speech_speed_goes_out_at_once_and_again_on_every_connection() {
|
||||
let w = FakeWorker::start(0).await;
|
||||
let (c, mut rx) = client(&w.url(), json!({}));
|
||||
c.start();
|
||||
c.wait_ready(Duration::from_secs(2)).await.unwrap();
|
||||
assert!(c.set_tts_speed(1.8), "sent while connected");
|
||||
until(|| w.got().contains(&Got::Json(json!({"type": "tts_speed", "speed": 1.8})))).await;
|
||||
// A restarted worker starts with the speed of its arguments; the latest one set catches it up.
|
||||
let port = w.kill();
|
||||
next_matching(&mut rx, |e| *e == WorkerEvent::Disconnected).await;
|
||||
assert!(!c.set_tts_speed(1.2), "not sent: no connection");
|
||||
let w2 = FakeWorker::start(port).await;
|
||||
until(|| w2.got().iter().any(|g| matches!(g, Got::Json(v) if v["type"] == "tts_speed"))).await;
|
||||
let speeds: Vec<_> = w2.got().into_iter().filter(|g| matches!(g, Got::Json(v) if v["type"] == "tts_speed")).collect();
|
||||
assert_eq!(speeds, [Got::Json(json!({"type": "tts_speed", "speed": 1.2}))]);
|
||||
c.close();
|
||||
}
|
||||
|
||||
190
app/ui/app.js
190
app/ui/app.js
@@ -2,6 +2,8 @@
|
||||
// the Tauri shell and the development server load the same files. Every action goes through
|
||||
// api(command, args), which the shell answers with AdminApi::call.
|
||||
|
||||
import { PAGE, PAGE_MAX, cursorOf, empty, withLive, withOlder } from "./talk.js";
|
||||
|
||||
const $ = (sel, el = document) => el.querySelector(sel);
|
||||
const h = (tag, attrs = {}, ...kids) => {
|
||||
const el = document.createElement(tag);
|
||||
@@ -40,6 +42,7 @@ const LEVEL = { auto: "자동", ask: "먼저 묻기", never: "안 함" };
|
||||
const CHOICE = {
|
||||
"pcControl.view": LEVEL, "pcControl.click": LEVEL, "pcControl.type": LEVEL, "pcControl.run": LEVEL,
|
||||
"call.mode": { wakeWord: "호출어로 부를 때만", addressed: "자비스에게 하는 말로 보이면", everything: "모든 말" },
|
||||
"app.closeButton": { quit: "완전 종료", tray: "트레이로 최소화" },
|
||||
"response.policy": { first: "처음 대화만", inOrder: "순서대로", latest: "가장 최근 것", important: "중요한 것 먼저" },
|
||||
};
|
||||
const REASON = { busy: "다른 답을 하는 중", queue_full: "대기열이 가득 참", replaced: "더 새 요청이 대신함",
|
||||
@@ -402,6 +405,185 @@ function activityScreen() {
|
||||
h("div", { class: "field" }, h("button", { class: "btn", onclick: load }, "새로 고침")), list));
|
||||
}
|
||||
|
||||
// ---- conversations ------------------------------------------------------------------------------
|
||||
|
||||
const VIA = { voice: "음성", chat: "채팅", task: "정기 작업" };
|
||||
const SKIPPED = { not_allowed: "허용되지 않은 도구라 부르지 않음", duplicate: "같은 호출을 되풀이해 부르지 않음" };
|
||||
const p2 = (n) => String(n).padStart(2, "0");
|
||||
const dayOf = (ts) => { const d = new Date(ts * 1000); return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`; };
|
||||
const timeOf = (ts) => { const d = new Date(ts * 1000); return `${p2(d.getHours())}:${p2(d.getMinutes())}:${p2(d.getSeconds())}`; };
|
||||
const pre = (text) => h("pre", { class: "pre" }, text);
|
||||
|
||||
/** One step of how an answer was made (history.spec.md, "Traces"). */
|
||||
function traceStep(s) {
|
||||
if (s.kind === "records") {
|
||||
const lines = (title, xs) => xs.length ? h("details", {}, h("summary", { class: "small" }, `${title} ${xs.length}줄`), pre(xs.join("\n"))) : null;
|
||||
return h("div", { class: "step-row" }, h("div", { class: "k" }, "참고한 기록"),
|
||||
h("div", {}, (s.recent || []).length + (s.matches || []).length ? null : h("span", { class: "muted" }, "없음"),
|
||||
lines("최근 대화", s.recent || []), lines("관련 기록", s.matches || []),
|
||||
s.notes ? h("div", { class: "small muted" }, `사람별 지침 ${s.notes}개`) : null));
|
||||
}
|
||||
if (s.kind === "tools") return h("div", { class: "step-row" }, h("div", { class: "k" }, "쓸 수 있게 고른 도구"),
|
||||
h("div", { class: "row" }, (s.names || []).length ? s.names.map((n) => h("span", { class: "badge" }, n)) : h("span", { class: "muted" }, "없음")));
|
||||
if (s.kind === "plan") return h("div", { class: "step-row" }, h("div", { class: "k" }, "계획"), h("ol", { class: "plan" }, (s.steps || []).map((x) => h("li", {}, x))));
|
||||
if (s.kind === "think") return h("div", { class: "step-row" }, h("div", { class: "k" }, "모델 생각"), pre(s.text || ""));
|
||||
if (s.kind === "tool") {
|
||||
const state = s.skipped ? ["건너뜀", "warn"] : s.ok ? ["성공", "ok"] : ["실패", "bad"];
|
||||
return h("div", { class: "step-row" }, h("div", { class: "k" }, "도구 호출"),
|
||||
h("div", {}, h("div", { class: "row" }, h("b", {}, s.name), h("span", { class: "badge " + state[1] }, state[0])),
|
||||
Object.keys(s.args || {}).length ? pre(JSON.stringify(s.args, null, 2)) : null,
|
||||
s.skipped ? h("div", { class: "small muted" }, SKIPPED[s.skipped] || s.skipped) : null,
|
||||
s.result ? h("details", {}, h("summary", { class: "small" }, "결과"), pre(s.result)) : null));
|
||||
}
|
||||
return h("div", { class: "step-row" }, h("div", { class: "k" }, s.kind), pre(JSON.stringify(s, null, 2)));
|
||||
}
|
||||
|
||||
/** The 대화 screen (admin.spec.md, "Conversations"): what people said, what Jarvis answered, how. */
|
||||
function conversationScreen() {
|
||||
const chip = (label, on = true) => { const c = h("input", { type: "checkbox", checked: on }); return [c, h("label", { class: "chip" }, c, label)]; };
|
||||
const [said, saidChip] = chip("사람 말"), [answered, answeredChip] = chip("자비스 말"), [thought, thoughtChip] = chip("자비스 생각");
|
||||
const [session, sessionChip] = chip("현재 세션", false); // from when the bot was last started
|
||||
const via = h("select", {}, h("option", { value: "" }, "모든 곳"), Object.entries(VIA).map(([v, t]) => h("option", { value: v }, t)));
|
||||
const person = h("select", {}, h("option", { value: "" }, "모든 사람"));
|
||||
const channel = h("select", {}, h("option", { value: "" }, "모든 채널"));
|
||||
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
|
||||
// `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;
|
||||
let epoch = 0, liveSeq = 0, first = true, loadingOlder = false;
|
||||
const box = h("div", { class: "talk" });
|
||||
const summary = h("div", { class: "small muted" });
|
||||
const more = h("button", { class: "btn", hidden: true, onclick: () => loadOlder() }, "이전 기록 더 보기");
|
||||
|
||||
const fill = (sel, list, label) => {
|
||||
const key = JSON.stringify(list);
|
||||
if (sel.dataset.list === key) return; // an open picker is not rebuilt under the user
|
||||
sel.dataset.list = key;
|
||||
const keep = sel.value;
|
||||
sel.replaceChildren(sel.firstChild, ...list.map((x) => h("option", { value: x.id }, label(x))));
|
||||
sel.value = list.some((x) => x.id === keep) ? keep : "";
|
||||
};
|
||||
const channelLabel = (c) => c.name ? `${c.name} (${VIA[c.via]})` : `${VIA[c.via]} 채널 ${c.id}`;
|
||||
const channelName = (id) => { const c = (load.channels || []).find((x) => x.id === id); return c ? channelLabel(c) : id || ""; };
|
||||
const copy = (text) => async () => { try { await navigator.clipboard.writeText(text); toast("복사했습니다"); } catch (e) { fail(e); } };
|
||||
|
||||
function item(i) {
|
||||
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 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),
|
||||
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)));
|
||||
return d;
|
||||
}
|
||||
const mine = i.type === "answered";
|
||||
const who = mine ? (i.to ? `자비스 → ${i.to.name || i.to.id}` : "자비스") : (i.who.name || i.who.id);
|
||||
return h("div", { class: "msg " + (mine ? "answered" : "said") },
|
||||
h("div", { class: "row" }, h("span", { class: "who" }, who), where,
|
||||
h("button", { class: "linkbtn small", title: "글 복사", onclick: copy(i.text) }, "복사")),
|
||||
h("div", { class: "text" }, i.text));
|
||||
}
|
||||
|
||||
function filters() {
|
||||
const since = day.value ? new Date(day.value + "T00:00:00").getTime() / 1000 : null;
|
||||
return { said: said.checked, answered: answered.checked, thought: thought.checked,
|
||||
via: via.value || null, person: person.value || null, channel: channel.value || null, find: find.value || null,
|
||||
since, until: since == null ? null : since + 86400, session: session.checked };
|
||||
}
|
||||
|
||||
function render(keepTop = false) {
|
||||
const items = page.older.concat(page.shown);
|
||||
// The whole items, so an edited message or a changed answer is redrawn too.
|
||||
const s = JSON.stringify([items, expandAll, page.hasOlder, missing, session.checked, sessionAt]);
|
||||
if (s === sig) return;
|
||||
sig = s;
|
||||
const stick = box.scrollTop + box.clientHeight >= box.scrollHeight - 30, fromBottom = box.scrollHeight - box.scrollTop;
|
||||
const kids = [];
|
||||
let lastDay = null;
|
||||
for (const i of items) {
|
||||
const d = dayOf(i.at);
|
||||
if (d !== lastDay) { kids.push(h("div", { class: "day" }, d)); lastDay = d; }
|
||||
kids.push(item(i));
|
||||
}
|
||||
box.replaceChildren(...(kids.length ? kids : [h("div", { class: "muted" },
|
||||
missing ? "아직 대화 기록이 없습니다. 서비스를 켜고 자비스와 이야기하면 여기에 나옵니다."
|
||||
: session.checked && sessionAt == null ? "앱을 켠 뒤 아직 봇을 시작하지 않았습니다. 대시보드에서 시작하면 그때부터의 대화가 여기에 나옵니다."
|
||||
: "조건에 맞는 기록이 없습니다.")]));
|
||||
more.hidden = !page.hasOlder;
|
||||
const n = (t) => items.filter((i) => i.type === t).length;
|
||||
summary.textContent = (session.checked && sessionAt != null ? `${dayOf(sessionAt)} ${timeOf(sessionAt)}에 시작한 봇부터 · ` : "")
|
||||
+ `사람 말 ${n("said")} · 자비스 말 ${n("answered")} · 생각 ${n("thought")}` + (page.hasOlder ? " (이전 기록 더 있음)" : "");
|
||||
if (keepTop) box.scrollTop = box.scrollHeight - fromBottom;
|
||||
else if (stick || first) box.scrollTop = box.scrollHeight;
|
||||
first = false;
|
||||
}
|
||||
|
||||
function lists(r) {
|
||||
load.channels = r.channels;
|
||||
fill(person, r.people, (p) => `${p.name || p.id}`);
|
||||
fill(channel, r.channels, channelLabel);
|
||||
}
|
||||
|
||||
/** The live window, from its first item on (the newest page at first), re-read on every tick. */
|
||||
async function load() {
|
||||
const ep = epoch, my = ++liveSeq, from = page.from;
|
||||
try {
|
||||
const r = await api("history_query", { ...filters(), ...(from ? { from, limit: PAGE_MAX } : { limit: PAGE }) });
|
||||
if (ep !== epoch || my !== liveSeq) return;
|
||||
lists(r);
|
||||
missing = !!r.missing;
|
||||
// A new start while the current session is shown: its window starts over at the new start.
|
||||
if (session.checked && sessionAt != null && r.session !== sessionAt) { sessionAt = r.session; reload(); return; }
|
||||
sessionAt = r.session ?? null;
|
||||
page = withLive(page, r.items, r.more);
|
||||
render();
|
||||
} catch (e) { fail(e); }
|
||||
}
|
||||
|
||||
/** The page before the oldest item loaded; one at a time, so a double click adds it once. */
|
||||
async function loadOlder() {
|
||||
const oldest = page.older[0] || page.shown[0];
|
||||
if (!oldest || loadingOlder) return;
|
||||
const ep = epoch;
|
||||
loadingOlder = more.disabled = true;
|
||||
try {
|
||||
const r = await api("history_query", { ...filters(), before: cursorOf(oldest), limit: PAGE });
|
||||
if (ep !== epoch) return;
|
||||
++liveSeq; // a live answer asked with the old window would drop this page
|
||||
page = withOlder(page, r.items, r.more);
|
||||
render(true);
|
||||
} catch (e) { fail(e); } finally {
|
||||
if (ep === epoch) loadingOlder = more.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
const reload = () => {
|
||||
epoch++; sig = null; page = empty(); first = true; loadingOlder = more.disabled = false; load();
|
||||
};
|
||||
for (const el of [said, answered, thought, session, via, person, channel, day]) el.addEventListener("change", reload);
|
||||
find.addEventListener("input", () => { clearTimeout(find.t); find.t = setTimeout(reload, 300); });
|
||||
const view = h("div", {}, h("h1", {}, "대화"),
|
||||
h("div", { class: "card filters" },
|
||||
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: () => { sig = null; load(); } }, "새로 고침"), summary)),
|
||||
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() };
|
||||
}
|
||||
|
||||
async function settingsScreen(screen, title, extra) {
|
||||
const [all, view] = await Promise.all([fields(), api("settings_view")]);
|
||||
const list = all.filter((f) => f.screen === screen);
|
||||
@@ -671,7 +853,7 @@ function updateScreen() {
|
||||
u.phase === "ready" ? act("update_install", "설치하고 다시 시작", true) : null),
|
||||
u.phase === "ready" ? h("p", { class: "small muted" }, "설치하면 봇과 서비스를 멈추고 Jarvis를 닫은 뒤 새 버전을 설치하고 다시 켭니다. Windows가 관리자 권한을 한 번 묻습니다.") : null),
|
||||
u.latest?.notes ? h("div", { class: "card" }, h("h2", {}, `${u.latest.version} 바뀐 점`),
|
||||
h("pre", { class: "small", style: "white-space:pre-wrap" }, u.latest.notes)) : null);
|
||||
h("pre", { class: "small", style: "white-space:pre-wrap" }, u.latest.notes)) : "");
|
||||
}
|
||||
tick();
|
||||
return { view: h("div", {}, h("h1", {}, "업데이트"), body), tick };
|
||||
@@ -719,11 +901,13 @@ async function show(name) {
|
||||
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 === "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 제어" };
|
||||
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard() : null;
|
||||
collect: "백그라운드 수집", game: "게임 모드", schedule: "예약", pcControl: "PC 제어", app: "앱" };
|
||||
const extra = name === "bot" ? await tokenCard() : name === "features" ? await displayDriverCard()
|
||||
: name === "app" ? h("div", { class: "hint", style: "margin-bottom:12px" }, "트레이로 최소화하면 창만 숨고 봇과 서비스는 계속 돕니다. 작업 표시줄 오른쪽의 Jarvis 아이콘을 누르면 창이 다시 열리고, 아이콘의 오른쪽 클릭 메뉴에서 완전 종료할 수 있습니다. 저장하면 바로 적용됩니다.") : null;
|
||||
const view = await settingsScreen(name, titles[name], extra);
|
||||
if (name === "collect") view.append(await collectResults());
|
||||
if (name === "schedule") view.append(await scheduleList());
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<nav class="side">
|
||||
<div class="brand">Jarvis</div>
|
||||
<button data-screen="dashboard" class="nav">대시보드</button>
|
||||
<button data-screen="conversations" class="nav">대화</button>
|
||||
<button data-screen="bot" class="nav">봇</button>
|
||||
<button data-screen="channels" class="nav">채널·호출</button>
|
||||
<button data-screen="chat" class="nav">채팅 채널</button>
|
||||
@@ -26,6 +27,7 @@
|
||||
<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>
|
||||
<div class="side-foot" id="version"></div>
|
||||
</nav>
|
||||
<main id="screen" class="screen"></main>
|
||||
|
||||
@@ -73,3 +73,23 @@ a { color: var(--accent2); }
|
||||
.row > select, .row > input[type=date] { width: auto; }
|
||||
input[type=date] { color-scheme: dark; }
|
||||
th, .btn { white-space: nowrap; }
|
||||
.filters { display: flex; flex-direction: column; gap: 10px; }
|
||||
.filters select, .filters input[type=date] { width: auto; }
|
||||
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); border-radius: 999px; padding: 4px 12px; cursor: pointer; color: var(--ink2); }
|
||||
.chip:has(input:checked) { border-color: var(--accent); color: var(--ink); background: var(--s3); }
|
||||
.talk { background: var(--s1); border: 1px solid var(--line); border-radius: 10px; height: 62vh; overflow: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
|
||||
.day { align-self: center; color: var(--ink4); font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; margin: 6px 0; }
|
||||
.msg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; max-width: 85%; background: var(--s2); }
|
||||
.msg.said { align-self: flex-start; }
|
||||
.msg.answered { align-self: flex-end; border-color: #2f3570; background: #12142a; }
|
||||
.msg.thought { align-self: stretch; max-width: none; border-style: dashed; background: var(--canvas); }
|
||||
.msg.thought > summary { cursor: pointer; }
|
||||
.msg .who { font-weight: 600; }
|
||||
.msg .text { white-space: pre-wrap; word-break: break-word; margin-top: 4px; line-height: 1.5; }
|
||||
.steps { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
|
||||
.step-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
|
||||
.step-row .k { color: var(--ink3); font-size: 12px; padding-top: 2px; }
|
||||
.pre { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--s1); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 4px 0; max-height: 320px; overflow: auto; }
|
||||
.plan { margin: 0; padding-left: 18px; }
|
||||
.linkbtn { background: none; border: 0; color: var(--ink4); cursor: pointer; padding: 0 4px; margin-left: auto; }
|
||||
.linkbtn:hover { color: var(--ink2); }
|
||||
|
||||
42
app/ui/talk.js
Normal file
42
app/ui/talk.js
Normal file
@@ -0,0 +1,42 @@
|
||||
// Paging of the 대화 screen (app/src/admin.spec.md, "Screens"). Pure, so app/tests/ui checks it.
|
||||
//
|
||||
// The screen keeps a live window, every item from the cursor `from` on (re-read on each tick, at
|
||||
// most PAGE_MAX), and before it the `older` pages kept as loaded. Items are ordered like
|
||||
// history_query: time, then records (`h<id>`) before traces (`t<id>`), then id.
|
||||
|
||||
export const PAGE = 200, PAGE_MAX = 2000;
|
||||
|
||||
export const cursorOf = (i) => ({ at: i.at, key: i.key });
|
||||
|
||||
export function compare(a, b) {
|
||||
return a.at - b.at || (a.key[0] === b.key[0] ? 0 : a.key[0] < b.key[0] ? -1 : 1)
|
||||
|| Number(a.key.slice(1)) - Number(b.key.slice(1));
|
||||
}
|
||||
|
||||
export const empty = () => ({ shown: [], older: [], from: null, hasOlder: false });
|
||||
|
||||
/** A live answer: the items from `from` on (the newest page while there is no `from`), and
|
||||
* whether there were more than it holds. */
|
||||
export function withLive(s, items, more) {
|
||||
let { older, hasOlder } = s;
|
||||
if (!s.from) hasOlder = more;
|
||||
else if (more && items.length) {
|
||||
// More new items than the window holds: the shown ones it no longer reaches join the pages
|
||||
// kept as loaded, so nothing the user had on screen disappears.
|
||||
const seen = new Set(older.map((i) => i.key));
|
||||
older = older.concat(s.shown.filter((i) => compare(i, items[0]) < 0 && !seen.has(i.key)));
|
||||
}
|
||||
return { shown: items, older, hasOlder, from: items.length ? cursorOf(items[0]) : s.from };
|
||||
}
|
||||
|
||||
/** The page before the oldest item loaded: it joins the live window while that stays within
|
||||
* PAGE_MAX, else the older pages. Items already loaded are not added again. */
|
||||
export function withOlder(s, page, more) {
|
||||
const seen = new Set(s.older.concat(s.shown).map((i) => i.key));
|
||||
const fresh = page.filter((i) => !seen.has(i.key));
|
||||
if (!s.older.length && s.shown.length + fresh.length <= PAGE_MAX) {
|
||||
const shown = fresh.concat(s.shown);
|
||||
return { ...s, shown, hasOlder: more, from: shown.length ? cursorOf(shown[0]) : s.from };
|
||||
}
|
||||
return { ...s, older: fresh.concat(s.older), hasOlder: more };
|
||||
}
|
||||
@@ -61,6 +61,7 @@
|
||||
| 화면 보기 | 볼 수 있는 대상(전체 화면, 모니터별, 창별), 캡처 제외 프로그램 목록, 볼 수 있는 조건, 캡처 미리 준비(말하는 중에만/항상/끔), 기본 화질 단계, 화면공유 창 분리 대기 시간, "봇용 크롬창 화면공유 선택 표시" 켜기/끄기 |
|
||||
| 백그라운드 수집 | 수집 대상(사이트, 검색어, RSS), 주기, 보관 기간, 결과 보기. 기본 수집 대상은 비워 둠 |
|
||||
| 데이터 | 폴더별 사용량, 캐시 정리, 데이터 이동, 설정 내보내기/가져오기, 메모리 백업 |
|
||||
| 대화 | 사람이 한 말, 자비스의 답, 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)을 시간순으로 보기. 종류·장소·사람·채널·날짜·글자로 거르기, 실시간 따라가기 |
|
||||
| 로그 | 실시간 로그 보기·검색·복사·다운로드 |
|
||||
| 업데이트 | 새 버전 확인과 설치 (Gitea 릴리스 기준) |
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
- 채팅은 GUI에 등록한 채팅 채널만 읽고 저장합니다. 그 밖의 채널은 읽지 않습니다. 채팅에 올라온 글은 명령이 아니라 데이터로 다룹니다.
|
||||
- 음성 원본은 기본적으로 저장하지 않습니다. 디버그용 저장은 직접 켰을 때만 하고, 기간이 지나면 자동 삭제합니다.
|
||||
- 대화 기록(음성 전사, 채팅 채널 메시지)은 [memory.md](memory.md) 설정대로 저장하고, 사람별로 보고 지울 수 있습니다. 기본으로 참고하는 것은 말한 사람 본인의 기록, 등록한 채팅 채널, 그리고 그 사람과 같은 음성 채널에 함께 있던 동안 다른 사람이 한 말입니다. 다른 사람 말 참고는 GUI에서 끌 수 있습니다.
|
||||
- 자비스가 답을 만든 과정(참고한 기록, 고른 도구, 계획, 도구 호출과 결과, 모델 생각)은 대화 기록 저장소에 함께 남겨 관리 앱 "대화" 화면에서만 봅니다. 로그에는 넣지 않고, 30일이 지나면 지우며, 사람별로 지우면 같이 지웁니다.
|
||||
- 화면 캡처는 자비스가 볼 때만 쓰고 기본적으로 저장하지 않습니다.
|
||||
- 빠른 응답을 위해 미리 잡아 두는 화면도 메모리에 최근 한 장만 두고 계속 덮어씁니다.
|
||||
- 캡처 제외 목록에 넣은 프로그램은 보지 않습니다.
|
||||
|
||||
@@ -4,6 +4,7 @@ registered chat channel messages, searched per asker. Contract:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import math
|
||||
import re
|
||||
import sqlite3
|
||||
@@ -41,6 +42,19 @@ CREATE TABLE IF NOT EXISTS presence (
|
||||
left_at REAL
|
||||
);
|
||||
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
|
||||
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,
|
||||
steps TEXT NOT NULL -- JSON list (history.spec.md, "Traces")
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS traces_ts ON traces(ts);
|
||||
CREATE INDEX IF NOT EXISTS traces_user ON traces(user_id);
|
||||
"""
|
||||
|
||||
_WORD = re.compile(r"\w{2,}", re.UNICODE)
|
||||
@@ -70,6 +84,21 @@ class Record:
|
||||
text: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Trace:
|
||||
"""How one answer was made: never read back into a prompt (``history.spec.md``, "Traces")."""
|
||||
|
||||
id: int
|
||||
ts: float
|
||||
via: str
|
||||
channel_id: Optional[str]
|
||||
user_id: str
|
||||
question: str
|
||||
answer: str
|
||||
ms: int
|
||||
steps: list
|
||||
|
||||
|
||||
@dataclass
|
||||
class HistoryContext:
|
||||
"""Lines for the prompt: the recent window and the search matches, kept apart for labelling."""
|
||||
@@ -196,6 +225,29 @@ 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:
|
||||
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)))
|
||||
self._conn.commit()
|
||||
return int(cur.lastrowid)
|
||||
|
||||
def traces_of(self, person: str) -> List[Trace]:
|
||||
with self._lock:
|
||||
rows = self._conn.execute(
|
||||
"SELECT id, ts, via, channel_id, user_id, question, answer, ms, steps FROM traces"
|
||||
" WHERE user_id=? ORDER BY ts, id", (person,)).fetchall()
|
||||
return [Trace(**{**dict(r), "steps": json.loads(r["steps"])}) for r in rows]
|
||||
|
||||
def purge_traces_older_than(self, ts: float) -> int:
|
||||
with self._lock:
|
||||
n = self._conn.execute("DELETE FROM traces WHERE ts < ?", (ts,)).rowcount
|
||||
self._conn.commit()
|
||||
return n
|
||||
|
||||
def records_of(self, person: str) -> List[Record]:
|
||||
with self._lock:
|
||||
rows = self._conn.execute(
|
||||
@@ -207,6 +259,7 @@ class HistoryStore:
|
||||
with self._lock:
|
||||
n = self._conn.execute("DELETE FROM history WHERE author_id=? OR to_id=?", (person, person)).rowcount
|
||||
self._conn.execute("DELETE FROM presence WHERE user_id=?", (person,))
|
||||
self._conn.execute("DELETE FROM traces WHERE user_id=?", (person,))
|
||||
self._conn.commit()
|
||||
debug_log(f"history: forgot a person ({n} records)", "memory")
|
||||
|
||||
@@ -214,6 +267,7 @@ class HistoryStore:
|
||||
with self._lock:
|
||||
n = self._conn.execute("DELETE FROM history WHERE ts < ?", (ts,)).rowcount
|
||||
self._conn.execute("DELETE FROM presence WHERE left_at IS NOT NULL AND left_at < ?", (ts,))
|
||||
self._conn.execute("DELETE FROM traces WHERE ts < ?", (ts,))
|
||||
self._conn.commit()
|
||||
debug_log(f"history: retention removed {n} records", "memory")
|
||||
|
||||
|
||||
@@ -68,6 +68,30 @@ Setting `since` (default none, meaning the whole history) drops records older th
|
||||
A record that is a match is not repeated in the recent block. Returns the two blocks separately
|
||||
so the prompt can label them.
|
||||
|
||||
## Traces
|
||||
|
||||
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:
|
||||
- `{"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,
|
||||
- `{"kind": "plan", "steps": [...]}`: the planner's steps, when it ran,
|
||||
- `{"kind": "think", "text": "..."}`: the model's thinking in one round, when thinking is on
|
||||
(at most 8,000 characters),
|
||||
- `{"kind": "tool", "name", "args", "ok", "result"}`: a tool call and the start of its result or
|
||||
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).
|
||||
- `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.
|
||||
|
||||
## Writes and maintenance
|
||||
|
||||
- `add_voice`, `add_reply`, `add_chat`, `edit_chat`, `delete_chat`.
|
||||
|
||||
@@ -27,6 +27,7 @@ from .enrichment import (
|
||||
digest_tool_result_for_query,
|
||||
digest_loop_for_max_turns,
|
||||
)
|
||||
from . import turn_state as _turn_state
|
||||
from .prompt_dump import dump_reply_turn, is_enabled as _prompt_dump_enabled, new_session_id
|
||||
from .prompts import ModelSize, detect_model_size, get_system_prompts
|
||||
from .compound_query import split_compound_query
|
||||
@@ -61,6 +62,22 @@ if TYPE_CHECKING:
|
||||
# ── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
# How much of a tool result and of the model's thinking a trace keeps (history.spec.md, "Traces").
|
||||
TRACE_RESULT_CHARS = 2000
|
||||
TRACE_THINKING_CHARS = 8000
|
||||
|
||||
|
||||
def _clip(text: str, limit: int) -> str:
|
||||
return text if len(text) <= limit else text[:limit] + "…"
|
||||
|
||||
|
||||
def _trace_tool(name: str, args, result) -> None:
|
||||
"""One executed tool call in the turn's trace: name, arguments, outcome and the start of its result."""
|
||||
text = result.reply_text or result.error_message or ""
|
||||
_turn_state.trace("tool", name=name, args=args or {}, ok=bool(result.success),
|
||||
result=_clip(str(text), TRACE_RESULT_CHARS))
|
||||
|
||||
|
||||
def _indent_text(text: str, prefix: str = " ") -> str:
|
||||
return f"\n{prefix}".join(text.splitlines())
|
||||
|
||||
@@ -1419,6 +1436,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
routed_tools = [t for t in routed_tools if t != "webSearch"]
|
||||
debug_log("screen-share: site named — dropping webSearch so controlBrowser wins", "tools")
|
||||
|
||||
_turn_state.trace("tools", names=list(routed_tools))
|
||||
_planner_schema = generate_tools_json_schema(routed_tools, mcp_tools)
|
||||
_planner_tool_catalog = planner_tool_catalog(_planner_schema or [])
|
||||
|
||||
@@ -1438,6 +1456,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
debug_log(f"planner step failed (non-fatal): {_plan_exc}", "planning")
|
||||
action_plan = []
|
||||
if action_plan:
|
||||
_turn_state.trace("plan", steps=list(action_plan))
|
||||
_plan_preview = " | ".join(s[:50] for s in action_plan)
|
||||
print(
|
||||
f" 🗺️ Plan: {len(action_plan)} step(s) — {_plan_preview}",
|
||||
@@ -2389,6 +2408,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
max_retries=1,
|
||||
language=language,
|
||||
)
|
||||
_trace_tool(_name, _args, _plan_result)
|
||||
if _plan_result.reply_text:
|
||||
_plan_text = _maybe_digest_tool_result(
|
||||
cfg=cfg,
|
||||
@@ -2602,6 +2622,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
|
||||
# Always show thinking if present, regardless of content
|
||||
if thinking:
|
||||
_turn_state.trace("think", text=_clip(str(thinking), TRACE_THINKING_CHARS))
|
||||
debug_log(f" 💭 LLM thinking: '{thinking[:300]}{'...' if len(thinking) > 300 else ''}'", "planning")
|
||||
|
||||
# Extract tool call if present
|
||||
@@ -2647,6 +2668,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
# Check if tool is not allowed - respond with tool error
|
||||
if tool_name not in allowed_tools:
|
||||
debug_log(f" ⚠️ tool not allowed: {tool_name}", "planning")
|
||||
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="not_allowed")
|
||||
print(f" ⚠️ Tool '{tool_name}' not in allow-list", flush=True)
|
||||
# Use tool response instead of system message to maintain native tool calling compatibility
|
||||
messages.append({
|
||||
@@ -2694,6 +2716,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
|
||||
if signature in recent_tool_signatures:
|
||||
debug_log(f" ⚠️ Duplicate {tool_name} call - returning cached guidance", "planning")
|
||||
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="duplicate")
|
||||
if use_text_tools:
|
||||
messages.append({"role": "user", "content": f"[Tool: {tool_name}] You already called this tool with these arguments. Use the results from the previous tool call to answer the user."})
|
||||
else:
|
||||
@@ -2713,6 +2736,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
)
|
||||
if duplicate_tool_count >= 2:
|
||||
debug_log(f" ⚠️ Too many {tool_name} calls ({duplicate_tool_count}) - returning guidance", "planning")
|
||||
_turn_state.trace("tool", name=tool_name, args=tool_args or {}, ok=False, skipped="duplicate")
|
||||
if use_text_tools:
|
||||
messages.append({"role": "user", "content": f"[Tool: {tool_name}] You have already called this tool {duplicate_tool_count} times. Use the results from those calls to answer the user's question."})
|
||||
else:
|
||||
@@ -2731,6 +2755,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
|
||||
max_retries=1,
|
||||
language=language,
|
||||
)
|
||||
_trace_tool(tool_name, tool_args, result)
|
||||
|
||||
# Handle stop tool - end conversation without response
|
||||
if result.reply_text == STOP_SIGNAL:
|
||||
|
||||
@@ -31,6 +31,9 @@ notes : Optional[object]
|
||||
screen : Optional[object]
|
||||
v2: the app's screen backend for the asker (screen_view.spec.md). None means the screenView
|
||||
tool is not offered.
|
||||
trace : Optional[list]
|
||||
v2: where the engine writes down how it made this answer (history.spec.md, "Traces"): the
|
||||
tools it was given, the plan, the model's thinking and each tool call. None records nothing.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -50,6 +53,22 @@ def reset() -> None:
|
||||
_state.schedule = None
|
||||
_state.notes = None
|
||||
_state.screen = None
|
||||
_state.trace = None
|
||||
|
||||
|
||||
def set_trace(steps: Optional[list]) -> None:
|
||||
_state.trace = steps
|
||||
|
||||
|
||||
def get_trace() -> Optional[list]:
|
||||
return getattr(_state, "trace", None)
|
||||
|
||||
|
||||
def trace(kind: str, **data) -> None:
|
||||
"""Add one step to this turn's trace, if one is kept."""
|
||||
steps = get_trace()
|
||||
if steps is not None:
|
||||
steps.append({"kind": kind, **data})
|
||||
|
||||
|
||||
def set_screen(backend) -> None:
|
||||
|
||||
@@ -19,7 +19,7 @@ from jarvis.memory.history import HistoryContext, Scope
|
||||
class Brain(Protocol):
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
|
||||
task: bool = False, notes: Optional[list] = None, notes_backend=None,
|
||||
screen=None) -> Optional[str]:
|
||||
screen=None, trace: Optional[list] = None) -> Optional[str]:
|
||||
"""Blocking; called on a worker thread, one call per person at a time (a voice and a chat
|
||||
reply for different people may overlap). ``chat``: the chat backend for
|
||||
the chatChannels tool (voice_worker/chat_bridge.py), or None without registered channels.
|
||||
@@ -27,7 +27,8 @@ class Brain(Protocol):
|
||||
``task``: a scheduled task runs, with the read-only tools only (``TASK_TOOLS``).
|
||||
``notes``: the asker's standing instructions, put in the prompt; ``notes_backend``: the
|
||||
backend for the personalNotes tool (personal_notes.spec.md); ``screen``: the backend for the
|
||||
screenView tool (screen_view.spec.md)."""
|
||||
screenView tool (screen_view.spec.md); ``trace``: a list the engine adds the steps of
|
||||
this answer to (history.spec.md, "Traces")."""
|
||||
|
||||
def addressed(self, user: str, text: str, names: list[str]) -> Optional[bool]:
|
||||
"""Blocking: was ``text`` said to the assistant (called ``names``)? None when it could not tell.
|
||||
@@ -296,7 +297,7 @@ class JarvisBrain:
|
||||
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
|
||||
task: bool = False, notes: Optional[list] = None, notes_backend=None,
|
||||
screen=None) -> Optional[str]:
|
||||
screen=None, trace: Optional[list] = None) -> Optional[str]:
|
||||
from jarvis.memory.conversation import DialogueMemory
|
||||
from jarvis.reply import turn_state
|
||||
from jarvis.reply.engine import run_reply_engine
|
||||
@@ -317,6 +318,7 @@ class JarvisBrain:
|
||||
turn_state.set_schedule(None if task else schedule)
|
||||
turn_state.set_notes(None if task else notes_backend)
|
||||
turn_state.set_screen(None if task else screen)
|
||||
turn_state.set_trace(trace)
|
||||
try:
|
||||
return run_reply_engine(self.db, cfg, None, text, memory,
|
||||
language=self.language, history=history, legacy_memory=False,
|
||||
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
Stand-alone on purpose: it must not import the worker package, which lives in another venv.
|
||||
|
||||
stdin: one JSON request per line: {"text": "...", "rate": 48000}
|
||||
stdin: one JSON request per line: {"text": "...", "rate": 48000, "speed": 1.5} (speed optional,
|
||||
default --speed)
|
||||
stdout: frames of u32 LE header length | header JSON | payload. The first frame is
|
||||
{"ready": true, "rate": <native rate>}; each reply is {"ok": true, "samples": N} followed by N
|
||||
int16 LE mono samples at the requested rate, or {"ok": false, "error": "..."} with no payload.
|
||||
Library output that would land on stdout is sent to stderr so it cannot corrupt the frames.
|
||||
|
||||
Speed: MeloTTS's own speed past about 1.25 drops sounds (five Korean sentences, three renders each,
|
||||
read back by Whisper large-v3: at 1.5 sentence-final "요" and first syllables went missing, 4.6%
|
||||
character errors, 9.6% at 1.75, against 1.2% at 1.0 and none added at 1.25). A time stretch that keeps
|
||||
the pitch (WSOLA) keeps every sound but sounds less natural the more it stretches (UTMOS 3.13 at 1.5
|
||||
stretched from 1.0, against 3.73 for the model's own 1.5). So the model speaks up to MODEL_SPEED_MAX
|
||||
and the stretch does only the rest: 2.6% and UTMOS 3.56 at 1.5, 1.9% and 3.09 at 1.75 (through this
|
||||
child). A 5 ms search scored higher than 10 ms (UTMOS 3.42 against 3.27 for a 1.2 stretch).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -19,6 +28,42 @@ import struct
|
||||
import sys
|
||||
import types
|
||||
|
||||
MODEL_SPEED_MAX = 1.25
|
||||
|
||||
|
||||
def split_speed(speed: float) -> tuple[float, float]:
|
||||
"""(the model's speed, the stretch factor after it); their product is ``speed``."""
|
||||
model = min(speed, MODEL_SPEED_MAX)
|
||||
return model, speed / model
|
||||
|
||||
|
||||
def stretch(audio, factor: float, rate: int, frame_ms: float = 30.0, search_ms: float = 5.0):
|
||||
"""Shorten ``audio`` by ``factor`` and keep its pitch (WSOLA): half-overlapping Hann frames are
|
||||
taken ``factor`` times further apart than they are laid down, each shifted within ``search_ms``
|
||||
to where it best continues the frame before it, so the pieces join without dips or clicks."""
|
||||
import numpy as np
|
||||
|
||||
x = np.asarray(audio, dtype=np.float64)
|
||||
if abs(factor - 1.0) < 1e-3 or len(x) == 0:
|
||||
return x
|
||||
n = int(rate * frame_ms / 1000) // 2 * 2
|
||||
hop = n // 2
|
||||
tol = int(rate * search_ms / 1000)
|
||||
win = 0.5 - 0.5 * np.cos(2 * np.pi * np.arange(n) / n) # its half-overlapped copies sum to 1
|
||||
n_out = int(np.ceil(len(x) / factor))
|
||||
frames = n_out // hop + 2
|
||||
xp = np.pad(x, (tol, int(frames * hop * factor) + 2 * n + 2 * tol))
|
||||
y = np.zeros(frames * hop + n)
|
||||
prev = None
|
||||
for k in range(frames):
|
||||
pos = int(round(k * hop * factor)) + tol
|
||||
if prev is not None:
|
||||
natural = xp[prev + hop: prev + hop + n]
|
||||
pos += int(np.argmax(np.correlate(xp[pos - tol: pos + tol + n], natural, mode="valid"))) - tol
|
||||
y[k * hop: k * hop + n] += xp[pos: pos + n] * win
|
||||
prev = pos
|
||||
return y[:n_out]
|
||||
|
||||
|
||||
def korean_only_patches() -> None:
|
||||
"""MeloTTS imports its Japanese front end (module-level MeCab.Tagger()) even for Korean, and on
|
||||
@@ -76,7 +121,7 @@ def main() -> int:
|
||||
spk_map = model.hps.data.spk2id
|
||||
speaker = spk_map[args.language] if args.language in spk_map else spk_map[list(spk_map.keys())[0]]
|
||||
native = int(model.hps.data.sampling_rate)
|
||||
model.tts_to_file("워밍업입니다.", speaker, None, speed=args.speed, quiet=True)
|
||||
model.tts_to_file("워밍업입니다.", speaker, None, speed=split_speed(args.speed)[0], quiet=True)
|
||||
except Exception as e:
|
||||
reply({"ready": False, "error": f"{type(e).__name__}: {e}"})
|
||||
return 1
|
||||
@@ -86,8 +131,9 @@ def main() -> int:
|
||||
try:
|
||||
req = json.loads(line)
|
||||
rate = int(req["rate"])
|
||||
audio = model.tts_to_file(str(req["text"]), speaker, None, speed=args.speed, quiet=True)
|
||||
audio = np.asarray(audio, dtype=np.float64)
|
||||
model_speed, factor = split_speed(float(req.get("speed", args.speed)))
|
||||
audio = model.tts_to_file(str(req["text"]), speaker, None, speed=model_speed, quiet=True)
|
||||
audio = stretch(audio, factor, native)
|
||||
if rate != native:
|
||||
from math import gcd
|
||||
g = gcd(rate, native)
|
||||
|
||||
@@ -51,6 +51,8 @@ class _LlmPaused(Exception):
|
||||
# The asker's standing instructions the app sends with a reply (personal_notes.spec.md).
|
||||
MAX_NOTES = 20
|
||||
MAX_NOTE_CHARS = 300
|
||||
# How long answer traces stay (history.spec.md, "Traces"); removed when the worker starts.
|
||||
TRACE_KEEP_DAYS = 30
|
||||
|
||||
|
||||
class VoiceWorker:
|
||||
@@ -116,6 +118,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.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")
|
||||
if self.transcriber is not None:
|
||||
self.scheduler = SttScheduler(self.transcriber, partials_held=self._partials_held)
|
||||
self.scheduler.start()
|
||||
@@ -346,6 +351,7 @@ class Session:
|
||||
kind = msg.get("type")
|
||||
handler = {"speaking_end": self._on_speaking_end, "speaker_leave": self._on_speaker_leave,
|
||||
"config": self._on_config, "tts": self._on_tts, "tts_cancel": self._on_tts_cancel,
|
||||
"tts_speed": self._on_tts_speed,
|
||||
"voice_join": self._on_voice_join, "voice_leave": lambda m: self._leave_voice(),
|
||||
"member_join": self._on_member_join, "member_leave": self._on_member_leave,
|
||||
"chat_message": self._on_chat_message, "chat_edit": self._on_chat_edit,
|
||||
@@ -388,6 +394,15 @@ class Session:
|
||||
self.worker.scheduler.drop_partials(lambda key: key[0] == self.sid)
|
||||
debug_log(f"session {self.sid} settings changed: {sorted(changes)}", "voice_worker")
|
||||
|
||||
def _on_tts_speed(self, msg: dict) -> None:
|
||||
speed = msg.get("speed")
|
||||
if isinstance(speed, bool) or not isinstance(speed, (int, float)) or not 0.5 <= speed <= 2.0:
|
||||
self.error("bad_message", "tts_speed needs a speed from 0.5 to 2.0")
|
||||
return
|
||||
if self.worker.tts_engine is not None:
|
||||
self.worker.tts_engine.speed = float(speed)
|
||||
debug_log(f"tts speed {speed}", "tts")
|
||||
|
||||
def _on_tts(self, msg: dict) -> None:
|
||||
rid, text, more = msg.get("id"), msg.get("text", ""), msg.get("more", False)
|
||||
if not isinstance(rid, str) or not 0 < len(rid.encode()) < 256 or not isinstance(text, str) \
|
||||
@@ -593,6 +608,23 @@ class Session:
|
||||
waiting[user] = waiting.get(user, 0) + 1
|
||||
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:
|
||||
"""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")
|
||||
|
||||
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
|
||||
@@ -612,12 +644,14 @@ class Session:
|
||||
from jarvis.memory.history import HistoryContext
|
||||
history = HistoryContext()
|
||||
try:
|
||||
steps = self._trace_start(history, notes)
|
||||
async with self._llm():
|
||||
answer = await asyncio.to_thread(w.brain.reply, user, text, history, task=True,
|
||||
notes=notes or [])
|
||||
notes=notes or [], trace=steps)
|
||||
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()
|
||||
answer = (answer or "").strip()
|
||||
self._trace_end("task", None, user, text, answer, steps, now)
|
||||
self.send({"type": "reply_text", "id": rid, "text": answer, "failed": not answer})
|
||||
|
||||
def _on_llm(self, msg: dict) -> None:
|
||||
@@ -824,13 +858,15 @@ 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)
|
||||
try:
|
||||
async with self._llm(rid if speak else None):
|
||||
w.answering += 1
|
||||
try:
|
||||
answer = await asyncio.to_thread(w.brain.reply, user, text, history, chat=chat,
|
||||
schedule=schedule, notes=notes or [],
|
||||
notes_backend=notes_backend, screen=screen)
|
||||
notes_backend=notes_backend, screen=screen,
|
||||
trace=steps)
|
||||
finally:
|
||||
w.answering -= 1
|
||||
if not w.answering and w.scheduler:
|
||||
@@ -838,7 +874,8 @@ class Session:
|
||||
except Exception as e: # the brain must never take the session down
|
||||
debug_log(f"brain reply {rid} failed: {type(e).__name__}", "llm")
|
||||
answer = None
|
||||
answer = (answer or "").strip()
|
||||
answer = (answer or "").strip()
|
||||
self._trace_end(via, channel if via == "voice" else chat_channel, user, text, answer, steps, now)
|
||||
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})
|
||||
|
||||
@@ -19,6 +19,8 @@ CHILD = os.path.join(os.path.dirname(os.path.abspath(__file__)), "melo_child.py"
|
||||
class MeloEngine:
|
||||
def __init__(self, python: str, device: str = "cuda", speed: float = 1.5, language: str = "KR"):
|
||||
self.cmd = [python, CHILD, "--device", device, "--speed", str(speed), "--language", language]
|
||||
# Read for each sentence, so a new speed (`tts_speed`) applies from the next one.
|
||||
self.speed = speed
|
||||
self._lock = threading.Lock()
|
||||
self._proc: subprocess.Popen | None = None
|
||||
self.native_rate: int | None = None
|
||||
@@ -49,7 +51,7 @@ class MeloEngine:
|
||||
if self._proc is None or self._proc.poll() is not None:
|
||||
debug_log("melo child not running, restarting", "tts")
|
||||
self._start()
|
||||
self._proc.stdin.write((json.dumps({"text": text, "rate": rate}) + "\n").encode())
|
||||
self._proc.stdin.write((json.dumps({"text": text, "rate": rate, "speed": self.speed}) + "\n").encode())
|
||||
self._proc.stdin.flush()
|
||||
header, payload = self._read()
|
||||
if not header.get("ok"):
|
||||
|
||||
@@ -164,6 +164,7 @@ line (-0.6) would lose more real words than it saves.
|
||||
```
|
||||
-> {"type": "tts", "id": "r1", "text": "...", "more": false} // more=true: more text follows for r1
|
||||
-> {"type": "tts_cancel", "id": "r1"}
|
||||
-> {"type": "tts_speed", "speed": 1.8} // 0.5-2.0, from the next sentence on
|
||||
<- binary 0x02 | u8 n | id (n bytes UTF-8) | u32 LE seq | PCM16LE in the hello "tts" format
|
||||
<- {"type": "tts_done", "id": "r1", "chunks": 3, "cancelled": false, "failed": false}
|
||||
```
|
||||
@@ -178,6 +179,17 @@ is ready. Requests are served first come, first served by one TTS engine. `tts_c
|
||||
request's unsent sentences, and `tts_done` follows with `cancelled: true`. A sentence that fails to
|
||||
synthesise is reported with `error` (`code: "tts_failed"`) and the request ends with `failed: true`.
|
||||
|
||||
Speed starts at `--melo-speed` and `tts_speed` changes it for every sentence made after it (a speed
|
||||
outside 0.5-2.0 or not a number is `bad_message` and the last good one stays). MeloTTS itself speaks
|
||||
up to 1.25: its own speed shortens every sound, and past that it drops them (five Korean sentences,
|
||||
three renders each, read back by Whisper large-v3: at 1.5 sentence-final "요" and first syllables went
|
||||
missing, 4.6% character errors, 9.6% at 1.75, against 1.2% at 1.0). Faster speech is made at 1.25 and
|
||||
shortened with WSOLA, a time stretch that keeps the pitch (30 ms half-overlapping Hann frames, each
|
||||
shifted within 5 ms to where it best continues the one before): 2.6% at 1.5 and 1.9% at 1.75. The
|
||||
stretch costs naturalness the more it does (UTMOS at 1.5: 3.56, against 3.13 when all of it is
|
||||
stretched from 1.0), so it does only the part the model cannot; up to 1.25 nothing is stretched. About 15 ms per 4 s
|
||||
of speech.
|
||||
|
||||
### History and brain (M3)
|
||||
|
||||
The worker also hosts the brain (the existing `jarvis` reply engine) and the conversation history
|
||||
@@ -234,7 +246,10 @@ which carry Discord's own time.
|
||||
`speak: true` the answer is also spoken through the TTS path under the same id (audio frames and
|
||||
`tts_done`), and `tts_cancel` with that id stops it. A `tts_cancel` that arrives while the brain is
|
||||
still answering means the answer is not spoken: `reply_text` still comes, then `tts_done` with
|
||||
`cancelled: true` and no audio. Each user keeps their own short-term dialogue
|
||||
`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
|
||||
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
|
||||
|
||||
59
tests/test_engine_trace.py
Normal file
59
tests/test_engine_trace.py
Normal file
@@ -0,0 +1,59 @@
|
||||
"""The reply engine writes down how it made an answer (history.spec.md, "Traces").
|
||||
|
||||
With a trace list set on the turn state, a reply records the tools it was given, the plan, the
|
||||
model's thinking and each tool call with its outcome. Without one nothing is recorded.
|
||||
"""
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from src.jarvis.memory.conversation import DialogueMemory
|
||||
from src.jarvis.reply import turn_state
|
||||
from src.jarvis.reply.engine import run_reply_engine
|
||||
|
||||
from tests.test_engine_tool_carryover import _mock_cfg
|
||||
|
||||
|
||||
def _run(trace):
|
||||
tool = Mock(reply_text="서울: 맑음, 12도", error_message=None, success=True)
|
||||
replies = [
|
||||
{"message": {"content": "", "thinking": "날씨를 찾아봐야겠다", "tool_calls": [{
|
||||
"id": "c1", "type": "function",
|
||||
"function": {"name": "webSearch", "arguments": {"query": "서울 날씨"}}}]}},
|
||||
{"message": {"content": "서울은 맑고 12도입니다."}},
|
||||
]
|
||||
turn_state.reset()
|
||||
turn_state.set_trace(trace)
|
||||
try:
|
||||
with patch("src.jarvis.reply.engine.plan_query", return_value=["Search the web", "Reply to the user."]), \
|
||||
patch("src.jarvis.reply.engine.extract_search_params_for_memory", return_value={}), \
|
||||
patch("src.jarvis.reply.engine.run_tool_with_retries", return_value=tool), \
|
||||
patch("src.jarvis.reply.engine.extract_text_from_response",
|
||||
side_effect=lambda r: r["message"]["content"]), \
|
||||
patch("src.jarvis.reply.engine.chat_with_messages", side_effect=replies):
|
||||
return run_reply_engine(db=Mock(), cfg=_mock_cfg(), tts=None, text="서울 날씨 어때",
|
||||
dialogue_memory=DialogueMemory())
|
||||
finally:
|
||||
turn_state.reset()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_reply_records_its_tools_plan_thinking_and_tool_calls():
|
||||
trace = []
|
||||
assert _run(trace)
|
||||
kinds = [s["kind"] for s in trace]
|
||||
assert kinds.index("tools") < kinds.index("plan") < kinds.index("think") < kinds.index("tool")
|
||||
tools = next(s for s in trace if s["kind"] == "tools")
|
||||
assert "webSearch" in tools["names"]
|
||||
assert next(s for s in trace if s["kind"] == "plan")["steps"] == ["Search the web", "Reply to the user."]
|
||||
assert next(s for s in trace if s["kind"] == "think")["text"] == "날씨를 찾아봐야겠다"
|
||||
call = next(s for s in trace if s["kind"] == "tool")
|
||||
assert (call["name"], call["args"], call["ok"], call["result"]) == \
|
||||
("webSearch", {"query": "서울 날씨"}, True, "서울: 맑음, 12도")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_without_a_trace_nothing_is_recorded():
|
||||
assert _run(None)
|
||||
assert turn_state.get_trace() is None
|
||||
@@ -238,3 +238,26 @@ def test_chat_tool_reads_and_searches_one_channels_messages(store):
|
||||
assert sorted(texts(store.search_chat(["c1", "c2"], "회의"))) == ["회의 취소", "회의는 3시"]
|
||||
assert store.search_chat([], "회의") == []
|
||||
assert store.chat_channel_of("m3") == "c2" and store.chat_channel_of("nope") is None
|
||||
|
||||
|
||||
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)
|
||||
[t] = store.traces_of("a")
|
||||
assert (t.via, t.channel_id, t.question, t.answer, t.ms, t.steps) == ("voice", VC, "서울 날씨 어때", "맑습니다", 1200, steps)
|
||||
# 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()) == []
|
||||
store.forget_person("a")
|
||||
assert store.traces_of("a") == [] and len(store.traces_of("b")) == 1
|
||||
|
||||
|
||||
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.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") == []
|
||||
|
||||
@@ -29,8 +29,10 @@ class FakeBrain:
|
||||
self.calls = []
|
||||
|
||||
def reply(self, user, text, history, chat=None, schedule=None, task=False, notes=None, notes_backend=None,
|
||||
screen=None):
|
||||
screen=None, trace=None):
|
||||
self.calls.append((user, text, history))
|
||||
if trace is not None:
|
||||
trace.append({"kind": "tools", "names": ["getWeather"]})
|
||||
self.chat, self.schedule, self.task = chat, schedule, task
|
||||
self.notes, self.notes_backend, self.screen = notes, notes_backend, screen
|
||||
return self.answer(user, text)
|
||||
@@ -211,6 +213,37 @@ def test_a_failed_brain_answer_is_reported(store, answer):
|
||||
assert seen[-1] == {"type": "reply_text", "id": "r1", "text": "", "failed": True}
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_each_answer_keeps_how_it_was_made_with_the_records_it_was_given(store):
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws, stt={"partials": False})
|
||||
await send(ws, type="voice_join", channel="vc1")
|
||||
await send(ws, type="member_join", user="100", name="Alice")
|
||||
await say(ws, "100", 0.9)
|
||||
await send(ws, type="reply", id="r1", user="100", text="what did I say", via="voice", speak=False,
|
||||
notes=["반말로 해"])
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "r1")
|
||||
await send(ws, type="reply", id="c1", user="100", text="hi", via="chat", speak=False, channel="ch1")
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "c1")
|
||||
await send(ws, type="reply", id="t1", user="100", text="task", via="task")
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("id") == "t1")
|
||||
|
||||
brain = FakeBrain(lambda u, t: None if t == "hi" else f"answer for {t}")
|
||||
asyncio.run(with_worker(body, store=store, brain=brain))
|
||||
voice, chat, task = store.traces_of("100")
|
||||
assert (voice.via, voice.channel_id, voice.question, voice.answer) == \
|
||||
("voice", "vc1", "what did I say", "answer for what did I say")
|
||||
assert voice.ms >= 0
|
||||
records = voice.steps[0]
|
||||
assert records["kind"] == "records" and records["notes"] == 1
|
||||
assert any("Alice: level 0.9" in x for x in records["recent"])
|
||||
assert voice.steps[1:] == [{"kind": "tools", "names": ["getWeather"]}]
|
||||
# A failed answer is kept too, with no answer; a task has no channel.
|
||||
assert (chat.via, chat.channel_id, chat.answer) == ("chat", "ch1", "")
|
||||
assert (task.via, task.channel_id, task.answer) == ("task", None, "answer for task")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_without_a_brain_reply_is_an_error():
|
||||
async def body(url):
|
||||
@@ -300,6 +333,21 @@ def test_presence_left_open_by_a_previous_run_is_closed_at_start(store):
|
||||
assert store.recent("old", now=4_000_000_000, scope=Scope(), minutes=10 ** 9) == []
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
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)
|
||||
|
||||
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"]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_brain_prints_no_text_from_its_thread(tmp_path, monkeypatch, capfd):
|
||||
pytest.importorskip("mcp") # the real brain needs the jarvis dependencies (--brain)
|
||||
|
||||
89
tests/test_voice_worker_melo_speed.py
Normal file
89
tests/test_voice_worker_melo_speed.py
Normal file
@@ -0,0 +1,89 @@
|
||||
"""How the MeloTTS child speeds speech up: the model never speaks faster than MODEL_SPEED_MAX (faster
|
||||
drops sounds), and the rest is a time stretch that keeps the pitch. And the engine sends its current speed
|
||||
with every sentence."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from voice_worker import melo_child, tts_melo
|
||||
from voice_worker.melo_child import MODEL_SPEED_MAX, split_speed, stretch
|
||||
|
||||
SR = 44100
|
||||
|
||||
|
||||
def sine(hz: float, seconds: float) -> np.ndarray:
|
||||
return np.sin(2 * np.pi * hz * np.arange(int(SR * seconds)) / SR)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_model_never_speaks_faster_than_its_limit_and_the_stretch_does_the_rest():
|
||||
for speed in (0.5, 0.8, MODEL_SPEED_MAX):
|
||||
assert split_speed(speed) == (speed, 1.0)
|
||||
for speed in (1.5, 1.75, 2.0):
|
||||
model, factor = split_speed(speed)
|
||||
assert model == MODEL_SPEED_MAX and factor > 1.0
|
||||
assert model * factor == pytest.approx(speed)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_stretch_shortens_by_the_factor_and_keeps_the_pitch():
|
||||
x = sine(220.0, 2.0)
|
||||
for factor in (1.2, 1.6, 2.0):
|
||||
y = stretch(x, factor, SR)
|
||||
assert len(y) == pytest.approx(len(x) / factor, abs=2)
|
||||
spectrum = np.abs(np.fft.rfft(y * np.hanning(len(y))))
|
||||
assert np.argmax(spectrum) * SR / len(y) == pytest.approx(220.0, abs=2.0)
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_stretched_sound_stays_even_without_dips_or_clicks():
|
||||
# Badly joined pieces cancel each other (the level dips) or jump (clicks).
|
||||
x = 0.5 * sine(180.0, 1.5)
|
||||
y = stretch(x, 1.6, SR)
|
||||
middle = y[SR // 10: -SR // 10]
|
||||
frame = SR // 100
|
||||
levels = [np.sqrt(np.mean(middle[i:i + frame] ** 2)) for i in range(0, len(middle) - frame, frame)]
|
||||
assert min(levels) > 0.5 / np.sqrt(2) * 0.9 and max(levels) < 0.5 / np.sqrt(2) * 1.1
|
||||
assert np.max(np.abs(np.diff(middle))) < 2 * np.pi * 180.0 / SR * 0.5 * 1.5
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_no_stretch_leaves_the_sound_as_it_is():
|
||||
x = sine(300.0, 0.5)
|
||||
assert np.array_equal(stretch(x, 1.0, SR), x)
|
||||
assert len(stretch(np.zeros(0), 1.5, SR)) == 0
|
||||
|
||||
|
||||
FAKE_CHILD = textwrap.dedent("""
|
||||
import json, struct, sys
|
||||
out = sys.stdout.buffer
|
||||
def reply(h, payload=b""):
|
||||
raw = json.dumps(h).encode()
|
||||
out.write(struct.pack("<I", len(raw)) + raw + payload); out.flush()
|
||||
reply({"ready": True, "rate": 44100})
|
||||
for line in sys.stdin:
|
||||
req = json.loads(line)
|
||||
n = int(req["speed"] * 100)
|
||||
reply({"ok": True, "samples": n}, b"\\x00\\x00" * n)
|
||||
""")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_engine_sends_its_current_speed_with_every_sentence(tmp_path, monkeypatch):
|
||||
child = tmp_path / "fake_child.py"
|
||||
child.write_text(FAKE_CHILD)
|
||||
monkeypatch.setattr(tts_melo, "CHILD", str(child))
|
||||
engine = tts_melo.MeloEngine(sys.executable, "cpu", 1.5)
|
||||
try:
|
||||
assert len(engine.synthesize("하나", 48000)) == 150
|
||||
engine.speed = 1.8
|
||||
assert len(engine.synthesize("둘", 48000)) == 180
|
||||
finally:
|
||||
engine.close()
|
||||
@@ -43,6 +43,8 @@ class FakeTts:
|
||||
def __init__(self, delay: float = 0.0):
|
||||
self.delay = delay
|
||||
self.texts = []
|
||||
self.speed = 1.5
|
||||
self.speeds = []
|
||||
|
||||
def synthesize(self, text, rate):
|
||||
if self.delay:
|
||||
@@ -50,6 +52,7 @@ class FakeTts:
|
||||
if "FAIL" in text:
|
||||
raise RuntimeError("engine broke")
|
||||
self.texts.append(text)
|
||||
self.speeds.append(self.speed)
|
||||
return np.full(len(text) * 10, 1000, dtype=np.int16)
|
||||
|
||||
|
||||
@@ -272,6 +275,29 @@ def test_a_failing_sentence_ends_the_request_as_failed():
|
||||
assert tts.texts == ["첫 문장입니다."]
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_a_new_speech_speed_applies_to_the_sentences_made_after_it():
|
||||
tts = FakeTts()
|
||||
|
||||
async def body(url):
|
||||
async with connect(url) as ws:
|
||||
await hello(ws)
|
||||
await ws.send(json.dumps({"type": "tts", "id": "a", "text": "보통 속도 문장이에요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
await ws.send(json.dumps({"type": "tts_speed", "speed": 1.8}))
|
||||
out = []
|
||||
for bad in (2.5, 0.2, "fast", True):
|
||||
await ws.send(json.dumps({"type": "tts_speed", "speed": bad}))
|
||||
out.append(json.loads(await ws.recv()))
|
||||
await ws.send(json.dumps({"type": "tts", "id": "b", "text": "빨라진 문장이에요."}))
|
||||
await recv_until(ws, lambda m: isinstance(m, dict) and m.get("type") == "tts_done")
|
||||
return out
|
||||
|
||||
errors = asyncio.run(with_worker(body, tts=tts))
|
||||
assert [e["code"] for e in errors] == ["bad_message"] * 4
|
||||
assert tts.speeds == [1.5, 1.8], "a refused speed leaves the last good one"
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_tts_without_an_engine_reports_unavailable():
|
||||
async def body(url):
|
||||
|
||||
Reference in New Issue
Block a user