This commit is contained in:
k
2026-09-21 21:10:09 +02:00
parent c0e7899ab3
commit 4cefd3e17f
18 changed files with 577 additions and 217 deletions
+18 -18
View File
@@ -99,7 +99,7 @@ only ever sees reviewed text blocks, never raw files.
## Drivers`src/drivers/`: `LLMDriver` interface (`listModels`, `chat`, `chatStream`),
`DriverRegistry` with global priority
`ollama → mistral → glm → puppeteer-openai (POC) → deepseek → anthropic → openai`.
`ollama → mistral → glm → arcaic-openai → arcaic-gemini → arcaic-qwen → deepseek → anthropic → openai`.
Models are addressed as `"driver:model"` (split on the first `:`).
- `OllamaDriver`: model discovery via `GET {OLLAMA_HOST}/api/tags`, chat via
@@ -113,20 +113,20 @@ Models are addressed as `"driver:model"` (split on the first `:`).
(SSE) implementation; concrete drivers only set base URL, key, and fallback
model list. A driver is enabled only when its `*_ENABLED` flag is set **and**
its key is non-empty; failing drivers are skipped (not fatal) in listings.
- `PuppeteerOpenAIDriver` (+ `browser.ts` `ChatGPTBrowserEngine`): ChatGPT via
the web UI — puppeteer-core driving Firefox (WebDriver BiDi) with a
**throwaway profile** (mkdtemp under /tmp, deleted on close). Anonymous
session works without login; if the composer is missing the engine waits up
to `PUPPETEER_LOGIN_TIMEOUT_S` for a manual login in the window. Flow:
accept the cookie banner, focus the composer (`#mobile-composer-prompt`,
multi-line via Shift+Enter), submit with `[data-composer-submit]`, stream
by polling `[data-assistant-stream-block]` text, and treat a newly
**visible** `[data-copy-message]` button as end-of-response (toolbars exist
hidden in the DOM during streaming — visibility is the real signal).
Navigation uses domcontentloaded + retries (chatgpt.com stalls sometimes).
POC — ToS-risky, off unless `PUPPETEER_ENABLED=true`. Headless validated
(`PUPPETEER_HEADLESS=true`, see `scripts/poc-chatgpt.ts --headless`); on
NixOS use `services.kisassistant.enableBrowserDriver` for a headless
Firefox in the service, or wrap it all in a declarative `containers.*`
(see `docs/NIXOS-HOSTING.md`). Smoke test:
`bun scripts/poc-chatgpt.ts` (headed, `--probe` for a state report).
- `ArcaicSubDriver` ×3 (`arcaic-openai`, `arcaic-gemini`, `arcaic-qwen`,
one model each: `chat`) + `browser.ts` engine: web-UI sessions driven by a
headless browser (WebDriver BiDi) with a **throwaway profile** (mkdtemp
under /tmp, deleted on close). Each sub-driver owns its engine (own
browser + profile) and declares a site config — composer selectors, submit
mode (send-button click vs Enter key), completion signal (newly **visible**
copy control, or `aria-busy="false"` on the response container for Gemini),
answer-text selectors. Anonymous sessions work without login; if the
composer is missing the engine waits up to `ARCAIC_LOGIN_TIMEOUT_S` for a
manual login in the window. Multi-line prompts are typed with Shift+Enter.
Off unless `ARCAIC_ENABLED=true`. Headless by default
(`ARCAIC_HEADLESS=false` for a visible debug window: `bun
scripts/poc-chatgpt.ts --headed`); on NixOS use
`services.kisassistant.enableBrowserDriver` for a headless Firefox in the
service, or wrap it all in a declarative `containers.*` (see
`docs/NIXOS-HOSTING.md`). Smoke test: `bun scripts/poc-chatgpt.ts
--site openai|qwen|gemini` (`--probe` for a state report).
+16 -14
View File
@@ -129,26 +129,28 @@ tool (`POST /api/tools/ocr`, image attachments) works out of the box.
> `services.kisassistant.extraEnv = { MISTRAL_ENABLED = "true"; };` plus a
> drop-in containing the key.
### ChatGPT web driver (`enableBrowserDriver`)
### Arcaic backend (`enableBrowserDriver`)
The `puppeteer-openai` driver answers through the ChatGPT web UI: a headless
Firefox from the nix store runs **inside the service** and drives
`chatgpt.com` via puppeteer-core (WebDriver BiDi). Anonymous sessions work —
no ChatGPT login needed — and every browser launch gets a throwaway profile
(mkdtemp under `/tmp`, deleted on exit).
The `arcaic-*` sub-drivers (`arcaic-openai`, `arcaic-gemini`, `arcaic-qwen`)
answer through web-UI sessions: a headless Firefox from the nix store runs
**inside the service** and drives the sites via a browser-automation session
(WebDriver BiDi). Anonymous sessions work — no login needed — and every
browser launch gets a throwaway profile (mkdtemp under `/tmp`, deleted on
exit).
```nix
services.kisassistant = {
enable = true;
# …
enableBrowserDriver = true; # adds firefox to the service PATH and sets
}; # PUPPETEER_ENABLED/HEADLESS/EXECUTABLE
}; # ARCAIC_ENABLED/HEADLESS/EXECUTABLE
```
Overridable through `extraEnv` (values win over the module defaults):
`PUPPETEER_LOGIN_TIMEOUT_S` (default 300), `PUPPETEER_RESPONSE_TIMEOUT_S`
(default 300). The browser only starts on the **first request** that uses the
`puppeteer-openai:chatgpt` model — boot cost stays zero otherwise.
`ARCAIC_LOGIN_TIMEOUT_S` (default 300), `ARCAIC_RESPONSE_TIMEOUT_S`
(default 300). The browser only starts on the **first request** that uses one
of the `arcaic-*:chat` models (`arcaic-openai`, `arcaic-gemini`,
`arcaic-qwen`) — boot cost stays zero otherwise.
**Full isolation: run the whole app in a declarative NixOS container.**
The driver launches Firefox as a subprocess, so the browser must live in the
@@ -184,9 +186,9 @@ services.nginx.virtualHosts."chat.kisakay.com" = {
};
```
Headless mode needs no display server anywhere (validated on CI-less builds:
cookie banner accepted, message sent, response streamed). If ChatGPT ever
starts headless-shaming, fall back to `PUPPETEER_HEADLESS=false` inside the
Headless mode needs no display server anywhere (validated: cookie banner
accepted, message sent, response streamed). If the site ever starts
headless-shaming, fall back to `ARCAIC_HEADLESS=false` inside the
container plus an `Xvfb` service — same driver, virtual display.
## 5. TLS reverse proxy (`enableNginx`)
@@ -288,5 +290,5 @@ After dependency bumps the first build may fail with a `bunDepsHash` mismatch
| `ollamaHost` | str, `http://localhost:11434` | Ollama endpoint |
| `domain` | null \| str | nginx vhost name, required when `enableNginx = true` |
| `enableNginx` | null \| bool, `null` | `true`/`false` force the bundled reverse proxy on/off; `null` = nginx iff `domain` set (legacy) |
| `enableBrowserDriver` | bool, `false` | headless Firefox in the service for the `puppeteer-openai` ChatGPT web driver (sets `PUPPETEER_ENABLED`/`PUPPETEER_HEADLESS`/`PUPPETEER_EXECUTABLE`, overridable via `extraEnv`) |
| `enableBrowserDriver` | bool, `false` | headless Firefox in the service for the `arcaic` driver ("Arcaic-Technology" model; sets `ARCAIC_ENABLED`/`ARCAIC_HEADLESS`/`ARCAIC_EXECUTABLE`, overridable via `extraEnv`) |
| `extraEnv` | attrs of str, `{}` | extra environment (non-secret values only) |