AI Assistant
Read First
src/components/AiChatTab.tsxandsrc/components/AiProvidersDialog.tsxfor UI behavior.src/lib/ai/buildDiagramContext.tsfor context scope and truncation.src/lib/ai/diagramAssistantInstruction.tsfor the model contract.src/lib/ai/diagramPatchSchema.tsandsrc/lib/ai/diagramPatchJsonSchema.tsfor the patch contract.src/lib/ai/simulateAiPatch.tsandsrc/store/store.tsfor validation and commit behavior.src/lib/ai/aiCredentialStorage.tsfor credential handling.
Change Rules
- Preserve the pipeline: provider request -> streamed response -> parse -> Zod validation -> simulation on a clone -> atomic store commit.
- Never apply raw model output or a partially simulated patch. Return an actionable error and leave the current diagram unchanged on failure.
- Resolve references with the existing ID/name rules and handle duplicate names deliberately.
- Preserve locked diagram and locked zone protections in both direct store actions and AI simulation.
- Keep cloud and local providers distinct. Cloud providers receive diagram context; Ollama and LM Studio are intended for local keyless use and may require local CORS configuration.
- Never log API keys, decrypted credentials, session secrets, or full schema context. Avoid expanding context beyond what the user selected or the feature requires.
- Preserve retry and cancellation behavior for transient provider failures without duplicating a committed patch.
Verification
- Test valid patches, malformed JSON, schema-invalid operations, simulation failures, duplicate references, locked diagrams, and streamed/retried responses.
- Verify provider setup does not expose secrets in logs or UI errors.
- Confirm chat history remains scoped to the selected diagram and persists after reload.
- Run the standard type-check, lint, and production build gate.