Appearance
Generate Text with AI Scenes
Use an AI Scene to bind model selection, instructions, and execution limits to a business task. Configure a provider and model before invoking the Scene.
Register a Scene
Register a business scene in its owning backend module, then regenerate that module's metadata through the Vona CLI:
ts
import { BeanBase } from 'vona';
import { AiScene } from 'vona-module-cabloy-ai';
@AiScene({
aiModel: 'default',
instructions: 'Summarize the supplied text without inventing facts.',
limits: { maxOutputTokens: 1024 },
})
export class AiSceneSummary extends BeanBase {}Declare the owning module's dependency on cabloy-ai. Scene identity is the full registered onion name; a database row cannot register this class on its behalf. cabloy-ai:default is provided for the built-in chat.
Generate and stream text
The business call sequence is:
ts
const scene = await this.bean.ai.create('cabloy-ai:default');
const result = await scene.generateText({
prompt: 'Summarize the supplied public information.',
});For a stream:
ts
const scene = await this.bean.ai.create('cabloy-ai:default');
const result = scene.streamText({ messages, abortSignal });Async creation performs configuration/model resolution. After creation, generateText returns the SDK promise and streamText returns the SDK streaming result synchronously. The default scene is a real registered bean, not a fallback that turns arbitrary names into scenes. Business modules may register their own AiScene beans and select named models.
When using the SDK directly, prefer v7's canonical instructions, onEnd, onAbort, stream and aggregate usage interfaces. Older examples may use deprecated names. SDK provider packages have independent versions; their major version need not equal the ai package's major.
Set per-step limits
The input, output, and timeout limits apply to each model step. Without Scene-specific overrides, the invocation defaults to maxInputCharacters: 32_000, maxOutputTokens: 4096, and stepTimeoutMs: 60_000. Before each provider request, it checks the serialized effective messages and instructions and rejects an oversized input. limits.maxOutputTokens is the Scene's only output-budget setting. Trusted calls to a bound invocation can request fewer tokens with the SDK's maxOutputTokens, including through prepareStep, but cannot exceed the Scene budget. Unused tokens do not carry over to another step.
Use limits.stepTimeoutMs to configure how long a model step may run. Each new step gets the full time allowance. Remove request.timeout from backend model and Scene configuration and from stored overrides; it is no longer accepted. If an override still uses limits.timeoutMs, replace it with limits.stepTimeoutMs and choose the value for one step rather than the entire run.
Trusted backend calls to an already bound invocation can still pass native SDK timeout options. Those options are not Scene configuration and cannot extend the Scene's step limit.
Generation defaults are overridable only inside the trusted backend boundary. Disabled entries, ownership, admission and hard execution limits are not ordinary browser-overridable generation options. Do not pass posted SDK option objects directly into the facade.
For a model call that can use tools and continue across multiple steps, see Run a Tool-Enabled Agent.