Skip to content

Use Private Chat ​

Open Chat ​

The authenticated page is /cabloy/ai/chat. It uses session SSR for saved private history and starts generation only from a browser action. Conversation/history queries belong to the Zova model; the current stream is transient state, not a second durable history owner.

AI_CHAT_BOT_ENABLE controls the frontend navigation entry; Passport and role.aiChatAccess authorize the backend Chat API. The navigation setting does not grant API access. Chat uses a server-configured model. For business reads and reviewed writes, see Use Controller Tools in Chat.

The API derives the user from Passport and operates inside the active instance. The browser sends a conversation identity, request key and new user text. The server loads owned history and chooses the scene/model; client-supplied system/assistant history and owner/tenant/model authority are not accepted.

Run behavior ​

  1. A short atomic preparation admits one active turn and persists its user message and run.
  2. The provider executes outside the transaction.
  3. A short fenced finalization persists the terminal outcome, assistant result and observed usage.

Repeating the same request key with the same input references the existing run without another provider call. Reusing it with different input conflicts. This establishes local admission/persistence behavior, not exactly-once remote billing.

If an ordinary send fails or is interrupted after the server accepts the message, the saved transcript keeps the user's prompt but not the incomplete reply. A new message such as “Please continue” can use those unanswered prompts along with earlier completed dialogue, subject to the conversation's access and input limits. This is a fresh request, not a replay, stream resume, or approval of a tool action.

Stop aborts the browser transport and propagates cancellation. Server status and history remain authoritative after a cancellation or connection failure. Aborted turns are not shown in the saved transcript or reused as model context. Unknown usage remains unknown rather than a fabricated zero.

If a model step times out, Chat interrupts the run as chat_timeout and does not save a partial reply. A browser disconnect is a separate cancellation.

Chat also records a deadline automatically so a failed server process cannot leave a conversation stuck in the running state. It derives this deadline from maxSteps * stepTimeoutMs plus 10 seconds for preparation and settlement, using four steps if the Scene does not specify maxSteps. No separate timeout setting is required. A later status lookup or admission can release an expired run's claim; it never resumes that execution or accepts a late result.

How Chat selects history ​

Chat starts history selection with the full per-step input limit, subtracting the serialized current payload and the actual first-step instructions (Scene instructions and any host instructions). When more tool steps are possible, it also reserves the lesser of 32,000 characters and one quarter of the input limit for later context. This reserve limits only the history selected, not the current input. Chat takes the newest whole saved runs that fit and prepends them in chronological order. The selected history stays fixed across model steps; each later request must still fit the per-step limit, including any new tool results and effective instructions.

Keeping history in order can preserve a request prefix across turns, but provider cache hits depend on the actual request and deployment. History trimming or changes to tool visibility can change that prefix. See what Chat sends to the provider for the disclosure rules.

Streaming integration ​

The guarded Vona action validates authorization and input before taking ownership of the native response. It sets the response status and disables ordinary response handling, then awaits the SDK's native Node response pump and application finalization inside the live request scope. A lazy Koa body alone does not establish that lifetime.

Chat saves the answer before sending its terminal stream event. Best-effort naming runs after the native response ends, so a generated title can appear in the sidebar and conversation heading after Chat returns to Ready. An unavailable title does not change the saved answer or prevent the next send.

The built-in cabloy-ai:generateTitle AI Scene supplies naming options separately from reply generation. It uses the exact model and provider already bound for that reply. To tune naming, add an entry in backend config.onions.aiScene or save an instance-scoped override with configuration.saveScene(). The built-in defaults are:

ts
{
  'cabloy-ai:generateTitle': {
    request: { maxRetries: 0 },
    limits: { maxOutputTokens: 256, stepTimeoutMs: 20_000 },
  },
}

This Scene accepts generation, request, limits.maxOutputTokens, limits.stepTimeoutMs, and enabled (false disables automatic naming). It does not select a model or create a standalone invocation. The title call runs one model step. For both output tokens and timeout, it uses the smaller of the title Scene's limit and the bound Chat invocation's limit. The model timeout does not cover saving the title. The browser's last automatic title check is about 12 seconds after reply reconciliation; a title saved after that can appear on a later refresh.

The Zova transport uses the current API origin, locale/timezone and Passport bearer-token refresh path. Cookie credentials alone are not a replacement for that API authentication contract. The browser uses SDK transport/reader primitives, not a React-specific chat hook. Backend AI invocations use strict provider-wire validation rather than HTTP query coercion; the chat service retains that strict scope through stream consumption and finalization. This preserves valid empty-string provider events without changing the application's ordinary query parsing.

Tune the Chat budgets ​

The built-in Chat Scene (cabloy-ai:default) defaults to maxInputCharacters: 256_000, maxOutputTokens: 2048, and stepTimeoutMs: 120_000 per step, with up to maxSteps: 10 per run. To tune these budgets or the proposal review window, add an entry like this to backend config.onions.aiScene, or set the same limits fields in an instance's stored Scene override:

