Skip to content
ERPForAll DocsDevelopment

    AI provider configuration

    erp-addon-ai-base::config::Credentials validates the [ai] section of the server configuration. The CLI invokes it through the configuration entry shared by erp server and the lifecycle commands. The server crate only retains the optional TOML table; it has no dependency on the AI addon.

    [ai]
    max_providers = 32
    max_key_bytes = 16384
    max_request_bytes = 1048576
    max_response_bytes = 1048576
    timeout_ms = 30000
    [ai.provider.office_model]
    key_file = "/etc/erpforall/ai/office_model.key"
    base_url = "https://models.example.invalid/v1"

    A relative key path is resolved against the directory of server.toml. A key file must be a regular file, owned by the effective service user, with exact mode 0600, without setuid/setgid/sticky bits. The final path component cannot be a symlink. The token must contain ASCII graphic characters; one terminal LF is accepted. Empty files, whitespace/control characters, non-ASCII bytes, missing files and oversized files fail admission with a provider/path diagnostic that excludes file contents. Parent directories and the server configuration remain operator-controlled trusted paths.

    The node validates these limits at startup before database access.

    SettingDefaultInclusive range
    ai.max_providers321–128
    ai.max_key_bytes163841–65536
    ai.max_request_bytes104857665536–4194304
    ai.max_response_bytes10485761024–1048576
    ai.max_concurrent_turns41–64
    ai.timeout_ms30000100–120000

    The request limit is in bytes. It bounds the encoder’s preflight work and the compact request body that the route can emit. JSON escaping and embedded result JSON count toward the limit. Structural safety limits also apply to the number and nesting of values. Configure the same admission policy on nodes serving the same routes.

    Missing [ai] creates an empty registry. Unknown keys and wrong types fail with sanitized diagnostics. Provider configuration names contain 1–63 ASCII letters, digits, underscores or hyphens. Credentials::require(name) checks only that explicit name and returns erp.ai.provider_unconfigured when absent. It never selects another credential. Secret buffers use Zeroizing<Vec<u8>>, are not serializable or cloneable through this API, and are omitted from Debug.

    The serving process retains the validated registry for its lifetime. Restart the node after changing credential files. Administrative CLI commands validate the same configuration at startup. The addon’s HTTP transport binds the credential to a node-configured API base before constructing an authenticated request. Existing key-file-only configurations continue to load and validate routes. A network exchange requires an explicit matching base URL.

    ai_base declares ai.provider and ai.route and is linked into the CLI native addon catalogue. Installation seeds an inactive local provider at http://127.0.0.1:11434/v1 with model local-model, and the main company’s explicit assistant route to that provider. These inert values are editable records, not a claim that a local server/model is installed. Default records are noupdate so upgrades preserve operator choices. No hosted provider, key or unrestricted budget is installed.

    Providers have a unique configuration name, protocol family (anthropic or openai_compatible), base_url, JSON allowed_models, model_limit, region, no_training, terms_reference and active. model_limit is a provider field: default 128, floor 1, hard bound 1024. Each allowed model identifier is unique, nonempty, ASCII graphic text of at most 1024 bytes. Endpoint URLs require HTTP(S), a host, and no embedded credentials, query or fragment. Saving a provider or a route does not contact an endpoint. no_training and region record the operator’s chosen policy; this slice does not verify vendor terms.

    Routes have name, required company_id, task_kind (assistant, summarize for the in-turn rolling summary, or title for the in-turn session title), required provider_id and an explicit allowed model. A SQL unique constraint permits one route per task per company. A missing route for a task answers erp.ai.route_missing naming the task; no other route is ever used as a fallback. Native exact-company policy applies to all route reads/writes, including direct record ids. base.group_system may manage configuration; base.group_user may read provider metadata and routes within allowed companies. No model contains keys or key paths. A provider is global configuration; its ordinary metadata is shared. Company-specific choices live on routes.

    erp_addon_ai_base::routing::resolve(env, tx, credentials) uses the caller’s current company and ordinary access checks without elevation. Missing routes fail by company; inactive/missing credentials fail by provider name; no other route/provider/model is tried. If an operator removes a model from a provider’s allowlist, existing routes remain stored but subsequent resolutions refuse them. Validation at resolution prevents stale configuration from authorizing a call.

    Sending a non-streaming turn from native code

    Section titled “Sending a non-streaming turn from native code”

    Resolve the route in the authenticated user’s ordinary environment; finish the database transaction before waiting for the network. Construct route.transport(&credentials)? once per turn, then await transport.complete_turn(&typed_request). Follow-up exchanges for that turn keep the context delimiter. The HTTP caller must authenticate a signed-in session and check CSRF before using this native API. System, service, API-key, impersonated and elevated routes cannot construct the transport.

    Configure the full API prefix in both places, including /v1 when required. The Anthropic client appends messages; the OpenAI-compatible client appends chat/completions. Credentials are sent over HTTPS with certificate verification, or over HTTP to an explicitly pinned loopback IP literal for a local provider. The client ignores proxy environment variables and refuses redirects. It retries a transient connection-establishment refusal or reset once. Once transmission may have begun, the exchange fails without replay. The node timeout covers the entire exchange, including retry and body reads. Status diagnostics expose the HTTP code without upstream body contents.

    Interactive standalone text turns use the dedicated browser route below. Streaming, conversation history, tools and approvals remain separate features. Configuration reload is not available: changing key files or the server configuration requires a restart. To rotate a credential, replace its file with a regular service-owned file at mode 0600, then restart each node using that configuration. An invalid replacement refuses startup; there is no fallback key. Keep the protected file outside version control and never paste its contents into diagnostics. No live provider requests belong in CI.

    Installing ai_base contributes Providers and Company routes links to General Settings → AI. The links and stored actions require Settings Administration; hiding them does not grant or replace server authorization. The provider list includes inactive records so the seeded local configuration can be opened before activation.

    The addon registers ai_base.model_list for its JSON-backed text field. Enter one exact identifier per line; empty lines are omitted. Invalid drafts remain visible, mark the record dirty and block Save. Standard Save/Discard, keyboard shortcuts and dirty-navigation protection use RecordForm’s retained draft lifecycle. The server enforces model_limit and the authoritative identifier rules. Credentials have no model field, widget or browser API. The browser never contacts the configured provider while editing configuration.

    Packaging must include ai_base alongside web in build-human-ui.mjs --addons; the human release builder includes it. The native integration binary ai_configuration_browser runs in normal nextest selection. It builds isolated current assets using the prebuilt CARGO_TARGET_DIR/debug/erp-ui-compile (or Cargo’s standard target/debug directory), then drives those assets against a disposable native fixture. The full CI web stage prepares the compiler; a focused run must build erp-ui-compiler-cli --bin erp-ui-compile first on its build host. ERP_UI_OUTPUT_DIR selects an absolute output directory for isolated build fixtures; absent that variable the builder writes web/dist/human-ui. Empty or relative output paths fail explicitly.

    GET /erp/ai/assistant/status checks the current internal browser session and installed addon. Its JSON response {"available":true} indicates the feature is installed. Company routing and spending admission occur when a message is submitted. A missing addon returns 404. Both endpoints use ordinary same-origin fetch metadata. Bearer credentials are refused.

    POST /erp/ai/assistant/turn requires the signed browser session, JSON content type, and X-CSRF-Token set to the token from the authenticated shell (bootstrap.csrf.logout). Send {"message":"What is a purchase order?","company_id":1} using a company available to this user, optionally with history, the prior visible conversation the tab resends so follow-up questions keep their context: {"history":[{"role":"user","text":"…"},{"role":"assistant","text":"…"}]}. History entries alternate strictly between questions and replies, begin with a question, and hold nonempty text; the whole array, measured as serialized JSON, must stay within ai_base.tab_history_bytes (262,144 by default, range 4,096–2,097,152), each text within ai_base.turn_message_bytes, and the count within two per ai_base.tab_history_turns exchange (32 by default). An entry or a total past those bounds answers erp.ai.message_invalid before any provider call; nothing is truncated. The input has a closed schema. Success returns text, model and usage with input_tokens and output_tokens. The application must render the result as plain text. Each call is independent: the server stores no conversation, and only the resent history carries earlier context. Do not replay failed or interrupted POSTs. Errors have a safe message. Refused admission returns 429. A closed or unauthorized session cannot receive a result.

    The database must be upgraded to ai_base 0.3.0. Configure one ai.budget for the company and exact model/provider. The optional user policy supplies an additional token/cost cap. Daily/monthly periods reset at UTC boundaries. Rates in a company budget are micro-units of company currency per thousand tokens, rounded up once per exchange. Only the company tier supplies prices. On user budgets leave both rates at the default zero and confirmed_free false. The database refuses overriding company prices at user level. The token ceiling ranges from 1 to 1,000,000,000, and the cost ceiling from 1 to 1,000,000,000,000 micro-units. Each input/output rate ranges from 0 to 1,000,000. Set confirmed_free on a company policy with both rates zero. A new installation grants no spending automatically.

    Technical System Parameters control ai_base.turn_message_bytes (4,096 by default, range 1–32,768), ai_base.turn_output_tokens (512, range 1–4,096), ai_base.turn_user_concurrency (2, range 1–8), and the tab transcript bounds ai_base.tab_history_turns (32, range 1–200) and ai_base.tab_history_bytes (262,144, range 4,096–2,097,152). The node also enforces ai.max_concurrent_turns. A provider request releases its database transaction before HTTP. The durable ai.usage row holds an estimated reservation, later settled to provider-reported input/output counts. The reservation estimate is the serialized provider payload byte length (system instructions, resent transcript, message, tools and framing) metered against the budget’s token_limit without conversion: a budget sized in tokens caps the request at roughly that many payload bytes, so raising the transcript bound without re-sizing the budget shortens the usable conversation. Over-estimates are released on settlement. An upstream report higher than the estimate is recorded in full and can exhaust the next turn. On uncertain failure, retain the estimate for the applicable period. Expired admissions can be reclaimed by the next request. The ledger carries no prompt, provider credential or response text.

    The installed client action ai_base.workspace normalizes empty params to permitted retail model names, the active company ID and the configured ai_base.search_rows limit. The records panel uses the ordinary web_search_read and fields_get RPC methods. Opening a returned ID requests the normal ir.actions.act_window form and repeats the authorization checks for that form.