Agent API (window.midas)
A JavaScript API for controlling MIDAS programmatically from AI agents, Playwright, or other external tools.
Overview
window.midas provides access to MIDAS features from the browser DevTools console or automation tools like Playwright. Use it to manage datasets, tabs, statistical models, reports, and layout.
Availability
- Project screen: All methods are available
- Launcher screen: Only
help()is available. Other methods return aNO_PROJECTerror
Usage
From DevTools Console
Open the browser DevTools and call methods directly in the console.
// Check project status
const result = await window.midas.status();
console.log(result.data);
// { datasets: 3, tabs: 2, models: 1, ... }
From Playwright
const result = await page.evaluate(async () => {
return await window.midas.datasets.list();
});
console.log(result.data);
// [{ id: '...', name: 'Iris', rows: 150, columns: 5, type: 'primary' }, ...]
Viewing Help
Call help() to see a list of available methods and their signatures.
const help = window.midas.help();
console.log(help);
Response Format
All methods except help() are async and return a unified APIResult<T> response. help() is synchronous and returns a HelpInfo object directly.
// Success
{
success: true,
message: "Found 3 datasets",
data: [...]
}
// Failure
{
success: false,
message: "Dataset not found",
error: {
code: "NOT_FOUND",
message: "No dataset with ID 'abc'",
suggestion: "Use datasets.list() to see available datasets"
}
}
A warnings field may be included when the operation succeeds but there are points to note.
Method Reference
status()
Get the current project status.
const result = await window.midas.status();
// result.data:
// {
// datasets: 3,
// derivedDatasets: 1,
// tabs: 2,
// models: 1,
// reports: 1,
// activeDatasetId: 'ds_001',
// activeTabId: 'tab_001'
// }
datasets
datasets.list()
List all datasets in the project.
const result = await window.midas.datasets.list();
// result.data: [{ id, name, rows, columns, type }, ...]
type is one of 'primary' (imported data), 'derived' (created by SQL or other operations), or 'ephemeral' (temporary).
datasets.describe(id)
Get detailed information about a dataset.
const result = await window.midas.datasets.describe('ds_001');
// result.data:
// {
// id: 'ds_001',
// name: 'Iris',
// type: 'primary',
// rowCount: 150,
// columns: [
// { id: 'col_001', name: 'sepal_length', type: 'float64', scale: 'ratio' },
// { id: 'col_002', name: 'species', type: 'string', scale: 'nominal' },
// ...
// ]
// }
datasets.query(sql, name, options?)
Execute a SQL query and save the result as a new derived dataset.
const result = await window.midas.datasets.query(
'SELECT species, AVG(sepal_length) as avg_sl FROM Iris GROUP BY species',
'Species Averages'
);
// result.data: { datasetId: 'derived_...', name: 'Species Averages', rowCount: 3, columnCount: 2 }
Table names are automatically resolved from dataset names (case-insensitive). By default, if a derived dataset with the same name exists, it is automatically overwritten (deleted and recreated). Set options.overwrite to false to prevent overwriting; if a derived dataset with the same name already exists, an error is returned.
tabs
tabs.list()
List all open tabs.
const result = await window.midas.tabs.list();
// result.data: [{ id, type, title }, ...]
tabs.open(config)
Open a new tab.
// Open Graph Builder
const result = await window.midas.tabs.open({
type: 'graph-builder',
title: 'My Graph',
datasetId: 'ds_001'
});
// result.data: { tabId: 'tab_...', type: 'graph-builder', title: 'My Graph' }
// Open SQL Editor
const result2 = await window.midas.tabs.open({
type: 'sql-editor',
initialQuery: 'SELECT * FROM Iris LIMIT 10',
initialOutputName: 'Preview'
});
Check help() for available tab types.
tabs.close(id)
Close a tab.
await window.midas.tabs.close('tab_001');
tabs.closeOthers(keepTabId)
Close all tabs except the specified one.
const result = await window.midas.tabs.closeOthers('tab_001');
// result.data: { closedCount: 3 }
tabs.getGraphBuilder(tabId)
Get Graph Builder tab configuration.
const result = await window.midas.tabs.getGraphBuilder('tab_001');
// result.data: { tabId, graphType, datasetId, config, aspectRatio }
tabs.updateGraphBuilder(tabId, config)
Update Graph Builder tab configuration.
await window.midas.tabs.updateGraphBuilder('tab_001', {
graphType: 'custom',
datasetId: 'ds_001'
});
tabs.addGraphLayer(tabId, layer)
Add a layer to a custom graph. Only works when graphType is 'custom'.
const result = await window.midas.tabs.addGraphLayer('tab_001', {
geom: { type: 'point' },
aes: { x: 'col_sepal_length', y: 'col_sepal_width', color: 'col_species' },
stats: [{ type: 'identity' }]
});
// result.data: { layerIndex: 0 }
Aesthetic mappings (aes) use column IDs. To use a fixed color, specify { fixedColor: '#FF0000' }.
tabs.updateGraphLayer(tabId, layerIndex, layer)
Partially update an existing layer.
await window.midas.tabs.updateGraphLayer('tab_001', 0, {
geom: { type: 'line' }
});
tabs.removeGraphLayer(tabId, layerIndex)
Remove a layer.
await window.midas.tabs.removeGraphLayer('tab_001', 0);
tabs.moveToPane(tabId, toPaneId)
Move a tab to a different pane. Use a pane ID returned by layout.split().
await window.midas.tabs.moveToPane('tab_001', 'pane_002');
models
models.list()
List trained models.
const result = await window.midas.models.list();
// result.data: [{ id, type, name, datasetId, family }, ...]
models.run(config)
Run a statistical model. Columns can be specified by name (case-insensitive).
const result = await window.midas.models.run({
type: 'glm',
datasetId: 'ds_001',
yColumn: 'sepal_length',
xColumns: ['sepal_width', 'petal_length'],
family: 'gaussian'
});
// result.data: { tabId: 'tab_...', type: 'glm', title: 'GLM' }
type is one of 'glm', 'glmm', or 'random-forest'. For GLM, specify family as 'gaussian', 'binomial', 'poisson', 'gamma', or 'negative-binomial'. Use link to set the link function ('identity', 'logit', 'log', 'inverse', 'probit'). For GLMM, specify groupColumn for the grouping variable.
models.describe(id)
Get model details. Supports GLM, GLMM, and Random Forest. The response structure varies by model type (check result.data.type).
GLM returns coefficients, fit statistics (AIC, BIC, deviance), and diagnostic summary.
GLMM returns fixed effects (same format as GLM coefficients), random effects (group variable, variance, ICC, BLUP), fit statistics (AIC, BIC, deviance, REML log-likelihood), and diagnostic summary.
Random Forest returns task type (classification/regression), hyperparameters, and feature importances (if available).
const result = await window.midas.models.describe('model_001');
// GLM example - result.data:
// {
// type: 'glm',
// coefficients: [
// { variable: '(Intercept)', estimate: 2.25, se: 0.31, z: 7.23, p: 0.0001 },
// { variable: 'sepal_width', estimate: 0.60, se: 0.09, z: 6.45, p: 0.0001 },
// ...
// ],
// fit: { aic: 183.94, bic: 193.47, converged: true, ... },
// ...
// }
reports
reports.list()
List reports.
const result = await window.midas.reports.list();
// result.data: [{ id, name, elementCount }, ...]
reports.addContent(reportId, markdown)
Add Markdown text to a report.
await window.midas.reports.addContent('report_001', '## Analysis Results\n\nThe model shows...');
reports.addModelSummary(reportId, modelId)
Add a model summary as Markdown to a report. Supports GLM, GLMM, and Random Forest.
await window.midas.reports.addModelSummary('report_001', 'model_001');
layout
layout.split(config)
Split a pane to create a new area.
const result = await window.midas.layout.split({
tabId: 'tab_001',
direction: 'horizontal' // 'horizontal' or 'vertical'
});
// result.data: { newPaneId: 'pane_...', originalPaneId: 'pane_...' }
Use the returned newPaneId with tabs.moveToPane() to place tabs in the new pane.
Error Codes
| Code | Description |
|---|---|
NO_PROJECT | No project is loaded |
NOT_FOUND | Specified resource not found |
COLUMN_NOT_FOUND | Column not found |
INVALID_TAB_TYPE | Invalid tab type |
INVALID_GRAPH_TYPE | Layer operation attempted on non-custom graph |
INDEX_OUT_OF_RANGE | Layer index out of range |
DATASET_ALREADY_EXISTS | Dataset with the same name already exists (when overwrite is false) |
AMBIGUOUS_TABLE_NAME | Multiple datasets match the table name case-insensitively |
EXECUTION_ERROR | SQL execution error |
UNSUPPORTED_MODEL_TYPE | Unsupported model type |
Reference
- Live reference: Run
window.midas.help()in the project screen - Type definitions:
src/app/agent-api/types.ts