SDK
Desk apps: declaring, settings, the supervisor and the sandbox
Turn a program into a Desk app: declare, the settings schema, settings.get, request and onChange, the rotation, the supervisor and the community apps' sandbox.
What an app is
An app is a program that tells Miblo its name and the settings it needs. The person fills those settings in Miblo Hub (Desk apps tab) or the terminal, never in a file or an environment variable, and Miblo takes care of running the program. The official apps (miblo-apps) use exactly the routes you will use: there is no private door.
An app has three parts:
declaring the app (name, category, promise, settings, a preview);
reading its settings and reacting when the person changes one;
drawing its screen with a web page, the standard way since Miblo 1.45 (Page Desk apps), or with
screen.card()andscreen.layer(), the old and deprecated way (The App screen), or only sending alerts (Alert-only apps).
Apps need Miblo 1.30 or newer on the computer and on Miblo Desk (the SDK 2.x); reading the person's AI sessions (sessions) needs Miblo 1.34.
A page Desk app
In manifest.json, a page Desk app says "api": 5, "display": "page" and "page": "page.html" (a .html file of the folder). run() returns { data } (JSON, at most 16 KB) instead of a card, and Miblo hands that data to the page. It needs Miblo 1.45 (1.46 for api 5 and the render profiles) and cannot be alert-only (screen: false). The whole guide, with what a page cannot do, is Page Desk apps.
app()
const app = miblo.app({ id: 'weather', tool: 'weather' });app = miblo.app("weather", "weather")id: the app's id, lowercase letters, digits and-, up to 48 characters. Use the same one asmiblo apps add --id.tool: your program's name (a session'stoolrules). An app's settings belong to the program that declared it, by that name: another program getsnot_your_app. An app installed from the Desk App Store belongs to the package's name.
declare()
await app.declare({
name: { pt: 'Clima', en: 'Weather' },
category: 'daily',
promise: { pt: 'Vai chover?', en: 'Will it rain?' },
settings: [
{ key: 'city', label: { pt: 'Cidade', en: 'City' }, type: 'text', required: true, max: 40 },
{ key: 'units', label: { pt: 'Unidade', en: 'Units' }, type: 'select', options: ['°C', '°F'], default: '°C' },
{ key: 'peek', label: { pt: 'Avisar antes da chuva', en: 'Heads-up before rain' }, type: 'toggle', default: true },
],
preview: { v: 1, title: 'Weather', icon: 'cloud', items: [{ t: 'big', value: '24°', label: 'Recife' }] },
});app.declare(
{"pt": "Clima", "en": "Weather"},
settings=[
{"key": "city", "label": {"pt": "Cidade", "en": "City"}, "type": "text", "required": True, "max": 40},
{"key": "units", "label": {"pt": "Unidade", "en": "Units"}, "type": "select", "options": ["°C", "°F"], "default": "°C"},
{"key": "peek", "label": {"pt": "Avisar antes da chuva", "en": "Heads-up before rain"}, "type": "toggle", "default": True},
],
category="daily",
promise={"pt": "Vai chover?", "en": "Will it rain?"},
preview={"v": 1, "title": "Weather", "icon": "cloud", "items": [{"t": "big", "value": "24°", "label": "Recife"}]},
)| Field | Rules |
|---|---|
name | A string or { pt, en }, cut to 24 characters. Required. |
settings | The settings schema (below), up to 12. |
category | A short name for the Apps tab (a-z, 0-9, -, up to 24). The Desk App Store uses computer, money, daily, news-dev, sport, delights and other. |
promise | One line, { pt, en } or a string, cut to 100 characters: the question the app answers. |
preview | A card with sample data, shown in the Apps tab before the app runs. |
dwell | The seconds it suggests on the App screen (5 to 120); the person's choice wins. |
screen | false: an alert-only app, with no screen. |
alerts | What its alerts are about (a string or { pt, en }, 40 characters, shown when the person is asked), or its alert types (Alert-only apps). |
sessions | true: it reads the person's AI sessions with app.sessions(), once they allow it (Miblo 1.34). |
Returns { ok, id }. Declaring again replaces the schema and keeps every saved value still valid under it: declare on every start. Text longer than its limit is cut, not refused. At most 64 apps per computer (too_many_apps).
The settings schema
Each setting is { key, label, type, default?, required? } plus its type's fields.
type | Extra fields | Value |
|---|---|---|
text | max (1 to 200, default 100), suggest?, coords? | One line of text |
number | min?, max? | A number |
select | options: 1 to 2000 choices, each a string or { value, label }; max?; dependsOn? | One of the choices (a list with max above 1) |
toggle | (none; default false) | true or false |
url | (none) | An http:// or https:// address of up to 512 characters |
time | (none) | A HH:MM time (24 h); takes 22:00, 7:30 or 22h30 and always stores HH:MM. Miblo Hub shows a time picker |
connect | provider, clientId, scopes, clientSecret?, help? | The connected account (see Connecting accounts) |
key: starts with a lowercase letter, then letters, digits and_, up to 32 characters, unique.label: a string or{ pt, en }, cut to 40 characters.required:truemakes the app show as "needs setting up" while it has no value.default: must itself be a valid value of the type.group:"advanced"folds the setting under "Avançado" (Advanced) in Miblo Hub, for the ones almost nobody changes.Choices of a
select: avalueis up to 64 characters (no repeats), alabel(a string or{ pt, en }) is cut to 60; at most 6000 choices in one app.max(1 to 20) above 1 makes a multi-pick: the value is a list of at mostmaxdistinct choices.dependsOn: '<key>'names an earlier single-choice select, andoptionsis then a map from its values to lists ({ "bra.1": ["flamengo", ...] }).Type-ahead (
text):suggest: 'city'or'free'gets suggestions your running program answers withapp.settings.onSuggest(key, async (q) => [{ value, label }])(Pythonon_suggest);coords: true(only withsuggest: 'city') also takes"lat,lon"from Miblo Hub's "Use my location".placeholder(text,number,url,time): an example of what to type, a string or{ pt, en }of up to 40 characters, shown in the empty field. Where a list exists, declare aselect(load the list from its source and keep it 7 days); free text only where no list can exist, and then with the example.seed: a value your program carries over from an earlier version's settings (an old text split into new settings). Miblo saves it once, only where the person has no value yet, never keeps it in the schema, and ignores one that is not valid. A saved text whose parts are all choices of a multi-pickselectthat replaced it carries over by itself.No secrets. An app never asks the person for a key, a token or a password: there is no "password" type, and a key or label that looks like a secret (
token,password,senha,api_key,secret,chave,cookie,pin...) is refused (bad_request). Apps read public, account-free sources; for the person's own account, use aconnectsetting (Connecting accounts): Miblo signs them in with OAuth and your app never sees a password.
Reading the settings
settings.get()
const { values, missing, rev } = await app.settings.get();s = app.settings.get() # {"id", "values", "missing", "rev"}values: the defaults merged with what the person saved; a setting with neither isnull.missing: the required settings still without a value.rev: changes when the values do.
settings.request()
Asks the person now, with a reason (cut to 80 characters).
if (missing.length) await app.settings.request(missing, 'To show the forecast');if s["missing"]:
app.settings.request(s["missing"], "To show the forecast")What happens: Miblo Hub shows a setup card with the form and the reason, the phone says "Configure o app Weather no computador", and the app's screen on the Miblo shows "Configure no Miblo Hub" in its card's place. The request stands until the values change. Returns { ok, needsSetup }. The reason cannot start like one of Miblo's notices. It shares Miblo Desk actions' limit (say, focus, timer: 3 at once, then 1 every 10 s, for every program on the computer together): ask once, not in a loop.
settings.onChange() and settings.wait()
const stop = app.settings.onChange((values) => redraw(values)); // the person saved: redraw now
// ...
stop();stop = app.settings.on_change(lambda values: redraw(values)) # on a background thread
# ...
stop()onChange(cb, { onError, retryMs })callscb(values, answer)on every change (not for the current values) and returnsstop(). Errors go toonErrorand it keeps trying everyretryMs(default 5000). In Python:on_change(cb, on_error=None, retry=5.0), withcb(values).wait(rev?)is the piece underneath: it waits for the values to change fromrev, at most 20 s, and returns{ values, missing, rev }. At most 16 waits at once (busy).
The values stay on this computer (<Miblo's data>/apps/<id>.json, readable by your user only). From the terminal: miblo apps config <id> key=value.
Forms and a Desk app's own data
Since Miblo 1.48.0, with "api": 6. Use settings for a few simple values, forms when the Desk app needs screens or a list the person edits, and ctx.data for what those lists hold.
A form is data in manifest.json: Miblo Hub draws it from known components, with no HTML, script or regular expression of yours. It cannot ask for secrets or keys.
{
"api": 6,
"forms": [{
"id": "codigos",
"title": { "pt": "Minhas encomendas", "en": "My packages" },
"screens": [{
"id": "lista",
"title": { "pt": "Códigos", "en": "Codes" },
"children": [
{ "type": "list", "collection": "parcels", "item": "code", "note": "status",
"charset": "alnum-dash", "minLength": 8, "maxLength": 40, "max": 100, "upper": true,
"label": { "pt": "Cole os códigos", "en": "Paste the codes" } },
{ "type": "field", "key": "peek" }
]
}]
}]
}| Component | What it is |
|---|---|
heading, text | Words (text: {pt, en}) |
field | A setting of settings, by key, with its own validation |
list | Items the person pastes (commas, semicolons or new lines) or removes, kept in collection. charset: alnum, alnum-dash, digits or any. note is the field shown beside each item |
Any screen or component can carry visibleIf: { key, equals } on a setting. A Desk app holds up to 5 forms, each with up to 8 screens of 20 components; the Desk App Store checks the same rules. site_import also exists in the schema, but Miblo Hub does not show it yet.
Each item the person adds becomes a document: { code, addedAt, source } in this example. The Desk app reads the list and writes the note:
export async function run(ctx) {
const { items } = await ctx.data.list('parcels', { limit: 200 });
if (!items.length && !ctx.state.asked) {
ctx.state.asked = true;
await ctx.app.forms.open('codigos', { reason: 'Paste your tracking codes' });
}
for (const { id, value } of items) {
await ctx.data.patch('parcels', id, { status: 'on the way' }); // shows beside the item
}
return { data: { total: items.length } };
}| Call | What it does |
|---|---|
get(collection, id) | The value, or null |
list(collection, { limit, after }) | { items: [{ id, value, at }], next }, at most 200 a page |
put(collection, id, value) | Writes a document |
patch(collection, id, fields) | Merges fields; does nothing if the person removed it meanwhile |
delete(collection, id) | Removes a document |
batch(ops) | Up to 500 changes, all or none |
Limits: 16 KB a document, 5,000 documents, 5 MB and 32 collections per Desk app. Miblo keeps them in one sealed file (AES-256-GCM, key derived per Desk app) that the Desk app cannot open: only the program Miblo started holds this run's key, so the SDK token alone reads nothing (403 app_key_required), nor does another Desk app. There is no SQL and no file access. The seal protects a copied file, not the data from a program already running as this user.
In a program of your own the same calls are app.data and app.forms.open (@miblo/status 2.4.0; not in miblo-status for Python). What the person saves wakes the Desk app through settings.onChange() and settings.wait(); its own writes do not. Miblo Hub draws forms since 1.23.0, and Miblo Remote only says to set them up on the computer.
When the app's screen shows
The rotation: with several apps, the App screen shows one at a time, each for its own time:
miblo apps dwell <id> <seconds>(5 to 120; the default is what the app suggests when it declares itself,dwell, else 15 s). One time per app; there is no global one.When:
miblo apps when idle(the default: only when no AI session has been running, waiting or needing you for--idle-afterseconds, 60 by default, 10 to 3600),rotation(always in the rotation),request(only when an app asks for the screen withscreen.request(), for its own time, while nothing needs the person) ormanual(only pinned or in a peek). The person chooses; an app does not change it.Pin and peek still work with any choice; asking for the screen works with all but
manual. Miblo's alerts always come first.The limits are per computer, shared by every program and enabled official app: cards 2 a second (bursts of 5),
show1 every 10 s, peeks 1 every 10 s for all (and 1 every 10 minutes per program). While one program has its screen pinned (screen.show(true)), another program'sanimategetsanim_takenwithretryAfter.
The supervisor
miblo apps add "<command>" registers your program and miblo apps enable <id> keeps it running: Miblo starts it with the token, restarts it when it exits and keeps its output (miblo apps logs <id>). The step by step is in Install.
| Command | What it does |
|---|---|
miblo apps list [--json] | Every app, on or off, and which need setting up |
miblo apps enable / disable <id> | Turns it on or off |
miblo apps show <id> | State, restarts, command or hosts |
miblo apps logs <id> | The program's output (and what the sandbox blocked) |
miblo apps config <id> [key=value ...] | Shows or changes the settings |
miblo apps dwell [<id>|sessions|pet [<seconds>|default]] | Each app's time on the screen (and the sessions' and the pet's turn in the rotation) |
miblo apps order [<id>|sessions|pet <position>] | The rotation's order; --sessions-between on|off puts the sessions between two apps |
miblo apps when [rotation|idle|request|manual] [--idle-after <seconds>] | When the apps show |
miblo apps pin [<id> [always|idle|after <minutes>|window <HH-HH>]] / apps unpin | Keeps one app on the screen (always, when idle, after N minutes without AI sessions, or between two hours) |
miblo apps peek <id> | Its screen on the Miblo now, for 10 s |
miblo apps screen <id> on|off | Shows its screen or not (off: it runs only for its alerts) |
miblo apps alerts <id> [on|off|later] | Allows its alerts, refuses them, or asks again in 7 days (Alert-only apps) |
miblo apps sessions <id> [on|off|later] | Lets it see the AI sessions (or not) |
miblo apps connect|disconnect <id> <google|microsoft> | Connects or forgets an account |
miblo apps search [<words>] [--category <c>] | Searches the Desk App Store |
miblo apps install <id> | Installs an app from the Desk App Store (signed) |
miblo apps start | Starts the bridge and the apps that are on (Miblo Hub does it at launch) |
miblo apps remove <id> | Turns it off, takes its screen away and deletes its settings |
miblo screen status / clear | Shows or clears the App screen |
Only you, in your own terminal: miblo apps add, allowing an app's alerts (apps alerts <id> on) or its sessions (apps sessions <id> on) refuse to run inside an AI agent (Claude Code, Codex...). Type them yourself, or use Miblo Hub.
Connecting accounts
An app can read the person's own Google or Microsoft data (the official Agenda reads their calendar this way) without ever seeing a password or a refresh token: the Miblo bridge signs the person in, with OAuth 2.0 (Authorization Code + PKCE, as a desktop app), and your program only gets short-lived access tokens.
await app.declare({ name: 'Agenda', settings: [
{ key: 'google', label: { pt: 'Conectar Google', en: 'Connect Google' }, type: 'connect', provider: 'google',
clientId: '<your desktop client id>.apps.googleusercontent.com', clientSecret: '<Google\'s installed-app secret>',
scopes: ['https://www.googleapis.com/auth/calendar.readonly'],
help: { pt: 'Os eventos aparecem no Miblo em até 30 s', en: 'Events show on Miblo within 30 s' } },
] });
const { url } = await app.connect.start('google'); // the sign-in address (the Miblo app has the button)
const { accessToken, expiresAt, account } = await app.connect.token('google');
await fetch('https://www.googleapis.com/calendar/v3/users/me/calendarList', { headers: { authorization: `Bearer ${accessToken}` } });
await app.connect.off('google'); // disconnecturl = app.connect.start("google")["url"]
token = app.connect.token("google")["accessToken"] # MibloError "not_connected" until the person connects
app.connect.off("google")The
connectsetting says where to sign in:provider(googleormicrosoft, one setting each),clientId(your OAuth client: a Google "Desktop app" client or an Azure public client),scopes(1 to 8), Google'sclientSecretwhen it has one (Google issues one to desktop clients and documents it as not confidential; never for Microsoft) and an optionalhelpline (80 characters, under the button). It is never required and has no default; its value is the connected account (the e-mail),''until then, and only the bridge writes it. Sosettings.wait()wakes your program the moment the person connects or disconnects.connect.start(provider)returns{ provider, url }, the sign-in address. The bridge waits for exactly one redirect within 5 minutes on a loopback port of its own, checks itsstate, exchanges the code with the PKCE verifier and checks the id_token. The browser says "Conectado como ...". At most 4 sign-ins at once (busy).connect.token(provider)returns{ provider, accessToken, expiresAt, account }, a token with at least a minute left, refreshed when needed.not_connecteduntil the person connects (and again if the provider revokes access);unavailablewithretryAfterwhen the provider cannot be reached: try later, still connected.No
connectsetting for that provider:start,tokenandoffanswerno_connect_setting(404).connect.startandconnect.offshare Miblo Desk actions' limit (3, then 1 every 10 s);tokenis a read.connect.off(provider)forgets the account on this computer (miblo apps removedoes too).Who may: only the program that declared the app (
not_your_app), as with the settings.Where the tokens live: the refresh token is sealed (AES-256-GCM, under a key derived from the bridge key and bound to the app and provider) in
<Miblo's data>/apps/<id>/connect-<provider>.json; access tokens stay in the bridge's memory only. Nothing goes to miblo.ai.For the person: Miblo Hub's Desk apps tab shows a "Conectar Google" button, then "Conectado como ... · Desconectar". From a terminal:
miblo apps connect <id> googleandmiblo apps disconnect <id> google.
Recipe: YouTube subscribers
A YouTube channel's subscriber count, read with the person's own Google account (no API key in the app):
In the Google Cloud console, create a project, enable the YouTube Data API v3, set up the OAuth consent screen and create an OAuth client of type Desktop app. Copy its client id and client secret (Google documents a desktop client's secret as not confidential).
Declare a
connectsetting with the read-only scope, and read the count with the access token Miblo hands you:
import { MibloStatus } from '@miblo/status';
const miblo = new MibloStatus();
const app = miblo.app({ id: 'youtube-subs', tool: 'YouTube' });
await app.declare({ name: 'YouTube', settings: [
{ key: 'youtube', label: { pt: 'Conectar YouTube', en: 'Connect YouTube' }, type: 'connect', provider: 'google',
clientId: '<your client id>.apps.googleusercontent.com', clientSecret: '<your client secret>',
scopes: ['https://www.googleapis.com/auth/youtube.readonly'] },
] });
const screen = miblo.screen({ tool: 'YouTube' });
for (;;) {
try {
const { accessToken } = await app.connect.token('google');
const r = await fetch('https://www.googleapis.com/youtube/v3/channels?part=statistics&mine=true',
{ headers: { authorization: `Bearer ${accessToken}` } });
if (!r.ok) throw new Error(`YouTube answered ${r.status}`);
const subs = Number((await r.json()).items?.[0]?.statistics?.subscriberCount ?? 0);
await screen.card({ v: 1, title: 'YouTube', items: [{ t: 'big', value: subs.toLocaleString('en-US'), label: 'subscribers' }] });
} catch (e) {
if (e.code === 'not_connected') { await app.settings.wait(); continue; } // wakes when the person connects (20 s at most)
console.error(e.code ?? e.message);
}
await new Promise((r) => setTimeout(r, 10 * 60_000)); // every 10 minutes
}Then the person presses Connect YouTube in Miblo Hub's Desk apps tab (or runs miblo apps connect youtube-subs google).
Quota: each Google Cloud project gets 10,000 units a day.
channels.listandvideos.listcost 1 unit a call;search.listcosts 100, so avoid it. One read every 10 minutes is 144 units a day.
The community apps' sandbox
An app from the Desk App Store may carry code written by someone else. It reaches a computer only after the automatic scan, the AI review and a human's approval (Publish to the Desk App Store), and runs in a sandbox:
Files: it reads only its own package, its own state folder and the Miblo runtime; it writes only its state folder. It uses Node's permission model (
--permission).No processes or native code: no child processes, worker threads, native addons or WASI.
Blocked modules:
http,https,http2,net,tls,dgram,dns,child_process,cluster,worker_threads,vm,module,wasi,inspector,repl,v8,trace_eventsandsqlite. The app imports only files of its own package and Node's other built-ins; code it writes to its state folder cannot be imported.Network only through Miblo's
fetch, and only to the hosts declared innetwork: https on the default port, redirects followed under the same rule, 10 s a call, 256 KB an answer, 30 calls a minute.WebSocket,EventSourceandXMLHttpRequestare gone.The SDK token leaves the environment before the app loads; only the client keeps it.
Everything blocked becomes a line
blocked: ...inmiblo apps logs <id>, even when the app catches the error.The Desk App Store has the last word: at every start and every hour the package is checked again; an app the Desk App Store no longer serves or has hidden is turned off.
Updates (1.37.0): a newer version whose access (hosts, sessions, alerts) is the same is installed by itself; one that asks for more shows "Update available" and waits for the person to agree (Miblo Hub, or
miblo apps install <id>in a terminal).Memory and CPU (1.37.0): the app's JavaScript heap is capped at 128 MB, and one that keeps a CPU core busy for 2 minutes is stopped (macOS and Linux); both count as a crash and it is started again later.
It needs Node 22.15+, 23.5+ or 24+. Miblo picks one by itself: the bridge's own Node, else
MIBLO_NODE(the path to anode), else one on thePATHor in the usual places (Homebrew, nvm, fnm, Volta...). With none, the app does not run (stateunsupported, with the reason in its log).
Headers: Miblo's
fetchsends what the app gives it; thectx.fetchJson/fetchTexthelpers take onlyauthorization,accept,accept-language,if-none-matchandif-modified-since(Publish).Errors and retries: each failure is a line in the log with the reason (a refused card's field, the error's file and line, the HTTP status with an excerpt free of secrets), and the app tries again in 5 s, 10, 20..., never past its own
intervalMs(at least 10 s after a 4xx), so an API's quota is not spent.
What the sandbox does not guarantee: the network is held by the replaced fetch and the module control, not by the operating system, and an app can use CPU and memory and send its hosts what Node gives any program (the time, the locale, the computer's name). That is why a human reviews every version first.