Generated from the SDK source (v0.8.0) by
bun run build:docs
Everything below is available on loader.SDK.
Process
Base class of every plugin. A plugin's default export extends Process and
implements Process#exec; the host constructs it with
(process_id, account, access_token_id) and calls Process#start.
It runs isolated: on the server in a sandboxed child process, in the
browser in a sandboxed iframe — never in the dashboard page. It has no DOM
of the dashboard; its settings come from this.options.obj, its UI is its
menu (menu.html and the module's optional views, in a sandboxed frame),
and requests to the dashboard go through loader.SDK.ui.
Instance methods the dashboard may call (e.g. its chat dialog asking for
an AI reply) must be listed in a static callable array. Night itself
looks for a few optional ones:
regenerate_reply(draft): a new text for a reply drafted for reviewmember_profile(sender_id): the full profile for the chat dialog, when a log row stores only a slim copy (partial: true)conversation(sender_id): a ChatThread (Chat.get_thread). Messengers show it under an entry opened from a notification list. Several entries of one event logged within a few seconds arrive as one list.
The instance doubles as the request context for platform calls:
Manyvids.Account.get_me({}, this) or Manyvids.bind(this).Account.get_me().
new Process(id: string, account: Account, access_token_id: string)
| Member | Description |
|---|---|
id: string | |
account: Account | |
access_token_id: string | |
error: string | Message of the error that stopped the process, if one did |
created_at: Date | |
plugin: any | |
server: boolean | Whether this process runs on the server and should register with the API on start. Set via Process._env.server (injected by createSDK). |
options: { obj: Record<string, any>; } | The plugin's settings form. options.obj is the current settings object (on the server, the settings the process was started with). |
template_id: any | |
state: ProcessState | |
before_start(fn) → Process | Runs before Process#exec on every start (browser and server). |
after_start(fn) → Process | Runs after Process#exec resolves. |
on_activation(fn) → Process | Runs in the browser after the user activates the process (local and server runs alike), before its settings are submitted — the place for work that needs the user's machine, e.g. uploading picked files (file fields arrive in this.options.obj as File objects here). Return an object to add it to the run's settings (e.g. the uploaded files' keys): that's what a server run, or a later restart, gets to see. |
on_state_change(fn) → Process | |
on_error(fn) → Process | |
query_log(filter, since_ms) → Promise<boolean> | Whether a log entry matching filter was recorded, optionally within the last since_ms milliseconds — the building block for "skip users already messaged in the last N days" style checks. Scope: every process of this plugin run by the same user (cross-process / cross-account dedup). An event the manifest lists in log.shared, queried with only event + main_data, looks at every user's runs of the plugin instead — e.g. "has anyone messaged this member in the last N days". Put process_id: this.id in the filter to only look at this process. Runs through the same server handler in the browser and in a server worker, so a check behaves identically in both. |
save_state() → any | What the run needs to continue where it left off, as plain JSON data (up to 1 MB, kept for a day). Only called at a Process#checkpoint. Override together with Process#restore_state and Process.state_version. |
restore_state(state) → any | Called instead of starting over when a run is continued: after the constructor, before start(). Throwing ends the run, and its saved state. |
checkpoint(opts) → void | Marks a safe point: everything before it is done and Process#save_state describes what's left. Call it at the end of each step; a run stopped, failed or cut off by a restart continues from the last one. Taken at most every 5 seconds, so it's cheap to call often; pass now: true after anything that must not be repeated (e.g. a sent message). A run that ends by itself leaves nothing to continue. |
fail(err, log) → void | Stops the process because of an error. Errors in a running process usually mean something is broken beyond the current item (dead session, rate limit, platform change), so carrying on only piles up failures: catch, call this.fail(e), and let the loop see state === 'stopped'. Records the error as an error entry on log (default: the process' first log), sets Process#error, moves to 'stopped' and runs the Process#on_error hooks. Later calls (e.g. from parallel loops failing on the same cause) only reach the console. |
exec() → Promise<any> | The plugin's main loop. Override in the plugin class. |
start() → Promise<boolean> | |
dispose() → void | Releases everything the SDK holds for this process (store entries, its Stats, hook closures). Call when a stopped process is discarded. |
Stats
A named event log owned by a process. Every Stats#add is counted
per event in Stats#simple_data, rendered in the process page's
log table, and persisted server-side — in batches (see LogBuffer.js), so an
entry reaches the server within a few seconds, and at the latest when the
process stops.
this.output_log = new Stats(this.id, 'output');
this.output_log.add({ event: 'p_follower', main_data: user.handle });
this.output_log = new Stats(this.id, 'output');
this.output_log.add({ event: 'p_follower', main_data: user.handle });
new Stats(process_id: string, name: string)
| Member | Description |
|---|---|
name: string | |
process_id: string | |
data: LogData[] | The most recent entries (capped at 100). |
process: Process | |
simple_data: {} | |
owned: boolean | Whether this log's entries are produced in this context. The server echoes every entry back over the process stream; an owned log already has them and must not add them again. |
add(entry, silent) → void | |
add_bulk(entries) → void | Add multiple entries at once. |
clear() → void |
SdkError
The single error type thrown by every platform API method.
try {
await Manyvids.Content.get_video({ video_id: 123 }, this);
} catch (e) {
if (e instanceof loader.SDK.SdkError && e.code === 'TRANSPORT') retry_later();
}
try {
await Manyvids.Content.get_video({ video_id: 123 }, this);
} catch (e) {
if (e instanceof loader.SDK.SdkError && e.code === 'TRANSPORT') retry_later();
}
new SdkError(message: string, __1: { code?: SdkErrorCode; platform?: string; operation?: string; response?: unknown; cause?: unknown; })
| Member | Description |
|---|---|
name: string | |
code: SdkErrorCode | |
platform: string | |
operation: string | |
response: unknown | |
toJSON() → { name: string; code: SdkErrorCode; message: string; platform: string; operation: string; } | Error's own message is non-enumerable, so without this a thrown SdkError logged via Stats#add (JSON-serialised) would arrive as {}. |
toString() → string | Returns a string representation of an object. |
message: string | |
stack: string | |
cause: unknown |
Account
new Account(obj: { access_token_id: string; username: string; extra: any; night_module: NightModuleClient; })
| Member | Description |
|---|---|
access_token_id: string | |
username: string | |
night_module: NightModuleClient | |
extra: any | |
id: string | |
domain: string | |
process: Process | |
parent: AccountStore |