PrimeBrickPrimeBrick
  • Docs
  • Contact
  • MIT License
  • Documentation
  • MCP Server
  • API Catalog
  • Services
  • Libraries
PrimeBrickPrimeBrick

© 2026 PrimeBrick. MIT License. v3.11.2

github
Backend
Frontend
    Developer Guide
      OverviewGetting startedUI stackApp shell & sidebarAuthentication & sessionsSystem settingsUI componentsUI patternsIcon ConventionsInput AnatomyField Hints & TooltipsButton Style StandardsEntity metadatai18n — Translations on the FrontendThe AI Tool Loop (caller-driven)Error HandlingComposables (use* hooks)
      Components
        Entity list tableComboSelectDynamicIconColorSelectorColorPickerAvatarPreviewEventCardCommandPaletteAppShellAppSidebarAppTopbarAppPageLayoutAppPageScaffoldAppPageBreadcrumbAppServerBannerBrowserClientInfoLangSelectThemeToggleSidebarAppLauncherSidebarHealthBadgeSidebarOrgSwitcherSidebarProfileMenuSidebarVersionBadgeButtonButton (async)FormPageLayoutFormLabelWithPriorityHelpPasswordChecklistChoiceboxDateWheelPickerEventToastLoadingBarMetadataLoadingJsonTableViewerNumberTickerStatCardToolbarDialogBorderedEntity Confirm DialogsSheet panelRFCErrorDialogLoginFormPasskeyButtonPasskeyEnrollmentAuthMethodsPromptDialogSessionExpiredDialogInputSliderSliderFieldSwitchFieldSelectableFieldsetBadgeValuesEditorTooltipFormPrimeFieldSmartRegexInput
      API Reference
Microservices
powered by Zudoku
Components

SmartRegexInput

The SmartRegexInput component is an AI-powered regex pattern input that extends the standard text input with two inner CTAs:

  1. Flags CTA — opens a right-panel sheet to toggle regex flags (g, i, m)
  2. Brain CTA — opens a right-panel AI chat that converts natural language descriptions into regex patterns using a browser-only LLM

AI Engine

The AI assistant runs ONNX models in the browser via Transformers.js + ONNX Runtime WebGPU. No backend calls are made for the AI feature.

The model is selected from the ai_models registry (System Settings → AI models); each entry is an engine + quantization variant (e.g. onnx-community/Qwen3-4B-ONNX#fp16).

Requirements

  • WebGPU: Chrome 113+/Edge 113+ or other Chromium-based browser with WebGPU enabled
  • VRAM / download size: model-dependent — shown per model in the AI models list
  • Download: one-time per model, cached in the browser (Cache API / OPFS)

Model quality indicators

Each model row carries three quality/compute fields, all set empirically by E2E regression tests:

FieldRangeMeaning
power_level1-5Compute/size class (the 5-bar indicator). 1 = ≤1B quantized, 5 = ≥4B unquantized (fp16). Higher = heavier, not necessarily better.
rank0.0-5.0Combined score — quality × 0.8 + speed × 0.2. Quality = mean(turn_scores) × 0.6 + (success_count / total_turns) × 5 × 0.4 (turn scores 5 = correct, 2 = partially valid, 1 = fail; "success" = score ≥ 4). Speed = bucket of the average response time — the seconds are averaged FIRST (per case, then mean of case averages for the model), then mapped once: ≤3 s → 5, ≤5 s → 4, ≤7 s → 3, ≤9 s → 2, ≤10 s → 1, >10 s → 0

rank measures output quality and responsiveness — power_level is deliberately not part of it, so a light reliable model can outrank a heavy unreliable one. A model that cannot answer within the 90 s generation timeout on at least 2 of 5 test turns is marked not compatible regardless of quality.

Non-WebGPU Browsers

If the browser does not support WebGPU, the AI assistant shows a message: "AI regex assistant requires WebGPU (Chrome 113+/Edge 113+). Please type the regex manually."

The flags CTA works without AI — users can still toggle flags and type regex manually.

Flags

Regex flags are stored as a separate flags field in type_config.validation.rules.regex:

Code
{ "validation": { "rules": { "regex": { "pattern": "^[a-z]+$", "flags": "gi", "error_label_key": "app.common.validation.regexMismatch" } } } }

Available Flags

FlagNameAvailable For
gGlobalAll string-derived types
iIgnore caseAll string-derived types
mMultilinetext type only (textarea)

Model Lifecycle

  1. Background pre-download: A Service Worker pre-downloads the model files on app startup using the Cache API. This is non-blocking.
  2. Lazy loading: The model is loaded into VRAM only when the user clicks the brain CTA. A progress bar shows "Loading model X%".
  3. Ready state: On subsequent uses, the model is already cached and a {model} is ready! message appears.
  4. Resource cleanup: VRAM is released when the AI panel closes.

Usage

Code
<script lang="ts"> import { SmartRegexInput } from '$lib/components/ui/smart-regex-input'; </script> <SmartRegexInput bind:value={pattern} bind:flags={flags} on_change={(value, flags) => console.log(value, flags)} config_type="string" placeholder="^[A-Z]{3}$" />

Props

PropTypeDefaultDescription
valuestring''The regex pattern (bindable)
flagsstring''The regex flags (bindable, e.g. 'gi')
on_change(value: string, flags: string) => void—Called when pattern or flags change
config_type'string' | 'text' | 'secret' | 'url' | 'email' | 'phone''string'Controls which flags are available
placeholderstring—Placeholder text
disabledbooleanfalseDisabled state
readonlybooleanfalseRead-only state

Naming Convention

SmartRegexInput establishes the Smart prefix convention for AI-powered components. Future AI-capable components should follow this pattern:

  • Component: Smart{Purpose} (PascalCase)
  • File: smart-{purpose}.svelte (kebab-case)
  • Directory: src/lib/components/ui/smart-{purpose}/
Last modified on October 28, 2026
PrimeFieldAPI Reference
On this page
  • AI Engine
    • Requirements
    • Model quality indicators
    • Non-WebGPU Browsers
  • Flags
    • Available Flags
  • Model Lifecycle
  • Usage
  • Props
  • Naming Convention
JSON