AI

AI Assistant

Modify the model, run simulations, and run optimizations in natural language

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.

ItemBehavior
Open / close statePersisted to browser tmm-settings; restored on next visit
Default width480 px
Resizable widthDrag handle on desktop, range 320 ~ 1200 px, persisted
Vite under 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:

StatusColorMeaning
PendingYellowTool is executing; spinner active
SucceededGreenTool completed; expand to see input / output
FailedRedTool 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:

ToolActionExample impact
structure.removeLayerRemove a single layerAffects N optimization variables
structure.clearStructureClear the entire structureHigh severity; button turns red
model.importSnapshotReplace the current model with a snapshotSame 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:

DomainCountNotable tools
Structure8addLayer / updateLayer / removeLayer / clearStructure / duplicateLayer / reorderLayers / addLayerGroup / updateLayerGroup
Surroundings1setSurroundingMedium
Optics9setWavelengthSampling / setDetectors / setConeAngle / setIncidentSpectrumEnabled / setIncidentSpectrumSource / loadIncidentSpectrumFile / setColorCalculation / setDepthDistributionResolution / setIncidentAngleAzimuth
Sweep4addSweepParameter / updateSweepParameter / removeSweepParameter / setSweepParameterList
Optimization10startRun + addObjective / updateObjective / removeObjective / setObjectiveList + addVariable / updateVariable / removeVariable / setVariableList + setAlgorithmSettings
Simulation lifecycle5runCalculation / cancelRun / runSweep / cancelSweep / cancelOptimization
RI database3searchCatalog / applyMaterialToLayer / detachMaterialFromLayer
Model + URL3importSnapshot / exportSnapshot / encodeConfig

Full specifications live in packages/tmm-core/src/operations/catalog.ts in the tmm-vite repository.

Current Limitations

Not supportedNotes
Rate limiting / billing capsPlatform mode bills against the Vercel team account; no per-user throttle
Conversation persistenceRefreshing the page starts a new session; closing the Drawer does not clear the current conversation
Branching / regenerate / undoLinear single-thread conversation only
File / image uploadText + tool calls only
Cross-session memoryEach session starts from the system prompt; no history is read

Troubleshooting

SymptomCauseFix
Send button does nothingRunning locally with pnpm dev instead of vercel dev; the Edge function is not activeSwitch to vercel dev
Service unavailable toastVercel AI Gateway integration not enabled, or AI_GATEWAY_API_KEY missingEnable the integration in the Vercel project settings; locally, run vercel env pull
Repeated PRECONDITION_FAILED from tool callsInput referenced a non-existent layerIdAsk the AI to call model.exportSnapshot first to inspect current ids
Destructive confirmation appears but cannot be clickedMultiple Drawers / Dialogs are open simultaneouslyClose 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:

Copyright © 2026 Dreapex