Capabilities & Modes
AI‑Kit can run each feature from one of two sources:
- on-device — Chrome Built-in AI APIs (Gemini Nano) in the user’s browser
- backend — your own AWS-hosted AI‑Kit backend (SAR template)
Mode preference
The global preference is one of:
local-only— only on-device, never backendbackend-fallback— prefer on-device, fallback to backendbackend-only— only backend, ignore on-device
These values are represented by AiModePreference.
Supported features
AI‑Kit tracks capability per built-in AI feature:
promptsummarizerwriterrewriterproofreaderlanguage-detectortranslator
Programmatic capability checks
Use these helpers when you need to decide before rendering a UI:
import { decideCapability, checkOnDeviceAvailability, getMinChromeVersions } from "@smart-cloud/ai-kit-core";
const min = await getMinChromeVersions(); // { prompt: "...", summarizer: "...", ... }
const onDevice = await checkOnDeviceAvailability("writer");
if (onDevice.available) {
// Chrome API is available / downloadable / downloading
}
// For translator you must pass source/target languages to availability()
const translator = await checkOnDeviceAvailability("translator", {
sourceLanguage: "en",
targetLanguage: "de",
});
const decision = await decideCapability("writer");
// Optional overrides:
// - availability options (same shape as Chrome create() options)
// - modeOverride to force local/backend behaviour for this call
const forcedBackend = await decideCapability(
"writer",
undefined,
"backend-only",
);
console.log(decision.source); // "on-device" | "backend" | "none"
console.log(forcedBackend.reason); // detailed string explaining the decision
decideCapability(feature, availabilityOptions?, modeOverride?) mirrors the runtime logic used by AI‑Kit internally.
availabilityOptions should match the Chrome API create() options for the requested feature (for example Translator requires sourceLanguage and targetLanguage). modeOverride lets you temporarily force "local-only", "backend-fallback", or "backend-only" without touching global settings.
Backend configuration (when enabled)
When backend usage is allowed, AI‑Kit needs:
backendTransport:"fetch"or"gatey"
(gateymeans “use Gatey’s signed transport” when Gatey is present)backendBaseUrl: full base URL for the backend API (typical)backendApiName: API name if your transport requires it
In most setups you’ll only configure backendBaseUrl.
AI‑Kit distinguishes context: "admin" | "frontend" for backend calls. Some deployments may expose separate path prefixes (for example /admin/* and /frontend/*) with different security policies.