Add an export to a plugin widget
Let users export what a widget shows. The Export entry on a widget's card calls two functions that the module returns from initialize. The host defines no export formats, because only the widget's own code knows what it can export.
1. Ask for the permission
In the widget's manifest entry:
"permissions": ["core:data:read", "core:export:provide"]
2. Return the two functions
Return them from initialize:
async initialize({ model }) {
return {
async exportOptions() {
const rows = model.get("data") ?? [];
return rows.length
? [{ id: "rows", label: "Rows (CSV)", extension: "csv", mime: "text/csv" }]
: [];
},
async exportData(id, { title }) {
return toCsv(model.get("data"));
},
};
},
exportOptionsreturns the list of exports. The host calls it each time the user opens Export. An empty list means that the widget has nothing to export right now.exportDatareturns the content of the chosen export, as a string, anArrayBuffer, a typed array or aBlob.
3. Clean up through signal
initialize returns the exports, so it cannot return a cleanup function as well. Do the module's cleanup through signal.
Limits
An export has at most 16 options, and a file has at most 25 MiB. The timeouts are:
| Function | Timeout |
|---|---|
exportOptions | 10 seconds |
exportData | 60 seconds |
copilotContext | 10 seconds |
copilotRows | 60 seconds |
A copilotContext function, together with the permission core:copilot:context, works the same way. It tells the AI agent what the widget shows. A copilotRows function, with the same permission, hands the AI agent every row of the widget, which the agent loads as a table that it can query.
Next steps
Plugin module contract lists the limits.