AI Refinement#
Configuration#
flet_pkg.core.ai.config
#
AI refinement configuration.
Loads settings from CLI flags, environment variables, or provider defaults. Priority: CLI flags > env vars > provider defaults.
AIConfig
dataclass
#
AIConfig(provider: str = 'ollama', model: str = '', api_key: str = '', base_url: str = '', temperature: float = 0.1, max_tokens: int = 4096)
Configuration for the AI refinement pipeline.
load
classmethod
#
Load configuration from CLI flags and environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str | None
|
Provider name (anthropic, openai, google, ollama). |
None
|
model
|
str | None
|
Model name override. |
None
|
Returns:
| Type | Description |
|---|---|
AIConfig
|
Populated AIConfig instance. |
Source code in src/flet_pkg/core/ai/config.py
is_available
#
Check if the provider is configured and usable.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/flet_pkg/core/ai/config.py
list_ollama_models
#
Query the Ollama API for locally installed models.
Returns a list of model names (e.g. ["qwen2.5-coder:7b", "llama3:8b"]).
Returns an empty list if Ollama is unreachable.
Source code in src/flet_pkg/core/ai/config.py
Gap Analyzer#
flet_pkg.core.ai.gap_analyzer
#
Deterministic coverage gap analyzer.
Compares DartPackageAPI (source) against GenerationPlan (output)
to identify exactly what the pipeline missed and why. Produces a structured
GapReport — no LLM required.
GapAnalyzer
#
Deterministic gap analysis between Dart source and generated plan.
analyze
#
Analyze gaps between Dart API surface and generated plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
DartPackageAPI
|
Parsed Dart package API. |
required |
plan
|
GenerationPlan
|
Generated plan to compare against. |
required |
extension_type
|
str
|
Either |
required |
Returns:
| Type | Description |
|---|---|
GapReport
|
A |
Source code in src/flet_pkg/core/ai/gap_analyzer.py
Models#
flet_pkg.core.ai.models
#
Data models for the AI refinement pipeline.
Uses Pydantic BaseModel for structured LLM output validation. All models are importable without pydantic-ai installed (only pydantic needed at runtime when AI features are used).
GapKind
#
Bases: str, Enum
Classification of a coverage gap.
GapItem
dataclass
#
GapItem(kind: GapKind, dart_name: str, dart_type: str = '', dart_class: str = '', reason: str = '', feasible: bool = True, context: str = '')
A single coverage gap between Dart source and generated code.
GapReport
dataclass
#
GapReport(flutter_package: str, extension_type: str, total_dart_api: int = 0, total_generated: int = 0, coverage_pct: float = 0.0, gaps: list[GapItem] = list(), category_counts: dict[str, tuple[int, int]] = dict())
Structured report of coverage gaps (deterministic output).
category_counts
class-attribute
instance-attribute
#
Per-category (dart_api_count, generated_count) — e.g. {"Methods": (25, 24)}.
ImprovementSuggestion
dataclass
#
ImprovementSuggestion(target_file: str, description: str, gap_refs: list[int] = list(), priority: int = 1)
A single improvement suggested by the Architect.
ArchitectPlan
dataclass
#
ArchitectPlan(analysis: str, suggestions: list[ImprovementSuggestion] = list(), files_to_skip: list[str] = list())
The Architect's analysis and improvement plan.
FileEdit
dataclass
#
A precise search/replace edit to apply to a file.
EditorResult
dataclass
#
Collection of edits from the Editor agent.
RefinementResult
dataclass
#
RefinementResult(gap_report: GapReport, architect_plan: ArchitectPlan | None = None, edits_applied: int = 0, edits_failed: int = 0, validation_passed: bool = False, overall_assessment: str = '', input_tokens: int = 0, output_tokens: int = 0, file_diffs: list[tuple[str, str]] = list(), pending_suggestions: list[ImprovementSuggestion] = list())
Refiner#
flet_pkg.core.ai.refiner
#
AI refinement orchestrator.
Coordinates the four-step pipeline: 1. Gap Report (deterministic) 2. Architect (LLM — reasons about improvements) 3. Editor (LLM — produces search/replace edits) 4. Validator (deterministic — syntax check + retry loop)
AIRefiner
#
Orchestrates AI-powered code refinement.
Uses the Architect/Editor pattern: - Architect reasons about WHAT to fix (structured plan) - Editor produces HOW to fix it (search/replace edits) - Validator checks syntax and retries on failure
Initialise the refiner with an AI configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AIConfig
|
Provider and model settings for the LLM. |
required |
Source code in src/flet_pkg/core/ai/refiner.py
refine
#
refine(api: DartPackageAPI, plan: GenerationPlan, generated_files: dict[str, str], extension_type: str, package_path: Path | None = None, verbose: bool = False) -> RefinementResult
Run the full AI refinement pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api
|
DartPackageAPI
|
Parsed Dart package API. |
required |
plan
|
GenerationPlan
|
Generation plan from the analyzer. |
required |
generated_files
|
dict[str, str]
|
Dict of filename → content from generators. |
required |
extension_type
|
str
|
"service" or "ui_control". |
required |
package_path
|
Path | None
|
Path to the downloaded Flutter package source. |
None
|
verbose
|
bool
|
If True, print detailed progress at each step. |
False
|
Returns:
| Type | Description |
|---|---|
RefinementResult
|
RefinementResult with gap report, edits applied, and validation status. |