03b569d708
- Remove all sector-specific extensions (construction, ecommerce, export, hotel, restaurant, tech) — only general-purpose extensions remain - Move NE-bilaga and SRU export from extensions to core reports (lib/reports/) - Move moms-box-mapping from extensions/export/shared to lib/vat/ - Replace per-extension API routes with catch-all dispatcher (app/api/extensions/ext/[...path]/route.ts) - Add manifest.json for each extension with metadata, env vars, and deps - Add api-routes.ts pattern for extension-defined API endpoints - Add code generation scripts (generate-extension-registry, create-extension) - Add extensions.config.json for opt-in extension loading - Add extensions.schema.json for config validation - Add email service interface with noop default (lib/email/service.ts) - Add CI workflow (core-build.yml) to verify core builds with zero extensions - Add migration 045: expand account_type CHECK for untaxed_reserves - Update CLAUDE.md with comprehensive extension system documentation - Update all report engines and bookkeeping services for new imports - Clean up extensions.schema.json to only list existing extensions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
64 lines
2.0 KiB
TypeScript
64 lines
2.0 KiB
TypeScript
/**
|
|
* Template Embeddings — Core Facade
|
|
*
|
|
* Delegates to the ai-categorization extension's service when available.
|
|
* Returns empty/no-op results when the extension is not loaded,
|
|
* allowing core to compile without @langchain/openai.
|
|
*
|
|
* Pure helper functions (buildEmbeddingText, buildTransactionQueryText,
|
|
* getSchemaVersion) are re-exported from the extension for tests that
|
|
* depend on them.
|
|
*/
|
|
|
|
import { extensionRegistry } from '@/lib/extensions/registry'
|
|
import {
|
|
findMatchingTemplates,
|
|
type TemplateMatch,
|
|
} from './booking-templates'
|
|
import type { Transaction, EntityType } from '@/types'
|
|
|
|
/**
|
|
* Find similar templates via embedding search.
|
|
* Falls back to keyword matching when the AI extension is not loaded.
|
|
*/
|
|
export async function findSimilarTemplates(
|
|
transaction: Transaction,
|
|
entityType?: EntityType,
|
|
matchCount?: number,
|
|
userDescription?: string
|
|
): Promise<TemplateMatch[]> {
|
|
const aiExt = extensionRegistry.get('ai-categorization')
|
|
if (aiExt?.services?.findSimilarTemplates) {
|
|
return aiExt.services.findSimilarTemplates(transaction, entityType, matchCount, userDescription)
|
|
}
|
|
// Graceful fallback: keyword-based matching (no AI deps)
|
|
return findMatchingTemplates(transaction, entityType)
|
|
}
|
|
|
|
/**
|
|
* Seed all template embeddings in the database.
|
|
* No-op when the AI extension is not loaded.
|
|
*/
|
|
export async function seedAllTemplateEmbeddings(): Promise<{
|
|
seeded: number
|
|
errors: string[]
|
|
}> {
|
|
const aiExt = extensionRegistry.get('ai-categorization')
|
|
if (aiExt?.services?.seedAllTemplateEmbeddings) {
|
|
return aiExt.services.seedAllTemplateEmbeddings()
|
|
}
|
|
return { seeded: 0, errors: ['ai-categorization extension not loaded'] }
|
|
}
|
|
|
|
/**
|
|
* Get the current schema version hash.
|
|
* Returns 'none' when the AI extension is not loaded.
|
|
*/
|
|
export async function getSchemaVersion(): Promise<string> {
|
|
const aiExt = extensionRegistry.get('ai-categorization')
|
|
if (aiExt?.services?.getSchemaVersion) {
|
|
return aiExt.services.getSchemaVersion()
|
|
}
|
|
return 'none'
|
|
}
|