import { GeneratorTier, UiGenerator } from '@ggui-ai/mcp-server-core'; import { JsonObject } from '@ggui-ai/protocol'; import { BehaviorFailure, PlaywrightModule } from '@ggui-ai/ui-visual-tester'; import { C as CreateUiGeneratorOptions } from '../create-ui-generator-CF0EL0Li.js'; import { R as RenderCheckIssue } from '../render-check-WfOVO9kU.js'; import '@ggui-ai/gadgets'; import '../types-public-DIpjC-OA.js'; import '../axes-CzLEMDeB.js'; import '../types-BOvHNG7K.js'; import '../llm-router-BEVtbAb9.js'; import '../llm.js'; /** * Complaint-feedback builders for the advanced generator's iterative * loop. * * The fast stage (`runRenderCheck`) returns structured * {@link RenderCheckIssue}s; the slow stage * (`validateContractBehavior`) returns structured * {@link BehaviorFailure}s. This module converts both into * prompt-augmenting text fragments the regen call appends to the * user prompt — same shape the existing `runEvaluationLoop` uses * for LLM-eval complaints. * * Format mirrors the diagnostic format the runtime-render adapter * already produces (see `harness/check/runtime-render/adapter.ts`), * so the LLM sees consistent feedback regardless of which stage * surfaced the issue. */ interface FastStageDiagnostic { readonly stage: 'fast'; readonly check: RenderCheckIssue['check']; readonly subject?: string; readonly reason: string; } interface SlowStageDiagnostic { readonly stage: 'slow'; readonly kind: BehaviorFailure['kind']; readonly actionName?: string; readonly diagnostic: string; } type StageDiagnostic = FastStageDiagnostic | SlowStageDiagnostic; /** * Convert runtime-render issues into structured diagnostics. Only * `failed` outcomes become complaints; `unverified` / `verified` / * `skipped` are not blocking (mirrors the runtime-render adapter's * own block-vs-warn split). */ declare function buildFastStageComplaints(issues: readonly RenderCheckIssue[]): FastStageDiagnostic[]; declare function buildSlowStageComplaints(failures: readonly BehaviorFailure[]): SlowStageDiagnostic[]; /** * Build the prompt fragment appended to the next iteration's user * prompt. Same human-readable format the LLM-eval loop produces so * the generator sees a uniform regen surface. */ declare function buildIterationFeedback(diagnostics: readonly StageDiagnostic[], iteration: number): string; /** * Advanced UI generator factory (`ui-gen-advanced-opus-4-7`). * * See `./index.ts` for the design narrative. This file owns the * iterative two-stage loop and the {@link UiGenerator} adapter that * registers under the slug `ui-gen-advanced-opus-4-7`. * * Loop structure (max 3 iterations, threshold 0.8, always-persist): * * for round in 1..max: * result = innerGenerator.generate(input + accumulatedFeedback) * if !result.ok: # producer failure * return result # don't try to validate code we don't have * fastIssues = runRenderCheck(result.sourceCode, contract) * if fastIssues.failed: * feedback += buildFastComplaints(fastIssues) * continue * slowFailures = validateContractBehavior(result.compiledCode, contract) * if slowFailures: * feedback += buildSlowComplaints(slowFailures) * continue * return result # both stages clean * # max rounds exhausted — return last result + validatorScore<1 * * The slow stage is skipped when the fast stage fails (no point * spinning up Chromium for code we already know is broken) AND when * the contract has no `actionSpec` entries (no behaviour to verify). * * Generator identity is baked in — slug `ui-gen-advanced-opus-4-7`, * tier `advanced`, model `opus-4-7`. Operators can NOT override slug * via this factory; build a different factory if you want a different * tier/model pairing. */ /** Generator identity — slug, tier, and model. */ declare const ADVANCED_GENERATOR_SLUG: "ui-gen-advanced-opus-4-7"; declare const ADVANCED_GENERATOR_TIER: GeneratorTier; declare const ADVANCED_GENERATOR_MODEL: "opus-4-7"; /** * Re-exported under a friendlier name for callers wiring deploys. * * `import { createAdvancedUiGenerator, type AdvancedGeneratorPlaywright } from '@ggui-ai/ui-gen/advanced';` */ type AdvancedGeneratorPlaywright = PlaywrightModule; /** * Per-stage diagnostic surface for callers that want to inspect what * happened on each iteration (bench framework, console, operator * dashboards). The validator scores are 0..1: 1.0 = clean pass. */ interface ValidationStageResult { readonly stage: 'fast' | 'slow'; readonly ok: boolean; readonly score: number; /** Per-issue diagnostics, format depends on stage. */ readonly diagnostics: readonly StageDiagnostic[]; readonly durationMs: number; } interface ValidationIteration { readonly round: number; readonly fast: ValidationStageResult; /** Slow stage runs only if fast passed AND contract has actionSpec. */ readonly slow?: ValidationStageResult; /** Aggregated validator score for this round (0..1). */ readonly score: number; } /** * Optional structured diagnostic returned per iteration. Surfaced * via `metadata.attempts` on the generator result and as part of * the validator-score metadata persisted to the blueprint store. */ type ValidationDiagnostic = ValidationIteration; interface CreateAdvancedUiGeneratorOptions extends Pick { /** * Playwright module. Required at GENERATE time — the factory itself * does not throw if absent, but every generate() call will. This is * deliberate: a deploy config that drops the field surfaces the gap * via a clean PlaywrightNotAvailableError on the first render, rather * than at server boot when no caller can react. */ readonly playwright: AdvancedGeneratorPlaywright | undefined; /** * Maximum iterations of the gen → validate → regen loop. Hard cap * at 5; values above are clamped. Default 3 per MVB plan §D3. */ readonly maxIterations?: number; /** * Pass threshold for the iteration loop. When the aggregated score * meets or exceeds this, the loop returns. 0..1 (default 0.8 per * MVB plan §D3). Used by the loop, not the blueprint store — * blueprint store decides whether to mark a sub-threshold variant * as matchable. */ readonly passThreshold?: number; /** * Inner generator. Defaults to a fresh `createUiGenerator({tier: * 'advanced', model: 'opus-4-7'})` so the BYOK route resolves to an * Opus model on Anthropic. Tests can inject a stub. * * The inner generator's identity (slug/tier/model) is irrelevant — * this advanced wrapper exposes its own fixed identity. */ readonly innerGenerator?: UiGenerator; /** * Mockup props passed to the fast-stage `runRenderCheck`. Optional; * when absent the check uses an empty `{}` (most generated * components are robust to empty props). Bench callers can pass * the same `commit.props` they'd use for the visual probe. */ readonly fastStageMockupProps?: JsonObject; /** * Slow-stage timeout per action (ms). Default 5000. */ readonly slowStageTimeoutMs?: number; } /** * Create the advanced generator. Returns a {@link UiGenerator} * registrable under the slug `ui-gen-advanced-opus-4-7`. * * @example * import { chromium } from 'playwright-core'; * import { createInMemoryGeneratorRegistry } from '@ggui-ai/mcp-server-core/in-memory'; * import { createAdvancedUiGenerator } from '@ggui-ai/ui-gen/advanced'; * * const registry = createInMemoryGeneratorRegistry(); * registry.register(createAdvancedUiGenerator({ playwright: { chromium } })); */ declare function createAdvancedUiGenerator(options: CreateAdvancedUiGeneratorOptions): UiGenerator; export { ADVANCED_GENERATOR_MODEL, ADVANCED_GENERATOR_SLUG, ADVANCED_GENERATOR_TIER, type AdvancedGeneratorPlaywright, type CreateAdvancedUiGeneratorOptions, type ValidationDiagnostic, type ValidationIteration, type ValidationStageResult, buildFastStageComplaints, buildIterationFeedback, buildSlowStageComplaints, createAdvancedUiGenerator };