ts
{
  'cabloy-ai:default': {
    limits: {
      maxOutputTokens: 3072,
      maxSteps: 6,
      stepTimeoutMs: 90_000,
      confirmationWindowMs: 10 * 60_000,
    },
  },
}

A step is one model invocation, including the initial request and any final answer, not one tool call. maxSteps must be a positive safe integer. maxSteps: 1 does not disable tools: the model can call a tool on that step but cannot make a follow-up request to turn its result into an answer. Without visible tools, Chat already uses one step. Direct callers of streamAgent() still supply their own explicit maxSteps.

Input and output allowances are not divided among steps or debited across the run. Reported usage remains aggregate when available; the per-step allowances are neither a total usage cap nor a billing promise. A serialized character count is not a context-window or wire-size guarantee: model tokenization, provider formatting, and body-size or timeout limits at proxies and gateways depend on the deployment.

Do not override the output cap with raw provider-specific generation options. If the provider ends an otherwise clean Agent reply at the length limit, Chat marks the reply interrupted and suggests asking for a shorter answer. The partial reply is not published or added to conversation history.

Diagnosing text that appears only at completion ​

The following timing checks apply to ordinary first-step text, including turns with a visible tool catalog. Provisional prose is intentionally reset when a turn enters tool execution; tool-derived final text remains settlement-gated.

A successful SSE response or a short answer such as OK does not prove progressive rendering: a provider may emit the complete answer in one text delta. To observe progress manually, use one public, longer prompt (for example, a roughly 400-character explanation in numbered paragraphs) within the configured output/deadline limits. This makes a real provider request and may incur charges; do not repeatedly resend an uncertain request.

In browser Network tools, inspect POST /api/cabloy/ai/chat/send while it is still open. Where the browser exposes live SSE events, compare the arrival of text-delta events with growth of Assistant · live response, before the final finish event and Ready state. A completed Response tab, total request duration, or response.clone().text() read at EOF does not establish incremental arrival.

  • Spaced text events but no visible growth point to the browser parser/state/render boundary.
  • Text events arriving only in a final burst require upstream timing evidence to distinguish provider batching from HTTP/intermediary buffering. Multiple events in a completed response alone cannot make that distinction.
  • An ai.chat.stream.failed event followed by saved text appearing can indicate stream failure followed by authoritative history reconciliation, not successful incremental delivery.

For a same-request comparison, the backend ai.chat.stream.timing debug summary reports first/last nonempty text times, total execution duration and 250 ms windows of delta counts and character lengths. Its clock starts inside chat execution, whereas a browser observer commonly starts at fetch; compare cadence and counts rather than equating their time origins. This measures SDK text-stream consumption immediately before SSE enqueue, not raw provider-network arrival or browser painting. Bursty backend consumption places the delay at or before that boundary; it does not by itself prove the provider service is buffering. Debug events require the existing logger filters to admit them; do not bypass protected-request diagnostic suppression.

If further authorized diagnosis is needed, compare provider-local Fetch response-body reads before SSE parsing with SDK text timing in the same execution clock. Observe the body the SDK consumes without independently draining or retaining it, and remove temporary instrumentation after collection. Batches already present in those reads place the pattern before SDK text normalization; they still include Fetch/runtime buffering and decompression, not just the remote provider. Roughly regular byte-sized batches are a reason to inspect gateway/proxy/compression buffering, not proof of one specific cause. Requesting a longer public answer can make repeated batches observable, but does not guarantee output length or justify increasing deployment limits or automatic retries.

A separately authorized request-level Accept-Encoding: identity comparison can help investigate compression-dependent delivery. Keep it local to the selected invocation and record only allowlisted encoding classifications and numeric timing/count summaries; check the response's actual Content-Encoding, since requesting identity does not guarantee upstream compliance. Preserve an explicit caller/provider compression policy rather than silently changing global Fetch behavior. If delivery improves, treat it as evidence for the negotiated path, not proof of a specific gzip/proxy defect—especially when the baseline response encoding was not recorded. Prefer provider-specific configuration or correcting upstream flush/compression behavior over an unverified framework-wide default.

The managed mock regression checks multiple growing partial texts before completion and verifies the reset-to-progress handoff when a tool is selected. It does not qualify a real provider or deployment path. Retain only safe event types, counts and relative timing when investigating; do not share credentials, cookies, raw provider errors or unreviewed HAR files. Do not add artificial typewriter delays to disguise a buffering problem.

Stable non-sensitive debug events assist diagnostics; ai.chat.run.failure records only a fixed execution phase, SDK error family and validated HTTP status (or unknown), never the raw error or provider response. A schema-validation failure does not by itself establish an HTTP rejection or identify the failing response field. Logs are not a substitute for assertions or a billing ledger.

Released under the MIT License.