Dan-EL
Glitr can run a small language model and text-to-image models on the device. After the weights are downloaded, chat turns and image prompts stay in-process — they are not sent to a remote LLM API. Dan-EL is not part of the git mailbox, the recipient crypto cascade, or the live WebRTC path.
Beyond free-form chat, the product hosts an in-app agent: it retrieves Glitr docs (BM25 over a published index), proposes allowlisted UI actions for confirmation, and can run guided journeys (pair with a peer, attach a remote, load a model, and similar). The user how-to is In-app Dan-EL assistant. Chrome details are on UI/UX.
This page is the ai sibling library and how whatsup hosts it. Session, poll, and send stay on Network. How the shell sits on the rest of the stack is the Architecture product map.
The product path is closed-source. The ai gallery is the public surface you can press: positive-intentions.github.io/ai.
Product wiring
whatsup links the engines as path Cargo crates from the sibling ai repo:
| Target | Crate | When |
|---|---|---|
| Browser (wasm) | ai-web | Always for wasm32 |
| Desktop GUI | ai-core | Cargo feature desktop |
whatsup-ui has no dependency on ai. It owns the Dan-EL chrome and domain scaffolding (ChatKind::LocalAi, synthetic contact ids, load/manage dialogs, markdown assistant bubbles, floating assistant popover, guide/nudge cards). whatsup is the host that calls into ai-web or ai-core, runs the agent/guide loop, and pushes tokens or image data URLs into AppState.
| Host module | Role |
|---|---|
ai_gui.rs | Browser: WebLLM chat + ORT image over WebGPU; assistant popover; agent turns |
ai_native.rs | Desktop: Candle GGUF chat + Candle Stable Diffusion; assistant popover; agent turns |
agent_host.rs | Snapshot, BM25 retrieve, parse reply, execute confirmed actions |
guide_host.rs | GuideFacts, GuideRunner, journey auto-ops, nudge prefs |
gui.rs | provide_ai_ctx(), GuideCtx, route /ai, speed dial, overlays |
The Dan-EL thread uses fixed ids (AI_CHAT_ID, AI_CONTACT_ID). It is shared by the full-bleed /ai route and the top-right floating assistant. It is hidden from the main chat list, excluded from mailbox snapshots, and skipped on the TUI live-send path. Image prompts are detected with parse_image_intent (/image …, “draw me …”, and similar phrases); the host unloads chat VRAM when needed, runs the image session, and attaches a PNG data URL in the thread.
Platform availability: desktop and browser GUI builds (including the agent and guided journeys). Mobile-without-desktop and TUI show a stub (“available in desktop and browser builds”). UI details: UI/UX.
Inference after load is local. First-time model download still uses the network (Hugging Face, MLC, CDNs). Refreshing the docs index uses https://glitr.io/ai-index.json. That is not the same as a cloud assistant.
In-app agent
Each user turn in the Dan-EL thread is an agent turn, not a bare completion against an empty system prompt.
- Snapshot —
AppContextSnapshotfrom live app state (route, platform, connection/Tor status, loaded model, contacts/chats summaries, recent messages from an open thread). The host decides how much to include; the product path includes message text for guidance. - Retrieve — BM25 over the resolved docs index (fetched
ai-index.jsonmerged with a built-in app map). Prefer user-audience chunks for ordinary questions. - Budget —
TurnBudget/build_turn(orbuild_turn_with_guidewhen a journey is active) packs base system prompt, action protocol, optional active-guide block, context, docs snippets, and trimmed history into the model window. - Generate — WebLLM or Candle streams the assistant reply into
AI_CHAT_ID. - Parse — strip
<action>{json}</action>tags; resolve[n]citations against this turn’s hits; attachPendingActioncards that require Confirm before the host runs anything. - Keyword fallback — if the model emits no action,
suggest_journeymay still offer astart_journeyconfirm from the user’s wording.
Allowlisted action types include navigate, open_doc, set_theme, clear_ai_chat, open_model_picker, check_for_updates, start_journey, stop_journey, and open_chat. Unknown types are ignored.
Docs index (BM25)
The public site builds ai-index.json (and llms.txt) in a Docusaurus postBuild plugin under glitr-website/plugins/ai-index. It walks docs/ and blog/, strips MDX chrome, and chunks at ## / ### headings. Audience is user, technical, or blog from the path.
| Concern | Behavior |
|---|---|
| URL | https://glitr.io/ai-index.json (CORS headers from the site CDN stack) |
| Browser cache | Cache Storage via ai-web index store |
| Native cache | Disk cache via ai-core DiskIndexStore |
| Offline | If fetch fails, fall back to the built-in app map only |
| App map | Hand-written route/settings chunks in ai-core agent/app_map.rs (always merged when an index loads) |
Deterministic guided steps do not need BM25 (next_step reads GuideFacts). BM25 matters for free-text Q&A and for citing docs while a journey is active.
Guided journeys
Journeys are a hybrid design: a pure state machine in ai-core (agent/guide.rs) picks the next step from live facts; the LLM explains the step and may propose start_journey. After one confirmation (action card or nudge “Guide me”), the host runs auto_ops until the journey is done or the user stops. Typing codes, credentials, and sending messages stay with the user (awaiting_user); the assistant popover opens when the user must act.
| Id | Title | Primary doc | Rough machine |
|---|---|---|---|
pair_live | Pair with a peer | Talk now | Navigate/open Add contact (Pair) → mint invite → share/paste (awaiting_user) → connecting → live |
git_contact | Add a git contact | Add a contact | Open Add contact (Git) → fill URL (awaiting_user) → done when a peer contact exists |
connect_remote | Connect a mailbox remote | Connect repository | Navigate Settings → Sync → attach remote (awaiting_user) |
first_message | Send your first message | First conversation | Need a peer → open their chat → compose/send (awaiting_user) |
pair_device | Pair another device | Another device | Navigate Devices → show/scan code (awaiting_user) |
troubleshoot | Troubleshoot connection | Troubleshooting | Decision tree: no mailbox → Tor fail → pair failed → pending peer → delivery fail → stall |
ai_setup | Set up Dan-EL | Install | Open Dan-EL / model picker → wait until a model is loaded |
Proactive nudges (first run, pairing stalled/failed, peer offline, failed delivery, AI open with no model) show as badge/cards on the floating assistant. Dismissed nudge ids and onboarding_done persist under glitr:guide.
GuideOp values the host can auto-run: Navigate, OpenAddContact, StartPairInvite, OpenChat, OpenDevicePair, OpenAttachRemote, OpenModelPicker, Highlight (coach mark / data-guide anchor), OpenDoc.
Module map
| Area | Files |
|---|---|
| ai-core agent | agent/{mod,guide,actions,turn,bm25,index,store,app_map,prompt,context,disk_index}.rs |
| whatsup host | agent_host.rs, guide_host.rs, ai_gui.rs, ai_native.rs, gui.rs (GuideCtx, ClientCtx) |
| whatsup-ui chrome | AssistantButton, AssistantPopover, GuideStepCard, JourneyStartChips, NudgeCard, CoachMark, ActionConfirmCard, DocCitationChip; AppState.assistant |
| glitr-website | plugins/ai-index → ai-index.json / llms.txt |
ai-core
ai-core is the shared Rust core: curated catalogs, SHA-256-pinned fetch, chat templates, streaming AiSession, parallel ImageSession, and pluggable engines.
| Concern | Behavior |
|---|---|
| Catalog | Static ModelSpec list; list, get, list_for(Platform), default_web |
| Fetch | HttpFetcher pulls Hub resolve/main URLs; progress callbacks |
| Integrity | SHA-256 verify before cache write; mismatch → remove + error |
| Cache | DiskCache::user_cache() under the OS project dir for com.positive-intentions.ai (for example ~/.cache/positive-intentions/ai) |
| Chat | pull / load / generate_user / next_token / cancel_generation / history reset |
| Image | ImageSession + parse_image_intent; engines produce PNG bytes |
| Engines | CandleEngine / CandleImageEngine (feature candle); MockEngine / MockImageEngine for tests and --no-default-features |
Candle is not llama.cpp. Only curated GGUF arches ship in the catalog; arbitrary Hub GGUF files are unsupported. Optional native GPU features (cuda, metal) exist; CI stays on CPU/mock.
ai-web
ai-web is the browser product path. It does not run Candle in WASM for production chat.
| Surface | Stack |
|---|---|
| Chat | WebLLM (@mlc-ai/web-llm@0.2.79 vendored same-origin under assets/vendor/web-llm/), preferably a Worker engine; MLC prebuilt catalog (separate ids from native GGUF) |
| Image | ORT-Web WebGPU pipelines (sd_pipeline.js) for SD 1.5 / SDXL-Lightning ONNX packs |
| Prompt | Engine-side Glitr system prompt (system_prompt_for); not shown in the UI |
| Cache | Browser Cache Storage for weights; last model id in localStorage |
WebGPU is required for load. Browser image generation also requires shader-f16. Without an adapter or f16 support, load fails fast instead of hanging. Ubuntu + NVIDIA often needs Chrome launched with Vulkan ANGLE flags so requestAdapter() succeeds; the ai README documents npm run chrome:webgpu.
The host unloads WebLLM before starting an ORT image session so the two do not fight over the same GPU.
Catalogs
Hosts must pick the catalog that matches the surface. Native Candle uses GGUF ids. Browser WebLLM uses MLC ids. Image ids are shared by name across native and browser, with different backends underneath.
Native chat (Candle GGUF)
| Id | Approx. size | Notes |
|---|---|---|
tinyllama-stories-15m | ~19 MB | Tiny; web-default helper for mock/CLI |
smollm2-135m | ~105 MB | Instruct |
qwen3-0.6b-q4 | ~380 MB | Qwen3 |
smollm2-1.7b | ~1.06 GB | Native |
qwen25-1.5b-q4 | ~1.12 GB | Native |
qwen25-3b-q4 | ~2.1 GB | Native |
smollm3-3b-q4 | ~1.92 GB | Native; not in WebLLM |
Browser chat (WebLLM / MLC)
| Id | Notes |
|---|---|
SmolLM2-135M-Instruct-q0f32-MLC | Web default (f32; no shader-f16 required for this entry) |
Qwen2.5-0.5B-Instruct-q4f32_1-MLC | Larger |
Llama-3.2-1B-Instruct-q4f32_1-MLC | ~900 MB |
Qwen2.5-1.5B-Instruct-q4f32_1-MLC | ~1.1 GB; desktop GPU |
SmolLM2-1.7B-Instruct-q4f32_1-MLC | ~1.3 GB; high VRAM |
Qwen2.5-3B-Instruct-q4f32_1-MLC | ~1.9 GB; high VRAM |
Image (OpenRAIL-oriented catalog)
| Id | License | Approx. download | Notes |
| --- | --- | --- |
| sd15 | OpenRAIL-M | ~2 GB | Default. Native: Candle SD 1.5. Browser: Microsoft ONNX via ORT-Web |
| sdxl-lightning | OpenRAIL++-M | ~7 GB native / multi-GB ONNX | High VRAM. Browser: 4-step ONNX. Native uses SDXL-base weights with Lightning-oriented defaults |
Turbo / FLUX [dev] / revenue-capped community packs are excluded on purpose so the closed product path stays on commercial-safer OpenRAIL entries. Hub and MLC model licenses are separate from the library license; they are not part of the AGPL grant on the ai code.
CLI, WASM façade, gallery
| Piece | Role |
|---|---|
| ai-cli | models, pull, chat, complete, image over Candle or mock |
| ai-wasm (root crate) | wasm-bindgen + AiWasmClient JS helper; mock engine only — caller supplies GGUF bytes; not the production browser chat path |
| ai-gallery | Separate Dioxus workspace using whatsup-ui chrome: Local chat, Local image, Benchmark (GUI + TUI) |
Gallery e2e (Playwright) builds with the mock engine so CI never downloads Hub or MLC weights. The Pages build uses WebLLM; models download in the browser on first use.
The office gallery can also dock these engines beside document stories (skills + office::tools). That is a gallery host path, separate from the product Dan-EL route at /ai. See Office (editors) and Drive.
Privacy and network
| Claim | Meaning |
|---|---|
| On-device inference | After weights load, generation runs in the browser or desktop process — not a remote LLM API |
| App context for the agent | Each agent turn may include route, contacts/chats summaries, and recent message text from an open thread so the assistant can guide you. That data stays in-process; it is not uploaded to an LLM provider |
| Not mailbox crypto | Prompts are not cascaded to a peer; the AI thread is not a contact you sync with |
| Not synced | Mailbox snapshots omit the Dan-EL thread; it is reattached in-session only |
| Network still used | First download of weights/engine from Hub, MLC, or CDNs; docs index refresh from glitr.io; “local” ≠ offline-by-default |
| Residual | Large Cache Storage / disk caches (weights + optional ai-index.json) stay on the device; clearing models is a product UI action; guide prefs use glitr:guide |
The system prompt still forbids inventing APIs or claiming cloud storage of chats. It no longer claims the model can only see the Dan-EL thread: the host injects a Context block each turn. That is product framing for the model, not a sandbox proof against a compromised device. Device-store notes: Devices and storage.
Runtime and limits
- Browser: Chromium-class browser with a WebGPU adapter; image path needs shader-f16.
- Desktop: RAM/VRAM for chosen GGUF or SD weights; GPU strongly preferred for image.
- Dual catalogs: do not assume a GGUF id works in WebLLM or the reverse.
- Root WASM: mock-only; production browser chat is ai-web + WebLLM.
- License: ai code is AGPL-3.0-only; third-party crates and downloaded models keep their own licenses. A commercial license for proprietary use of the code is offered separately and does not change the public AGPL grant.
Tests
| Layer | What |
|---|---|
| ai-core | Unit tests; CI gates 100% line coverage with and without Candle |
| ai-cli | assert_cmd integration on the mock engine |
| ai-wasm | wasm-pack test --node on the mock façade |
| ai-web | Catalog / system-prompt / image-catalog unit tests |
| e2e | Playwright against the mock gallery build (UI smoke; no real model download) |
User how-to: In-app Dan-EL assistant. How the shell mounts Dan-EL chrome is on UI/UX. Next: Data structures for mailbox record shapes.
