mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 06:15:20 +00:00
Foundation for the AI chatbot + text generation feature. Phase 1 is infrastructure only: driver plumbing, configuration storage with encrypted API keys, global vs per-company resolution, admin + company UI pages, and an optional installer wizard step. The chat assistant and text-generation WYSIWYG integration come in later phases.
**Driver plumbing (app/Support/Ai/)** — AiDriver abstract, AiDriverFactory, AiException, AiChatResponse DTO, OpenRouterDriver concrete implementation. OpenRouter is the OpenAI-compatible aggregator that unlocks hundreds of models behind one API key and one request shape — ideal as the default v1 driver. Drivers are extensible the same way exchange rate drivers are: the module Registry's generic registerDriver('ai', ...) machinery plus a typed Registry::registerAiDriver() convenience wrapper (shipped in the upstream invoiceshelf/modules package in a paired commit).
**AiConfigurationService** — mirrors MailConfigurationService shape but with one deliberate deviation: API keys are encrypted at the service layer via Crypt::encryptString before persistence. OpenRouter bearer tokens have much bigger blast radius than SMTP passwords. Same settings / company_settings tables, same global-vs-per-company pattern, same use_custom_ai_config override toggle. Resolution order: global ai_enabled must be YES, then the company either overrides via use_custom_ai_config=YES (and can opt out with ai_enabled=NO inside the override) or inherits the global config.
**Controllers** — Admin/Settings/AiConfigurationController (global CRUD + driver list + test connection), Company/Settings/CompanyAiConfigurationController (per-company override + test), Setup/AiConfigurationController (installer wizard step, skippable with explicit ai_enabled=NO). API key is always masked as '********' in GET responses — the frontend submits the placeholder back on save and the backend preserves the stored value.
**Installer wizard** — new optional step 7 'AI' between Mail and Account. Default OFF with a Skip button. MailView.vue now routes to installation.ai instead of installation.account; installation.ai then routes to installation.account. Step order comment updated in routes.ts.
**Admin + Company settings pages** — AdminAiConfigView (no toggle, always global) and AiConfigView (with use_custom_ai_config BaseSwitchSection that auto-saves OFF). Both share AiConfigurationForm which renders the driver selector, API key input with show/hide, driver-specific config_fields (base_url for OpenRouter), and per-role enable toggles with free-text model inputs backed by a datalist of suggested models from driver metadata.
**Bootstrap endpoint** — adds an ai block to the response: { enabled, chat_enabled, text_generation_enabled }. All three are booleans resolved through AiConfigurationService::resolveForCompany(). Never leaks the API key. Frontend feature flags read from bootstrapData.ai to decide whether to show Phase 2/3 UI.
**Bouncer ability** 'manage ai config' added to SettingsPolicy, gated on isSuperAdmin() (same pattern as manage email config, manage pdf config).
**Tests** (22 new) — Unit: AiDriverFactory resolves built-in + Registry-contributed drivers, rejects unknown, merges availableDrivers. AiConfigurationService: encryption round-trip, resolution order (3 cases: global off, inherit global, override with company key, override with opt-out), makeDriver null/instance cases, listDrivers metadata. Feature: admin save + read with api key masking, preserve-on-placeholder behavior, company toggle ON/OFF semantics, bootstrap ai flags reflect resolution, company opt-out path.
372 tests pass (was 350, +22). Pint clean. npm run build clean. Phase 2 (chat assistant + tool calling) and Phase 3 (WYSIWYG text generation popup) are separate follow-up commits — this one is the foundation only.
187 lines
5.7 KiB
TypeScript
187 lines
5.7 KiB
TypeScript
export const API = {
|
|
// Authentication & Password Reset
|
|
LOGIN: '/login',
|
|
LOGOUT: '/auth/logout',
|
|
FORGOT_PASSWORD: '/api/v1/auth/password/email',
|
|
RESET_PASSWORD: '/api/v1/auth/reset/password',
|
|
AUTH_CHECK: '/api/v1/auth/check',
|
|
CSRF_COOKIE: '/sanctum/csrf-cookie',
|
|
REGISTER_WITH_INVITATION: '/api/v1/auth/register-with-invitation',
|
|
INSTALLATION_LOGIN: '/api/v1/installation/login',
|
|
INSTALLATION_SET_DOMAIN: '/api/v1/installation/set-domain',
|
|
INSTALLATION_WIZARD_STEP: '/api/v1/installation/wizard-step',
|
|
INSTALLATION_SESSION_LOGIN: '/installation/session-login',
|
|
|
|
// Invitation Registration (public)
|
|
INVITATION_DETAILS: '/api/v1/invitations', // append /{token}/details
|
|
|
|
// Invitations (user-scoped)
|
|
INVITATIONS_PENDING: '/api/v1/invitations/pending',
|
|
INVITATIONS: '/api/v1/invitations', // append /{token}/accept or /{token}/decline
|
|
|
|
// Bootstrap & General
|
|
BOOTSTRAP: '/api/v1/bootstrap',
|
|
CONFIG: '/api/v1/config',
|
|
CURRENT_COMPANY: '/api/v1/current-company',
|
|
SEARCH: '/api/v1/search',
|
|
SEARCH_USERS: '/api/v1/search/user',
|
|
APP_VERSION: '/api/v1/app/version',
|
|
COUNTRIES: '/api/v1/countries',
|
|
|
|
// Dashboard
|
|
DASHBOARD: '/api/v1/dashboard',
|
|
|
|
// Customers
|
|
CUSTOMERS: '/api/v1/customers',
|
|
CUSTOMERS_DELETE: '/api/v1/customers/delete',
|
|
CUSTOMER_STATS: '/api/v1/customers', // append /{id}/stats
|
|
|
|
// Items & Units
|
|
ITEMS: '/api/v1/items',
|
|
ITEMS_DELETE: '/api/v1/items/delete',
|
|
UNITS: '/api/v1/units',
|
|
|
|
// Invoices
|
|
INVOICES: '/api/v1/invoices',
|
|
INVOICES_DELETE: '/api/v1/invoices/delete',
|
|
INVOICE_TEMPLATES: '/api/v1/invoices/templates',
|
|
|
|
// Recurring Invoices
|
|
RECURRING_INVOICES: '/api/v1/recurring-invoices',
|
|
RECURRING_INVOICES_DELETE: '/api/v1/recurring-invoices/delete',
|
|
RECURRING_INVOICE_FREQUENCY: '/api/v1/recurring-invoice-frequency',
|
|
|
|
// Estimates
|
|
ESTIMATES: '/api/v1/estimates',
|
|
ESTIMATES_DELETE: '/api/v1/estimates/delete',
|
|
ESTIMATE_TEMPLATES: '/api/v1/estimates/templates',
|
|
|
|
// Expenses
|
|
EXPENSES: '/api/v1/expenses',
|
|
EXPENSES_DELETE: '/api/v1/expenses/delete',
|
|
|
|
// Expense Categories
|
|
CATEGORIES: '/api/v1/categories',
|
|
|
|
// Payments
|
|
PAYMENTS: '/api/v1/payments',
|
|
PAYMENTS_DELETE: '/api/v1/payments/delete',
|
|
PAYMENT_METHODS: '/api/v1/payment-methods',
|
|
|
|
// Custom Fields
|
|
CUSTOM_FIELDS: '/api/v1/custom-fields',
|
|
|
|
// Notes
|
|
NOTES: '/api/v1/notes',
|
|
|
|
// Tax Types
|
|
TAX_TYPES: '/api/v1/tax-types',
|
|
|
|
// Roles & Abilities
|
|
ROLES: '/api/v1/roles',
|
|
ABILITIES: '/api/v1/abilities',
|
|
|
|
// Company
|
|
COMPANY: '/api/v1/company',
|
|
COMPANY_UPLOAD_LOGO: '/api/v1/company/upload-logo',
|
|
COMPANY_SETTINGS: '/api/v1/company/settings',
|
|
COMPANY_HAS_TRANSACTIONS: '/api/v1/company/has-transactions',
|
|
COMPANIES: '/api/v1/companies',
|
|
COMPANIES_DELETE: '/api/v1/companies/delete',
|
|
TRANSFER_OWNERSHIP: '/api/v1/transfer/ownership', // append /{userId}
|
|
|
|
// Company Invitations (company-scoped)
|
|
COMPANY_INVITATIONS: '/api/v1/company-invitations',
|
|
|
|
// Members
|
|
MEMBERS: '/api/v1/members',
|
|
MEMBERS_DELETE: '/api/v1/members/delete',
|
|
|
|
// User Profile & Settings
|
|
ME: '/api/v1/me',
|
|
ME_SETTINGS: '/api/v1/me/settings',
|
|
ME_UPLOAD_AVATAR: '/api/v1/me/upload-avatar',
|
|
|
|
// Global Settings (admin)
|
|
SETTINGS: '/api/v1/settings',
|
|
|
|
// Mail Configuration (global)
|
|
MAIL_DRIVERS: '/api/v1/mail/drivers',
|
|
MAIL_CONFIG: '/api/v1/mail/config',
|
|
MAIL_TEST: '/api/v1/mail/test',
|
|
|
|
// Company Mail Configuration
|
|
COMPANY_MAIL_DEFAULT_CONFIG: '/api/v1/company/mail/config',
|
|
COMPANY_MAIL_CONFIG: '/api/v1/company/mail/company-config',
|
|
COMPANY_MAIL_TEST: '/api/v1/company/mail/company-test',
|
|
|
|
// AI Configuration (global)
|
|
AI_DRIVERS: '/api/v1/ai/drivers',
|
|
AI_CONFIG: '/api/v1/ai/config',
|
|
AI_TEST: '/api/v1/ai/test',
|
|
|
|
// Company AI Configuration
|
|
COMPANY_AI_CONFIG: '/api/v1/company/ai/config',
|
|
COMPANY_AI_TEST: '/api/v1/company/ai/test',
|
|
|
|
// Installer AI Configuration
|
|
INSTALLATION_AI_CONFIG: '/api/v1/installation/ai/config',
|
|
|
|
// PDF Configuration
|
|
PDF_DRIVERS: '/api/v1/pdf/drivers',
|
|
PDF_CONFIG: '/api/v1/pdf/config',
|
|
|
|
// Disks & Backups
|
|
DISKS: '/api/v1/disks',
|
|
DISK_DRIVERS: '/api/v1/disk/drivers',
|
|
DISK_PURPOSES: '/api/v1/disk/purposes',
|
|
BACKUPS: '/api/v1/backups',
|
|
DOWNLOAD_BACKUP: '/api/v1/download-backup',
|
|
|
|
// Fonts
|
|
FONTS_STATUS: '/api/v1/fonts/status',
|
|
FONTS_INSTALL: '/api/v1/fonts',
|
|
|
|
// Exchange Rates & Currencies
|
|
CURRENCIES: '/api/v1/currencies',
|
|
CURRENCIES_USED: '/api/v1/currencies/used',
|
|
CURRENCIES_BULK_UPDATE: '/api/v1/currencies/bulk-update-exchange-rate',
|
|
EXCHANGE_RATE_PROVIDERS: '/api/v1/exchange-rate-providers',
|
|
USED_CURRENCIES: '/api/v1/used-currencies',
|
|
SUPPORTED_CURRENCIES: '/api/v1/supported-currencies',
|
|
|
|
// Serial Numbers
|
|
NEXT_NUMBER: '/api/v1/next-number',
|
|
NUMBER_PLACEHOLDERS: '/api/v1/number-placeholders',
|
|
|
|
// Formats
|
|
TIMEZONES: '/api/v1/timezones',
|
|
DATE_FORMATS: '/api/v1/date/formats',
|
|
TIME_FORMATS: '/api/v1/time/formats',
|
|
|
|
// Modules
|
|
MODULES: '/api/v1/modules',
|
|
MODULES_CHECK: '/api/v1/modules/check',
|
|
MODULES_DOWNLOAD: '/api/v1/modules/download',
|
|
MODULES_UPLOAD: '/api/v1/modules/upload',
|
|
MODULES_UNZIP: '/api/v1/modules/unzip',
|
|
MODULES_COPY: '/api/v1/modules/copy',
|
|
MODULES_COMPLETE: '/api/v1/modules/complete',
|
|
|
|
// Self Update
|
|
CHECK_UPDATE: '/api/v1/check/update',
|
|
UPDATE_DOWNLOAD: '/api/v1/update/download',
|
|
UPDATE_UNZIP: '/api/v1/update/unzip',
|
|
UPDATE_COPY: '/api/v1/update/copy',
|
|
UPDATE_DELETE: '/api/v1/update/delete',
|
|
UPDATE_CLEAN: '/api/v1/update/clean',
|
|
UPDATE_MIGRATE: '/api/v1/update/migrate',
|
|
UPDATE_FINISH: '/api/v1/update/finish',
|
|
|
|
// Super Admin
|
|
SUPER_ADMIN_DASHBOARD: '/api/v1/super-admin/dashboard',
|
|
SUPER_ADMIN_COMPANIES: '/api/v1/super-admin/companies',
|
|
SUPER_ADMIN_USERS: '/api/v1/super-admin/users',
|
|
SUPER_ADMIN_STOP_IMPERSONATING: '/api/v1/super-admin/stop-impersonating',
|
|
} as const
|