feat: remove AI extensions, restructure settings, and add atomic voucher commits (#157)

Remove AI-dependent extensions (ai-chat, ai-categorization, receipt-ocr,
invoice-inbox) and their infrastructure (lib/ai/*, ai-consent, LangChain/
Anthropic/OpenAI deps) to simplify core and reduce bundle size.

Restructure monolithic settings page into dedicated sub-pages (company,
bookkeeping, invoicing, tax, banking, api, account, team, templates) with
shared layout and sidebar navigation.

Add atomic commit_journal_entry RPC so voucher number increment and status
update happen in a single transaction — prevents burned numbers on constraint
failures. Add continuity check report and voucher gap explanation tracking.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-04-01 17:08:00 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent e89f2c402d
commit d0b3f21bde
172 changed files with 3621 additions and 20538 deletions
-119
View File
@@ -1,119 +0,0 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
// Mock server-only
vi.mock('server-only', () => ({}))
// Mock the core document-analyzer module
const { mockClassify } = vi.hoisted(() => ({
mockClassify: vi.fn(),
}))
vi.mock('@/lib/ai/document-analyzer', () => ({
classifyDocument: mockClassify,
}))
import { classifyDocument } from '../classifier'
describe('classifyDocument', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('classifies a supplier invoice', async () => {
mockClassify.mockResolvedValueOnce({
type: 'supplier_invoice',
confidence: 0.95,
reasoning: 'Contains invoice number, bankgiro, and supplier details',
isReverseCharge: false,
})
const result = await classifyDocument('base64data', 'application/pdf')
expect(result.type).toBe('supplier_invoice')
expect(result.confidence).toBe(0.95)
expect(result.isReverseCharge).toBe(false)
})
it('classifies a receipt', async () => {
mockClassify.mockResolvedValueOnce({
type: 'receipt',
confidence: 0.92,
reasoning: 'Store receipt with line items and total',
})
const result = await classifyDocument('base64data', 'image/jpeg')
expect(result.type).toBe('receipt')
expect(result.confidence).toBe(0.92)
expect(result.isReverseCharge).toBeUndefined()
})
it('classifies a government letter', async () => {
mockClassify.mockResolvedValueOnce({
type: 'government_letter',
confidence: 0.88,
reasoning: 'Letter from Skatteverket',
})
const result = await classifyDocument('base64data', 'application/pdf')
expect(result.type).toBe('government_letter')
expect(result.confidence).toBe(0.88)
expect(result.isReverseCharge).toBeUndefined()
})
it('classifies unknown documents', async () => {
mockClassify.mockResolvedValueOnce({
type: 'unknown',
confidence: 0.5,
reasoning: 'Cannot determine document type',
})
const result = await classifyDocument('base64data', 'image/png')
expect(result.type).toBe('unknown')
expect(result.confidence).toBe(0.5)
})
it('detects reverse charge on EU invoices', async () => {
mockClassify.mockResolvedValueOnce({
type: 'supplier_invoice',
confidence: 0.93,
reasoning: 'EU invoice with reverse charge',
isReverseCharge: true,
})
const result = await classifyDocument('base64data', 'application/pdf')
expect(result.type).toBe('supplier_invoice')
expect(result.isReverseCharge).toBe(true)
})
it('delegates to core classify', async () => {
mockClassify.mockResolvedValueOnce({
type: 'receipt',
confidence: 0.9,
reasoning: 'Receipt',
})
await classifyDocument('base64data', 'image/jpeg')
expect(mockClassify).toHaveBeenCalledWith('base64data', 'image/jpeg')
})
it('propagates errors from core', async () => {
mockClassify.mockRejectedValueOnce(new Error('Vision API call failed after 3 attempts'))
await expect(classifyDocument('base64data', 'image/jpeg')).rejects.toThrow(
'Vision API call failed after 3 attempts'
)
})
it('propagates unsupported MIME type errors', async () => {
mockClassify.mockRejectedValueOnce(new Error('Unsupported file type: text/plain'))
await expect(classifyDocument('base64data', 'text/plain')).rejects.toThrow(
'Unsupported file type: text/plain'
)
})
})
-27
View File
@@ -1,27 +0,0 @@
/**
* Document Classifier — thin wrapper around lib/ai/document-analyzer.
*
* SERVER-ONLY: delegates to the shared vision client.
*
* Classifies documents as supplier invoices, receipts, government letters,
* or unknown. Also detects EU reverse charge for supplier invoices.
*
* This module preserves the original public API — existing callers see no change.
*/
import 'server-only'
import { classifyDocument as classifyCore } from '@/lib/ai/document-analyzer'
// Re-export the type so existing imports work
export type { DocumentClassification } from '@/lib/ai/document-analyzer'
/**
* Classify a document using Claude Haiku Vision.
* Determines if it's a supplier invoice, receipt, government letter, or unknown.
*/
export async function classifyDocument(
base64: string,
mimeType: string
) {
return classifyCore(base64, mimeType)
}