AbstractAbstractcreateAbstractgenerateGenerates twist source code from a specification using AI.
This method uses Claude AI to generate TypeScript source code and dependencies from a markdown specification. The generated source is validated by attempting to build it, with iterative error correction (up to 3 attempts).
Markdown specification describing the twist functionality
Promise resolving to twist source (dependencies and files)
const source = await twist.generate(`
# Calendar Sync Twist
This twist syncs Google Calendar events to Plot activities.
## Features
- Authenticate with Google
- Sync calendar events
- Create activities from events
`);
// source.dependencies: { "@plotday/sdk": "workspace:^", ... }
// source.files: { "index.ts": "export default class..." }
AbstractdeployDeploys a twist programmatically.
This method provides the same functionality as the plot deploy CLI command, but can be called from within a twist. Accepts either:
Deployment configuration
Twist ID for deployment
Optionalenvironment?: "personal" | "private" | "review"Target environment (defaults to "personal")
Optionalname?: stringOptional twist name (required for first deploy)
Optionaldescription?: stringOptional twist description (required for first deploy)
OptionaldryRun?: booleanIf true, validates without deploying (returns errors if any)
Pre-bundled twist module code (mutually exclusive with source)
Twist source code with dependencies (mutually exclusive with module)
Promise resolving to deployment result with version and optional errors
// Deploy with a module
const result = await twist.deploy({
twistId: 'abc-123-...',
module: 'export default class MyTwist extends Twist {...}',
environment: 'personal',
name: 'My Twist',
description: 'Does something cool'
});
console.log(`Deployed version ${result.version}`);
// Deploy with source
const source = await twist.generate(spec);
const result = await twist.deploy({
twistId: 'abc-123-...',
source,
environment: 'personal',
name: 'My Twist',
});
// Validate with dryRun
const result = await twist.deploy({
twistId: 'abc-123-...',
source,
dryRun: true,
});
if (result.errors?.length) {
console.error('Build errors:', result.errors);
}
AbstractwatchSubscribes to logs from a twist.
This method registers a callback to receive batches of logs from twist executions. The callback will be invoked with an array of logs whenever new logs are captured from the twist's console output.
Twist ID (root ID) to watch logs for
Callback token created via CallbackTool that will receive log batches
Promise that resolves when the subscription is created
// Create twist and callback
const twistId = await this.twist.create();
const callback = await this.callback.create("onLogs");
// Subscribe to logs
await this.twist.watchLogs(twistId, callback);
// Implement handler
async onLogs(logs: Log[]) {
for (const log of logs) {
console.log(`[${log.environment}] ${log.severity}: ${log.message}`);
}
}
Built-in tool for managing twists and deployments.
The Twists tool provides twists with the ability to create twist IDs and programmatically deploy twists.
Example