AI Assistant
Dreapex TMM ships with a built-in AI chat assistant. It accepts natural-language instructions like "add a 100 nm SiO₂ layer at the end", "sweep wavelengths 400–800 nm with R / T / A enabled", or "run an optimization", and executes them without leaving the current page. It modifies the Pinia model store via tool calls, with inline confirmation gates for destructive actions.
Entry Point
A floating button (pi pi-comments icon) in the bottom-right corner of every page opens the chat Drawer on the right side. Click again, or press the X in the Drawer header, to close it.
| Item | Behavior |
|---|---|
| Open / close state | Persisted to browser tmm-settings; restored on next visit |
| Default width | 480 px |
| Resizable width | Drag handle on desktop, range 320 ~ 1200 px, persisted |
pnpm dev does not run the /api/ai/chat Edge function. Use vercel dev for full AI assistant functionality. In production, requests are authenticated via Vercel AI Gateway with no extra configuration.Example Session
You: add a 100 nm SiO2 layer at the end
AI: done — called structure.addLayer; current stack has 4 layers.
You: sweep wavelengths 400-800 nm with 5 nm step, enable R T A
AI: called setWavelengthSampling + setDetectors.
You: run the calculation
AI: called simulation.runCalculation; waiting on backend...
You: delete layer #2
AI: [inline DiffPreview]
Remove Layer #2 (name='TiO2', thickness=80nm)
Will affect 1 optimization variable
[Cancel] [Confirm Delete]
You: [click Confirm]
AI: removed.
Tool Call Panel
Every AI tool call appears as a collapsible panel in the Drawer, color-coded by status:
| Status | Color | Meaning |
|---|---|---|
| Pending | Yellow | Tool is executing; spinner active |
| Succeeded | Green | Tool completed; expand to see input / output |
| Failed | Red | Tool failed; shows error code and reason |
If a tool call produces validation warnings (for example, a wavelength change leaves a layer's RI data out of range), a yellow warnings banner appears below. The AI reads those warnings on the next turn and either fixes them or asks for confirmation.
Inline Confirmation for Destructive Actions
Three tools require explicit user confirmation, with an inline before / after diff and dependency summary in the Drawer:
| Tool | Action | Example impact |
|---|---|---|
structure.removeLayer | Remove a single layer | Affects N optimization variables |
structure.clearStructure | Clear the entire structure | High severity; button turns red |
model.importSnapshot | Replace the current model with a snapshot | Same flow as .tmm import, triggered by AI |
Cancel returns a USER_CANCELLED error to the AI; it will not immediately retry the same call.
Available Tools
43 tools across 8 domains:
| Domain | Count | Notable tools |
|---|---|---|
| Structure | 8 | addLayer / updateLayer / removeLayer / clearStructure / duplicateLayer / reorderLayers / addLayerGroup / updateLayerGroup |
| Surroundings | 1 | setSurroundingMedium |
| Optics | 9 | setWavelengthSampling / setDetectors / setConeAngle / setIncidentSpectrumEnabled / setIncidentSpectrumSource / loadIncidentSpectrumFile / setColorCalculation / setDepthDistributionResolution / setIncidentAngleAzimuth |
| Sweep | 4 | addSweepParameter / updateSweepParameter / removeSweepParameter / setSweepParameterList |
| Optimization | 10 | startRun + addObjective / updateObjective / removeObjective / setObjectiveList + addVariable / updateVariable / removeVariable / setVariableList + setAlgorithmSettings |
| Simulation lifecycle | 5 | runCalculation / cancelRun / runSweep / cancelSweep / cancelOptimization |
| RI database | 3 | searchCatalog / applyMaterialToLayer / detachMaterialFromLayer |
| Model + URL | 3 | importSnapshot / exportSnapshot / encodeConfig |
Full specifications live in packages/tmm-core/src/operations/catalog.ts in the tmm-vite repository.
Current Limitations
| Not supported | Notes |
|---|---|
| Rate limiting / billing caps | Platform mode bills against the Vercel team account; no per-user throttle |
| Conversation persistence | Refreshing the page starts a new session; closing the Drawer does not clear the current conversation |
| Branching / regenerate / undo | Linear single-thread conversation only |
| File / image upload | Text + tool calls only |
| Cross-session memory | Each session starts from the system prompt; no history is read |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Send button does nothing | Running locally with pnpm dev instead of vercel dev; the Edge function is not active | Switch to vercel dev |
Service unavailable toast | Vercel AI Gateway integration not enabled, or AI_GATEWAY_API_KEY missing | Enable the integration in the Vercel project settings; locally, run vercel env pull |
Repeated PRECONDITION_FAILED from tool calls | Input referenced a non-existent layerId | Ask the AI to call model.exportSnapshot first to inspect current ids |
| Destructive confirmation appears but cannot be clicked | Multiple Drawers / Dialogs are open simultaneously | Close other dialogs first |
Relationship to Other Persistence
The AI assistant only mutates the current model snapshot in the store. After a mutation, local autosave fires as usual. To externalize state, follow the regular workflows:
- Long-term archival → Model File Import / Export (
.tmm) - One-shot reproduction → URL Config Sharing
- Quick entry into a working model → Case Library