Functions
downloads.register
function downloads.register(input: DownloadDeclaration): void;
Declares a download mirror or source as data: the game makes every request itself, only to the hosts you list, and your script never touches the network or the player's token. Only mods call it, only from setup, and the mod must declare permissions: ["network"]; the player can take that permission away from the Mods page, which withdraws the declaration at once.
kind: "mirror" serves osu! beatmapsets (target: "osu"): it must page by offset or page, download.url must contain {id} and nothing else, and its results have a numeric id. kind: "source" has a tab of its own: it needs search and either download.url (with {id}) or download.urlField (a path in the listed result, with the mapped response format). search.params are templates over 18 variables ({query}, {status}, {sort}, {offset}, {page}, {limit}, {cursor}, {keysMin}, {keysMax}, {starsMin}, {starsMax}, {bpmMin}, {bpmMax}, {lengthMin}, {lengthMax}, {genre}, {language}, {id}); a group in brackets is written only when every variable inside has a value, and \ escapes \ [ ] { }.
auth: { kind: "token" } makes the game ask the player for a token and send it itself. header is Authorization (default), X-API-Key or X-Auth-Token; scheme is up to 16 letters (Bearer for Authorization by default, "" sends the token alone); scope is all (default: search and download) or download (the file requests only). The token is 8 to 4096 visible characters.
| Limit | Value |
|---|---|
| Declarations per mod / all mods | 4 / 64 |
id |
a-z, 0-9, -, 1 to 32 characters |
name / description |
up to 32 / up to 200 characters |
hosts |
1 to 8 lowercase DNS names with at least two labels; no IP address, no port, no local, localhost, internal, lan, intranet, home, corp, *.home.arpa |
| URLs and templates | https only, plain ASCII, up to 256 characters, on a declared host |
rateLimit |
1 to 120 requests per minute (30 by default) |
search.paging.size |
1 to 100; search.params up to 16 entries |
| JSON paths | up to 128 characters and 8 steps; a key is up to 48 characters |
downloads.register({
id: "mirror",
name: "Example mirror",
kind: "mirror",
target: "osu",
hosts: ["mirror.example.org"],
search: {
url: "https://mirror.example.org/api/search",
params: { query: "{query}", amount: "{limit}", offset: "{offset}" },
paging: { kind: "offset", size: 20 },
response: { format: "osu" },
},
download: { url: "https://mirror.example.org/d/{id}" },
});
Errors you will see: `downloads.register` needs the `network` permission: declare `permissions: ["network"]`, a mod registers at most 4 downloads, download id is registered twice, host "x": local names are never allowed, a mirror names the source it serves: target: "osu", a source needs `search`: it lists the sets of its tab, download has `url` or `urlField`, not both, rateLimit is 1 to 120 requests per minute, auth.header is one of Authorization, X-API-Key, X-Auth-Token. See Adding a download source.
downloads.registerBridge
function downloads.registerBridge(input: BridgeDefinition): void;
Adapts a site whose API does not fit downloads.register: you write pure functions that compute the next step, the host does every request. Only mods call it, only from setup, with the network permission; the header fields (id, name, description, site, hosts, rateLimit, auth) follow the rules of downloads.register. A bridge is always a source with its own tab.
search(query, page, state) starts a search (page is 1 for the first page). onResponse(response, state) receives each answer as text; action(result, actionId, state) runs when the player presses one of a result's buttons. Each returns a step with exactly one of request, results, download and error. request makes the host perform it and call onResponse; results ends a search (nextPage, a string or a number of up to 128 characters, asks for another page); download ends an action with the file to fetch (format is zip, osz or qp, filename up to 128 characters); error shows a message of up to 200 characters. state is any JSON up to 8 KiB, handed back to the next function.
A request takes method (GET or POST), headers, and one of body (a string), form or json, plus expect (json, text, xml, html) for how the answer is checked. Answers arrive as text: parse XML and HTML with strings and regular expressions. A BridgeResult carries id, title, artist, optional creator, coverUrl, tags, size, keyCount, details, up to 4 actions, and data, a string of up to 1024 characters the game hands back to action as result.data.
| Bound | Value |
|---|---|
| Requests per search or action | 6, within 60 seconds |
| Answer text handed to the script | 2 MiB (a larger one is an error, never cut) |
| Request body | 64 KiB; URL up to 2048 bytes; up to 12 headers |
| One step as JSON | 256 KiB; results per step up to 100 |
| Header names a script may set | accept, accept-language, content-type, referer, origin, x-requested-with, x-api-key, x-auth-token, authorization, if-none-match |
The token is added by the host and never given to your functions; an answer that repeats it is scrubbed. Failures show up as a step has exactly one of `request`, `results`, `download` and `error` , needed more than 6 requests, `state` is at most 8 KiB of JSON, `nextPage` goes with `results`, returned results where a download was expected. The complete example content/examples/mods/download-bridge/main.ts is the reference; see Adding a download source.
skinImport.close
function skinImport.close(input: void): void;
Closes your panel and drops the picked source and the preparation, like the player's dismiss. Skins your importer already created stay (and stay valid targets of editSkin). It needs the skinImport permission; call it from an event handler when the job is over or abandoned. It takes no argument and returns nothing.
ctx.on("skinImport.action", (action) => {
if (action.id === "cancel") skinImport.close();
});
skinImport.create
function skinImport.create(input: SkinImportCreate): number | null;
Writes the staged skin as a new folder of the player's skins directory; it never replaces a skin that exists. stageId is the one skinImport.staged gave and must still be the current preparation. It returns a request number, or null while another job runs. The result arrives as a skinImport.created event with the new skin's id, or an error; the new folder goes through the same inspection as an installed skin first.
ctx.on("skinImport.staged", (staged) => {
if (staged.stageId != null && staged.report && !staged.report.overBudget) skinImport.create({ stageId: staged.stageId });
});
ctx.on("skinImport.created", (created) => {
if (created.id) skinImport.panel({ title: "Done", status: "done", actions: [{ id: "open", label: "Edit", primary: true, editSkin: created.id }] });
});
Errors you will see: nothing was prepared, this preparation is not the current one.
skinImport.panel
function skinImport.panel(input: ImportPanelDefinition): void;
Shows or updates the progress panel of your importer on the Skins page: a declarative description, never HTML. Call it from an event handler (skinImport.opened, skinImport.staged, skinImport.created) after an importer is registered; calling it again replaces the panel and re-draws only if it changed. status is working, ready, done or error.
| Limit | Value |
|---|---|
title |
1 to 96 characters |
| Sections / rows per section / parts per row | 6 / 24 / 8 |
| Notes / actions | 48 / 4 |
| Badges / tiles | 16 / 6 |
icon |
one of 30 names (palette, image, images, package, ruler, gauge, circle-check, triangle-alert, …) |
Action id |
a-z, 0-9, _, 1 to 32 characters, unique; dismiss is the game's |
An action with editSkin opens that skin in the editor; it must name a skin this importer created. When the player presses an action, you get a skinImport.action event with its id; dismiss closes the panel itself.
skinImport.panel({
title: "Converting",
status: "working",
detail: "Reading the pictures",
badges: [{ text: "osu!", tone: "info" }],
actions: [{ id: "cancel", label: "Cancel" }],
});
Errors you will see: register an importer in `setup` before showing a panel, a panel has at most 6 sections, 48 notes and 4 actions, a panel has at most 16 badges and 6 tiles, a section has at most 24 rows, a row has at most 8 parts, a tile meter needs a finite `value` of 0 or more and a `max` above 0, `editSkin` names "x", which this importer did not create.
skinImport.register
function skinImport.register(input: ImporterDeclaration): void;
Registers a skin importer, the entry the player sees in the Skins page to convert a skin of another game into a Prism skin. It needs the skinImport permission in defineMod and works only from setup. The player picks the folder or archive (the game opens the dialog, never the mod); a native worker reads it, and your script only receives the parsed data (skinImport.opened) and answers with values.
id is 1 to 32 characters among a-z, 0-9, -, _, and starts with a letter or a digit. name is 1 to 64 characters, description up to 256. sources lists folder, archive or both, once each. localized gives name and description for en, fr, zh and ko. A mod registers at most 4 importers, with distinct ids.
skinImport.register({
id: "my-converter",
name: "My converter",
description: "Converts a skin folder or archive.",
localized: { fr: { name: "Mon convertisseur" } },
sources: ["folder", "archive"],
});
Errors you will see: `skinImport` needs the `skinImport` permission: declare `permissions: ["skinImport"]`, `skinImport.register` is only available in a mod's setup, importer id "X" must be 1 to 32 characters among a-z, 0-9, `-`, `_` , an importer lists `folder`, `archive` or both, once each, a mod registers at most 4 importers, with distinct ids. See Importing a skin.
skinImport.stage
function skinImport.stage(input: StageRequest): number | null;
Prepares the conversion: you give a SkinDescription (the skin's id, name, layouts, lanes and HUD values) and a list of picture operations (source, dest as a .png path, optional animation, frame, crop, fit, stretch); the native worker builds the pictures and measures them. It returns a request number, or null when a job is already running. The result arrives as a skinImport.staged event: report lists every file, totalBytes, budgetBytes (900 KiB) and overBudget, plus problems, and stageId for skinImport.create.
sourceId must be the one skinImport.opened gave. The skin may name at most 8 layouts and every picture it references must be produced by an operation; fit and stretch exclude each other, and a picture over the side or byte limit needs one of them. A job allows up to 256 pictures.
ctx.on("skinImport.opened", (opened) => {
if (!opened.source) return;
skinImport.stage({
sourceId: opened.source.sourceId,
skin: { id: "converted", name: "Converted", layouts: [{ keys: 4, lanes: [{}, {}, {}, {}] }] },
images: [],
});
});
Errors you will see: no source was picked, this source is not the one the player picked, a skin describes 1 to 8 layouts, not 9, 300 pictures requested; the limit is 256, two images write x.png, `fit` and `stretch` are exclusive, x.png would weigh … bytes; the limit is …: add `fit` .
Types
Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.
type DownloadDeclaration = {
id: string;
name: string;
description?: string | null;
site?: string | null;
kind: DownloadKind;
target?: DownloadTarget | null;
hosts: string[];
rateLimit?: number | null;
auth?: DownloadAuth | null;
search?: SearchSpec | null;
download: DownloadSpec;
};
type DownloadKind = "mirror" | "source";
type DownloadTarget = "osu";
type DownloadAuth = {
kind: AuthKind;
header?: string | null;
scheme?: string | null;
scope?: AuthScope | null;
};
type AuthKind = "none" | "token";
type AuthScope = "download" | "all";
type SearchSpec = {
url: string;
params?: Record<string, string>;
sorts?: Record<string, string>;
statuses?: Record<string, string>;
paging?: PagingSpec | null;
response: ResponseSpec;
};
type PagingSpec = {
kind: PagingKind;
size: number;
first?: number | null;
};
type PagingKind = "offset" | "page" | "cursor";
type ResponseSpec = {
format: ResponseFormat;
results?: string | null;
total?: string | null;
nextCursor?: string | null;
item?: ItemSpec | null;
};
type ResponseFormat = "osu" | "mapped";
type ItemSpec = {
id: string;
title: string;
artist?: string | null;
creator?: string | null;
status?: string | null;
bpm?: string | null;
playCount?: string | null;
favourites?: string | null;
cover?: string | null;
difficulties?: DifficultySpec | null;
};
type DifficultySpec = {
path: string;
name?: string | null;
keys: string;
stars?: string | null;
length?: string | null;
only?: OnlySpec | null;
};
type OnlySpec = { path: string; equals: string; };
type DownloadSpec = { url?: string | null; urlField?: string | null; };
type BridgeDefinition = {
id: string;
name: string;
description?: string | null;
site?: string | null;
hosts: string[];
rateLimit?: number | null;
auth?: DownloadAuth | null;
search: BridgeSearch;
onResponse?: BridgeOnResponse;
action?: BridgeAction;
};
type BridgeSearch = (query: string, page: unknown, state: unknown) => BridgeStep;
type BridgeStep = {
request?: BridgeRequest | null;
results?: BridgeResult[] | null;
download?: BridgeDownload | null;
error?: string | null;
nextPage?: unknown | null;
state?: unknown | null;
};
type BridgeRequest = {
url: string;
method?: BridgeMethod | null;
headers?: Record<string, string> | null;
body?: string | null;
form?: Record<string, string> | null;
json?: unknown | null;
expect?: BridgeExpect | null;
};
type BridgeMethod = "GET" | "POST";
type BridgeExpect = "json" | "text" | "xml" | "html";
type BridgeResult = {
id: unknown;
title: string;
artist: string;
creator?: string | null;
coverUrl?: string | null;
tags?: string[] | null;
size?: string | null;
keyCount?: number | null;
details?: ResultDetail[] | null;
actions?: ResultAction[] | null;
data?: string | null;
};
type ResultDetail = { label: string; value: string; };
type ResultAction = { id: string; label: string; };
type BridgeDownload = {
url: string;
method?: BridgeMethod | null;
headers?: Record<string, string> | null;
body?: string | null;
form?: Record<string, string> | null;
json?: unknown | null;
filename?: string | null;
format: BridgeFormat;
};
type BridgeFormat = "zip" | "osz" | "qp";
type BridgeOnResponse = (response: BridgeResponse, state: unknown) => BridgeStep;
type BridgeResponse = {
status: number;
headers: Record<string, string>;
text: string;
};
type BridgeAction = (result: BridgeActionResult, actionId: string, state: unknown) => BridgeStep;
type BridgeActionResult = {
id: string;
title: string;
artist: string;
data?: string | null;
};
type SkinImportCreate = { stageId: number; };
type ImportPanelDefinition = {
title: string;
status: PanelStatus;
detail?: string | null;
icon?: string | null;
badges?: PanelBadge[];
tiles?: PanelTile[];
sections?: PanelSection[];
notes?: PanelNote[];
actions?: PanelAction[];
};
type PanelStatus = "working" | "ready" | "done" | "error";
type PanelBadge = {
text: string;
tone: PanelTone;
icon?: string | null;
};
type PanelTone = "ok" | "warn" | "info" | "bad";
type PanelTile = {
label: string;
value: string;
icon?: string | null;
tone?: PanelTone | null;
meter?: PanelMeter | null;
hint?: string | null;
};
type PanelMeter = { value: number; max: number; };
type PanelSection = { heading: string; rows: PanelRow[]; };
type PanelRow = {
label: string;
value: string;
icon?: string | null;
tone?: PanelTone | null;
parts?: PanelPart[] | null;
};
type PanelPart = { text: string; icon?: string | null; };
type PanelNote = {
level: NoteLevel;
text: string;
icon?: string | null;
};
type NoteLevel = "info" | "warning" | "error";
type PanelAction = {
id: string;
label: string;
primary?: boolean | null;
editSkin?: string | null;
};
type ImporterDeclaration = {
id: string;
name: string;
description?: string | null;
localized?: Record<string, ImporterText>;
sources: SourceKind[];
};
type ImporterText = { name: string; description?: string | null; };
type StageRequest = {
sourceId: number;
skin: SkinDescription;
images: ImageOp[];
};
type SkinDescription = {
id: string;
name: string;
version?: string | null;
author?: string | null;
description?: string | null;
playfield?: PlayfieldSpec;
layouts: SkinLayout[];
hud?: SkinHud;
};
type SkinLayout = {
keys: number;
playfield?: PlayfieldSpec;
lanes: LaneSpec[];
};
type SkinHud = { judgementY?: number | null; comboY?: number | null; };
type ImageOp = {
source: string;
dest: string;
animation?: boolean;
frame?: number | null;
crop?: PixelBox | null;
fit?: ImageBox | null;
stretch?: ImageSize | null;
additive?: boolean;
file?: string | null;
turn?: number | null;
};
type ImageBox = { maxWidth: number; maxHeight: number; };
type ImageSize = { width: number; height: number; };
Defined elsewhere
SourceKind (declarations), PlayfieldSpec (game), PlayfieldAnchor (game), ScrollDirection (game), SpriteSize (game), HitLightOn (game), TextureFilter (game), HoldMissedStyle (game), NoteSnapMax (game), NoteSnapTintMode (game), NoteSnapEnd (game), MeasureLineLength (game), JudgementLineAt (game), LaneSpec (game), PixelBox (declarations)