Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
Lägger docs/production-readiness.md och siax/production-gaps.json enligt SIAX Master Definition of Done. Underlag: git-, kod- och live-evidens 2026-11-11. Nivån är evidensbaserad, inte ett leveransgodkännande.
* chore: repo-wide bloat sweep, remove dead code and fold duplicate helpers
Remove 33 dead files, ~270 unreferenced exports/types, 13 dead i18n
namespaces and 4 unused dependencies; fold byte-identical helper copies
into one canonical home each (lib/utils chunk/sleep/utcDateStamp,
lib/dates/iso, lib/invariants/uuid, lib/xml/escape, lib/reports/sru/format,
lib/pdf/number-text, lib/browser/panel-request, lib/api/v1/body +
v1ValidationError rolled out to ~55 v1 routes, booking-template schemas).
No behaviour change: v1 bodies and status codes, MCP tool schemas, DB
writes and money math are untouched. Naive ore rounding was deliberately
not swapped for roundOre; see DECISIONS.md 2026-09-02 for the full list
of things left alone on purpose.
tsc, lint, 19588 unit tests and check:guards green; antipattern baseline
ratcheted (naive-ore-round 622 -> 620, hand-rolled-invariant 115 -> 113).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* test(transactions): import RawTransaction from @/types after the ingest re-export removal
CI's type ratchet (check:types, full tsconfig) caught the one test file
that still imported the type through lib/transactions/ingest.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Three user-reported failures in the assistant panel, one root cause each:
1. "The chat asks what I'm referring to" when continuing a thread. The
single-call console (general.help, AskConsole -> /api/agent/ask) was
stateless since the 08-20 model-agnostic cutover: conversationId was only
the tool actor id, so every turn was answered blind, reload or not.
The provider-agnostic GenerateTextRequest gains an optional `history`
(real message turns before the prompt, in both the Anthropic-family and
the OpenAI-compatible adapter; absent/empty leaves the request
byte-identical to the single-turn call). The route loads the thread's
earlier turns server-side (loadChatHistory: text only, hidden and tool
rows dropped, alternation repaired, newest 16 rows / 10k chars) before
writing the new question, and hands them to the model.
2. A full page reload (the deploy prompt's "Ladda om") closed the docked
panel and dropped the thread from view. The panel now remembers its open
thread per tab in sessionStorage (lib/agent-panel/session-restore) and
the provider reopens it on mount; the sheet loads it exactly like a pick
from "Tidigare konversationer". Close and "Ny konversation" forget it; a
thread that no longer opens is dropped instead of retried on every reload.
3. "Can't type any more" once the update banner shows. DeployReloadPrompt's
full-width wrapper sits at z-[60] after the panel in DOM order and
swallowed clicks on the panel's composer; only the card takes input now.
Claude-Session: https://claude.ai/code/session_01VjoXN3xdNZrHZeYA6qMi3g
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
The /chat assistant (audit Option A / rip) shipped in #1759 reading only the
company name + entity type, so it answered "jag har ingen bokföringsdata" to
every figures question ("vad är min största utgiftspost?"). It now behaves like
an MCP client: it answers over a bounded, READ-only tool loop across the same
MCP read tools the old streaming assistant had, plus an always-on company
snapshot as the backstop.
Provider-agnostic by construction, so it still runs on a local model:
- lib/ai generateText gains optional `tools` + `maxSteps`. The OpenAI-compatible
service forwards them to the Vercel AI SDK (stopWhen: stepCountIs), which runs
the loop; the Anthropic-family service hand-rolls a small loop against
messages.create. Kept on the raw Anthropic SDK: no new deps, and the no-tools
path is byte-identical, so hosted extraction/composer/etc. are unchanged.
- lib/agent/ask/ledger-tools.ts: the read slice of general.help's whitelist
(income statement, VAT, ledgers, query_journal, reskontror, lists…) from
agentToolRegistry, dispatched with the agent_chat actor run-turn uses. Write/
staging + memory-write tools are excluded; readOnlyHint/destructiveHint are
re-checked. Empty in a core-only build → snapshot-only, graceful.
- lib/agent/ask/snapshot.ts: a compact company_settings + deadlines block so a
model that can't/won't call tools still answers status questions. Never carries
figures (those come from the live tools).
- ask-service attaches tools + snapshot when a userId is present and uses a
tool-aware system prompt; the route calls ensureInitialized() so the registry
is populated and threads userId/conversationId through.
Works on Bedrock and on any local model with function-calling (Qwen). Tests:
the anthropic hand-rolled loop (tool call → result → answer, is_error handling,
step-budget forced answer), openai tool forwarding, the read-only adapter
filter, the snapshot format, and the ask-service wiring. 457 agent+ai tests
green, lint/guards clean.
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* feat(ai): job-shaped AI service with OpenAI-compatible backend, extraction-first; stop extracting every inbox document twice
Sovereign plan WS1 PR1 (#1406 Tier 2, extraction-first, aligned with the
AI surface audit).
lib/ai grows a job-shaped service (generateText / generateStructured /
extractFromDocument; no streaming members yet, see plan rule R3):
- services/anthropic-family delegates to the existing createAiClient()
and sends the exact request literals the inbox extractor sent before
(request-shape tests deep-equal them), so hosted Bedrock stays
byte-identical.
- services/openai-compatible talks to any chat-completions endpoint
(BYO Swedish provider) via Vercel AI SDK 6.x, exact-pinned and
guarded: images as parts, PDFs rasterized with poppler (AI_PDF_MODE)
or sent natively, AI_VISION / AI_STRICT_JSON declared, honest skips
(ai_no_vision, pdf_rasterizer_missing) instead of fake failures.
- config.ts: AI_PROVIDER/AI_BASE_URL/AI_API_KEY/AI_MODEL and per-tier
AI_*_MODEL with the legacy BEDROCK_* names kept as the same overrides;
getAiStatus() is the single source of truth for "is AI wired up".
- provider.ts: openai-compatible in the auto-detect chain (after Bedrock
and the direct API); createAiClient() refuses it loudly.
Document extraction moves onto the service and gets the audit's fixes:
- Inbox documents were extracted TWICE (pipeline A ran inside
uploadDocument() before the inbox row existed, so its dedupe branch
never fired; 3 707 + 1 666 calls / 30 d). The inbox now declares
extractionOwner on the upload, the extension yields, and the inbox
mirrors its single outcome onto document_attachments from every
writer (sync, deferred, attach, retry, MCP).
- Every "no extraction will ever happen" outcome is stamped
(skipped:no_ai_entitlement / ai_unconfigured / system_generated /
...); the status route maps the quiet ones to 'disabled' on the first
poll instead of a 30 s client timeout. Prod showed 309 of the 327
never-extracted uploads were the paywall working silently.
- Self-generated documents (our own invoice PDFs, payout files) are no
longer OCR'd.
- Agent invoke answers 503 ai_unconfigured when the deployment has no
assistant backend, distinct from the paywall.
Guard: new direct-ai-client antipattern check (shrink-only allowlist of
the pre-abstraction SDK callers) plus exact pins for @anthropic-ai/sdk,
ai and @ai-sdk/openai-compatible.
Verified: 15 958 unit tests green, guards, lint ratchet, typecheck, and a
live smoke against hosted Bedrock through the new service (ping, streamed
tool turn, thinking+cache, PDF extraction).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(ai): make AI_API_KEY optional for OpenAI-compatible endpoints (keyless local model servers)
A local model server (llama.cpp's server, Ollama /v1, LM Studio, vLLM)
usually has no auth. Before, the OpenAI-compatible backend required both
AI_BASE_URL and AI_API_KEY to count as configured, so running Accounted on a
local model meant setting a meaningless placeholder key.
- resolveAiProvider / hasAiCredentials: a base URL alone is now enough.
- services/openai-compatible: only send Authorization: Bearer when AI_API_KEY
is set, so a keyless server is never handed an empty bearer; a hosted
provider that needs a key still sets it.
- Docs (SELF-HOSTING Option 3: local-model example, key marked optional),
DECISIONS.
Verified: with no AI_API_KEY, just AI_BASE_URL + AI_MODEL, getAiStatus()
reports configured=true / provider=openai-compatible (live). lib/ai suite
71 green; tsc, guards, lint clean. Bedrock/Anthropic logic unchanged.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>