AbstractProtectedtoolsGets the initialized tools for this twist.
AbstractbuildDeclares tool dependencies for this twist. Return an object mapping tool names to build() promises.
The build function to use for declaring dependencies
Object mapping tool names to tool promises
ProtectedcallbackCreates a persistent callback to a method on this twist.
ExtraArgs are strongly typed to match the method's signature after the first argument.
The method to callback
Additional arguments to pass (type-checked, must be serializable)
Promise resolving to a persistent callback token
ProtecteddeleteDeletes a specific callback by its token.
The callback token to delete
Promise that resolves when the callback is deleted
ProtecteddeleteDeletes all callbacks for this twist.
Promise that resolves when all callbacks are deleted
ProtectedrunExecutes a callback by its token.
The callback token to execute
Optional arguments to pass to the callback
Promise resolving to the callback result
ProtectedgetRetrieves a value from persistent storage by key.
The expected type of the stored value
The storage key to retrieve
Promise resolving to the stored value or null
ProtectedsetStores a value in persistent storage.
Important: Values must be JSON-serializable. Functions, Symbols, and undefined values cannot be stored directly.
For function references: Use callbacks instead of storing functions directly.
The type of value being stored
The storage key to use
The value to store (must be JSON-serializable)
Promise that resolves when the value is stored
// ❌ WRONG: Cannot store functions directly
await this.set("handler", this.myHandler);
// ✅ CORRECT: Create a callback token first
const token = await this.callback(this.myHandler, "arg1", "arg2");
await this.set("handler_token", token);
// Later, execute the callback
const token = await this.get<string>("handler_token");
await this.run(token, args);
ProtectedclearRemoves a specific key from persistent storage.
The storage key to remove
Promise that resolves when the key is removed
ProtectedclearRemoves all keys from this twist's storage.
Promise that resolves when all keys are removed
ProtectedrunQueues a callback to execute in a separate worker context.
The callback token created with this.callback()
Optionaloptions: { runAt?: Date }Optional configuration for the execution
OptionalrunAt?: DateIf provided, schedules execution at this time; otherwise runs immediately
Promise resolving to a cancellation token (only for scheduled executions)
ProtectedcancelCancels a previously scheduled execution.
The cancellation token returned by runTask() with runAt option
Promise that resolves when the cancellation is processed
ProtectedcancelCancels all scheduled executions for this twist.
Promise that resolves when all cancellations are processed
Called when the twist is activated for a specific priority.
This method should contain initialization logic such as setting up initial activities, configuring webhooks, or establishing external connections.
The priority context containing the priority ID
Promise that resolves when activation is complete
Called when a new version of the twist is deployed to an existing priority.
This method should contain migration logic for updating old data structures or setting up new resources that weren't needed by the previous version. It is called with the new version for each active priorityTwist.
Promise that resolves when upgrade is complete
Called when the twist is removed from a priority.
This method should contain cleanup logic such as removing webhooks, cleaning up external resources, or performing final data operations.
Promise that resolves when deactivation is complete
Base class for all twists.
Twists are activated in a Plot priority and have access to that priority and all its descendants.
Override build() to declare tool dependencies and lifecycle methods to handle events.
Example