@@ -5,60 +5,149 @@ For a practical authoring guide, see [Creating a Plugin](creating.md).
55
66## Manager API
77
8- - ` #!ts plugins:add(name: string, struct: table): plugin.class `
8+ - ` #!ts plugins:add(name: string, struct: table): plugin.class ` \
99 Registers a plugin definition, creates ` config.Plugins.<name> ` , and returns the registered plugin class.
1010
11- - ` #!ts plugins:enable(name: string): boolean, ... `
11+ - ` #!ts plugins:enable(name: string): boolean, ... ` \
1212 Enables a registered plugin if it is not already active.
1313
14- - ` #!ts plugins:disable(name: string): boolean, ... `
14+ - ` #!ts plugins:disable(name: string): boolean, ... ` \
1515 Disables an active plugin instance.
1616
17- - ` #!ts plugins:remove(name: string): boolean, ... `
17+ - ` #!ts plugins:remove(name: string): boolean, ... ` \
1818 Disables the plugin if needed and removes it from the registry.
1919
20- - ` #!ts plugins:get(name: string): plugin.class | false `
20+ - ` #!ts plugins:get(name: string): plugin.class | false ` \
2121 Returns the registered plugin class.
2222
23- - ` #!ts plugins:list(): table `
23+ - ` #!ts plugins:list(): table ` \
2424 Returns the registry table.
2525
2626## Base Plugin Methods
2727
2828Every registered plugin inherits from the base ` plugin ` class.
2929
30- - ` #!ts plugin:constructor() `
30+ - ` #!ts plugin:constructor() ` \
3131 Called when the plugin is enabled.
3232
33- - ` #!ts plugin:destructor() `
33+ - ` #!ts plugin:destructor() ` \
3434 Called when the plugin is disabled.
3535
36- - ` #!ts plugin:active(): boolean `
36+ - ` #!ts plugin:active(): boolean ` \
3737 Returns whether the plugin instance is active.
3838
39- - ` #!ts plugin:disable() `
40- Shortcut for ` plugins:disable(self.name) ` .
39+ - ` #!ts plugin:disable() ` \
40+ Shortcut for ` #!ts plugins:disable(self.name)` .
4141
42- - ` #!ts plugin:enable() `
43- Shortcut for ` plugins:enable(self.name) ` .
42+ - ` #!ts plugin:enable() ` \
43+ Shortcut for ` #!ts plugins:enable(self.name)` .
4444
45- - ` #!ts plugin:remove() `
46- Shortcut for ` plugins:remove(self.name) ` .
45+ - ` #!ts plugin:remove() ` \
46+ Shortcut for ` #!ts plugins:remove(self.name)` .
4747
48- - ` #!ts plugin:transport(): table `
48+ - ` #!ts plugin:transport(): table ` \
4949 Returns transport-safe plugin information.
5050
51- - ` #!ts plugin:add_hook(name: string, id: string, callback: function) `
51+ ### Dispatcher Tracking
52+
53+ - ` #!ts plugin:create_dispatcher(name: string): dispatcher.object ` \
54+ Creates a new dispatcher object.
55+
56+ - ` #!ts plugin:add_dispatcher(handle: dispatcher, callback: function, id?: string): dispatcher.handle ` \
57+ Connects a callback to a dispatcher and tracks the ` dispatcher.handle ` for automatic cleanup. Uses ` <plugin>.<id> ` as the identity.
58+
59+ - ` #!ts plugin:remove_dispatcher(handle: dispatcher, id?: string): boolean ` \
60+ Disconnects a tracked dispatcher handle.
61+
62+ - ` #!ts plugin:clear_dispatchers() ` \
63+ Disconnects all tracked dispatcher connections for the plugin instance.
64+
65+ ### Hook Tracking
66+
67+ - ` #!ts plugin:add_hook(name: string, id: string, callback: function) ` \
5268 Adds a tracked hook using ` <plugin>.<id> ` as the final hook ID.
5369
54- - ` #!ts plugin:remove_hook(name: string, id: string) `
70+ - ` #!ts plugin:remove_hook(name: string, id: string) ` \
5571 Removes one tracked hook.
5672
57- - ` #!ts plugin:clear_hooks() `
73+ - ` #!ts plugin:clear_hooks() ` \
5874 Removes all tracked hooks for the plugin instance.
5975
60- - ` #!ts plugin:clean() `
61- Runs cleanup logic. Currently this clears tracked hooks.
76+ ### Timer Tracking
77+
78+ - ` #!ts plugin:simple_timer(delay: number, callback: function) ` \
79+ Creates a one-shot timer with an auto-generated identity. Automatically unregisters after firing.
80+
81+ - ` #!ts plugin:add_timer(id: string, delay: number, reps: number, callback: function) ` \
82+ Creates a tracked timer using ` <plugin>.<id> ` as the identity. Use ` 0 ` reps for infinite repetition.
83+
84+ - ` #!ts plugin:exist_timer(id: string): boolean ` \
85+ Returns whether a tracked timer exists.
86+
87+ - ` #!ts plugin:toggle_timer(id: string): boolean ` \
88+ Toggles a tracked timer between paused and running.
89+
90+ - ` #!ts plugin:pause_timer(id: string): boolean ` \
91+ Pauses a tracked timer.
92+
93+ - ` #!ts plugin:unpause_timer(id: string): boolean ` \
94+ Unpauses a tracked timer.
95+
96+ - ` #!ts plugin:repsleft_timer(id: string): number ` \
97+ Returns remaining repetitions for a tracked timer.
98+
99+ - ` #!ts plugin:timeleft_timer(id: string): number ` \
100+ Returns remaining time until the next tick of a tracked timer.
101+
102+ - ` #!ts plugin:adjust_timer(id: string, delay: number, reps?: number, callback?: function) ` \
103+ Adjusts the delay, repetitions, or callback of an existing tracked timer.
104+
105+ - ` #!ts plugin:stop_timer(id: string) ` \
106+ Stops a tracked timer.
107+
108+ - ` #!ts plugin:start_timer(id: string) ` \
109+ Starts a stopped tracked timer.
110+
111+ - ` #!ts plugin:remove_timer(id: string) ` \
112+ Removes a tracked timer. Also aliased as ` destroy_timer ` .
113+
114+ - ` #!ts plugin:clear_timers() ` \
115+ Removes all tracked timers for the plugin instance.
116+
117+ !!! note
118+ ` create_timer ` is an alias for ` add_timer ` .\
119+ ` destroy_timer ` is an alias for ` remove_timer ` .
120+
121+ ### HTTP Tracking
122+
123+ - ` #!ts plugin:http(url: string, callback: function, options?: table): request ` \
124+ Performs an HTTP request with automatic retry support.\
125+ Returns a request handle that can be cancelled.\
126+ The callback receives ` (code, body, headers) ` on success or ` (false, reason) ` on failure.\
127+ Requests are automatically ignored if the plugin becomes inactive.
128+
129+ ** Options table:**
130+
131+ | Field | Type | Default | Description |
132+ | -------------| ----------| ---------| --------------------------------|
133+ | ` retry ` | ` number ` | ` 1 ` | Number of retry attempts |
134+ | ` method ` | ` string ` | ` "GET" ` | HTTP method |
135+ | ` body ` | ` string ` | ` nil ` | Request body |
136+ | ` type ` | ` string ` | ` nil ` | Content type |
137+ | ` timeout ` | ` number ` | ` nil ` | Request timeout |
138+ | ` headers ` | ` table ` | ` {} ` | Request headers |
139+ | ` parameters ` | ` table ` | ` {} ` | URL query parameters |
140+
141+ - ` #!ts plugin:cancel_http(request: table) ` \
142+ Cancels a tracked HTTP request so its callback will not fire.
143+
144+ - ` #!ts plugin:clear_https() ` \
145+ Cancels all tracked HTTP requests for the plugin instance.
146+
147+ ### Cleanup
148+
149+ - ` #!ts plugin:clean() ` \
150+ Runs full cleanup: clears tracked dispatchers, hooks, timers, and HTTP requests.
62151
63152## Loader Behavior
64153
@@ -108,19 +197,14 @@ Failure behavior:
108197When ` plugins:disable(name) ` runs, the runtime:
109198
1101991 . Calls ` plugin:destructor() ` .
111- 2 . Calls ` plugin:clean() ` which clears tracked hooks.
200+ 2 . Calls ` plugin:clean() ` which clears tracked dispatchers, hooks, timers, and HTTP requests .
1122013 . Removes the client interface if one was mounted.
1132024 . Removes the runtime client/language config containers for that plugin.
1142035 . Removes dynamic child nodes created under ` self.config ` .
1152046 . Clears the active registry entries.
1162057 . Syncs the new active plugin list.
1172068 . Invokes ` plugins.disabled(plugin, state, err) ` .
118207
119- Important detail:
120-
121- - Hook cleanup is automatic if you used ` self:add_hook(...) ` .
122- - Timers are not tracked by the plugin system yet.
123-
124208## Runtime Events
125209
126210These dispatchers live on ` plugins ` :
0 commit comments