Automation Extension

Built-in extension ID: @chaton/automation

The automation extension lets users create rules that trigger actions when events occur in Chatons.


What It Does

An automation rule consists of:

FieldTypeDescription
idstringUnique rule identifier
namestringHuman-readable rule name
enabledbooleanWhether the rule is active
trigger_topicstringEvent topic that triggers this rule
conditions_jsonJSONOptional conditions to match against the event payload
actions_jsonJSONOne or more actions to execute
cooldown_msnumberMinimum milliseconds between executions
last_triggered_atstringTimestamp of last execution

User-Facing Features

The extension adds to the Chatons UI:

  • Sidebar entry: "Automations" (icon: Gauge, order: 10)
  • Main view: automation.main -- a full-page automation management screen
  • Quick action: automation.create -- opens the create-automation flow

In the automation screen, users can:

  • List existing rules
  • Create new rules in a modal dialog
  • View recent execution history
  • Delete rules (double-click)
  • Switch between light and dark themes

Trigger Topics

The runtime validates triggers against a fixed allowlist. Current supported triggers:

TopicWhen Fired
conversation.createdA new conversation is created
conversation.message.receivedA new message is received in a conversation
project.createdA new project is imported
conversation.agent.endedThe AI finishes processing a conversation turn
extension.eventAny extension-published event occurs
extension.{name}A specific extension event (e.g., extension.user_created) occurs

Rules with any other trigger topic are rejected on save.

:::info Extension events allow third-party extensions to publish custom events that can trigger automations. See the Extension Events section below for details. :::


Action Types

notify

Shows a host notification.

{
  "type": "notify",
  "title": "Automation Alert",
  "body": "A new conversation was created."
}

If title or body are omitted, they are derived from the event topic and payload.

executeAndNotify

Runs an instruction through an ephemeral Pi session and sends the result as a notification.

{
  "type": "executeAndNotify",
  "title": "Summary",
  "instruction": "Summarize the latest conversation message.",
  "model": "openai/gpt-4o"
}

The instruction is executed in a temporary conversation that is created and cleaned up automatically. If a model key is provided, the Pi session uses that model.

enqueueEvent

Publishes an item into the extension queue system for downstream processing.

{
  "type": "enqueueEvent",
  "topic": "export-jobs",
  "payload": { "format": "markdown" }
}

runHostCommand

Calls a host method from a narrow allowlist:

  • notifications.notify
  • open.mainView

Any other method is rejected.

{
  "type": "runHostCommand",
  "method": "notifications.notify",
  "params": { "title": "Alert", "body": "Something happened." }
}

setConversationTag

Currently a no-op placeholder. Accepted by the runtime but does not apply any tag mutation.


Conditions

Rules can include conditions evaluated against the event payload.

Supported Operators

OperatorBehavior
equalsExact match: payload[field] === value
containsSubstring match: payload[field].includes(value) (both must be strings)

Limitations

  • Conditions evaluate only top-level fields in the event payload
  • Nested object paths are not supported
  • Malformed or unsupported conditions fail conservatively (rule does not fire)

Example

[
  { "field": "projectId", "operator": "equals", "value": "my-project-uuid" }
]

Cooldown

Each rule has a cooldown_ms field (milliseconds).

When an event matches a rule:

  1. Check last_triggered_at
  2. If the cooldown window has not elapsed, skip the rule
  3. Otherwise execute the rule and update last_triggered_at

LLM-Callable Tools

The extension exposes two tools that the AI can call during conversations:

automation.schedule_task

Create or update an automation rule from natural language.

ParameterTypeRequiredDescription
namestringNoRule name (derived from instruction if omitted)
instructionstringYesNatural-language task description
triggerstringNoTrigger topic (inferred from instruction if omitted)
cooldownnumberNoCooldown in ms (inferred from instruction if omitted)
projectIdstringNoTarget project ID
modelKeystringNoModel to use (e.g. openai/gpt-4o)
notifyMessagestringNoCustom notification message
idstringNoExisting rule ID to update
conditionsarrayNoCondition array
enabledbooleanNoWhether the rule is enabled

When called by the AI, this creates a rule with a default notify action carrying the instruction text, or an executeAndNotify action if a model key is provided.

automation.list_scheduled_tasks

Returns existing rules so the AI can inspect them before creating or modifying.

ParameterTypeRequiredDescription
limitnumberNoMaximum number of rules to return

Extension APIs

Exposed via the manifest apis.exposes and handled in electron/extensions/runtime/automation.ts:

API NamePurpose
automation.rules.listList all automation rules
automation.rules.saveCreate or update a rule
automation.rules.deleteDelete a rule by ID
automation.runs.listList execution history
automation.schedule_taskCreate/update rule (LLM-callable version)
automation.list_scheduled_tasksList rules (LLM-callable version)

Persistence

Automation state is stored in the Chatons SQLite database.

automation_rules table

ColumnTypeDescription
idTEXT PKRule identifier
nameTEXTRule name
enabledINTEGER0 or 1
trigger_topicTEXTEvent topic
conditions_jsonTEXTJSON array of conditions
actions_jsonTEXTJSON array of actions
cooldown_msINTEGERCooldown in milliseconds
last_triggered_atTEXTISO timestamp of last trigger
created_atTEXTISO creation timestamp
updated_atTEXTISO update timestamp

automation_runs table

ColumnTypeDescription
idTEXT PKRun identifier
rule_idTEXTAssociated rule ID
event_topicTEXTEvent that triggered this run
event_payload_jsonTEXTSerialized event payload
statusTEXTsuccess or error
error_messageTEXTError message (if failed)
created_atTEXTISO timestamp

Implementation Files

FilePurpose
electron/extensions/builtin/automation/chaton.extension.jsonExtension manifest
electron/extensions/builtin/automation/index.htmlUI entry point
electron/extensions/builtin/automation/index.jsUI logic (plain JavaScript)
electron/extensions/builtin/automation/components.jsShared UI components
electron/extensions/runtime/automation.tsBackend: rule evaluation, action execution
electron/extensions/runtime/automation-pi-bridge.tsEphemeral Pi session executor for executeAndNotify
electron/db/repos/automation.tsDatabase operations for rules and runs

The UI is self-contained plain HTML/JS (not compiled React). It uses the injected Chatons UI helpers (window.chatonExtensionComponents, window.chatonUi.createModelPicker()). It is the primary reference implementation for building native-looking extension UIs.


Translation

The automation extension owns its own labels. Chatons renders extension-provided strings as-is -- the host does not auto-translate extension labels. If you localize an extension, handle translation within the extension.


Scope and Limitations

The automation system is intentionally simple. Do not document it as a full workflow engine.

Current limitations:

  • Fixed trigger allowlist (4 topics)
  • Simple condition matching (top-level fields only, 2 operators)
  • Narrow runHostCommand allowlist (2 methods)
  • setConversationTag is a no-op placeholder
  • Most LLM-scheduled tasks become notification-style rules unless a broader action is explicitly saved via the API
  • The executeAndNotify action creates ephemeral conversations that appear in the conversation list

Extension Events

Extensions can publish custom events that trigger automations, enabling powerful integration scenarios.

Publishing Events

Extensions with the events.publish capability can publish events using the automation.publish_extension_event API:

// Extension code example
const result = await window.chaton.extensionCall(
  '@chaton/automation',
  'automation.publish_extension_event',
  {
    eventName: 'user_created',
    payload: {
      userId: '123',
      name: 'John Doe',
      email: 'john@example.com'
    }
  }
);

if (result.ok) {
  console.log('Event published successfully');
} else {
  console.error('Failed to publish event:', result.error.message);
}

Event Name Format

Event names must follow these rules:

  • Allowed characters: a-z, A-Z, 0-9, _, -
  • Maximum length: 100 characters
  • Examples: user_created, file_uploaded, data_processed
  • Invalid: user created (spaces), user!created (special chars)

When published, an event named my_event creates the topic extension.my_event.

Triggering Automations

There are two ways to trigger automations from extension events:

1. Specific Event Trigger

Create a rule with trigger extension.my_event to respond only to that specific event.

Example Automation Rule:

{
  "name": "Notify on user creation",
  "trigger": "extension.user_created",
  "actions": [
    {
      "type": "notify",
      "title": "New User Created",
      "body": "User {{userId}} was created"
    }
  ]
}

2. Generic Extension Trigger

Create a rule with trigger extension.event to respond to any extension event, then use conditions to filter:

Example with Conditions:

{
  "name": "Log important events",
  "trigger": "extension.event",
  "conditions": [
    {"field": "priority", "operator": "equals", "value": "high"}
  ],
  "actions": [
    {
      "type": "executeAndNotify",
      "instruction": "Analyze this important event: {{eventType}}"
    }
  ]
}

UI Integration

In the automation creation UI:

  1. Select "Evenement d'extension" from the trigger dropdown
  2. Enter your custom event name (e.g., user_created)
  3. Configure the action to perform when the event occurs
  4. Save the automation rule

The event name field appears only when "Evenement d'extension" is selected and validates the format.

Use Cases

User Activity Tracking

// Extension publishes when user logs in
await publishExtensionAutomationEvent(
  '@auth/extension',
  'user_login',
  { userId: '123', timestamp: Date.now() }
);

// Automation sends notification to admin channel

File Processing

// Extension publishes when file processing completes
await publishExtensionAutomationEvent(
  '@file/processor',
  'file_processed',
  { file: 'document.pdf', status: 'completed' }
);

// Automation triggers follow-up analysis

System Monitoring

// Extension publishes health check results
await publishExtensionAutomationEvent(
  '@system/monitor',
  'health_check',
  { status: 'ok', cpu: 0.45, memory: 0.68 }
);

// Automation alerts on critical issues

API Reference

automation.publish_extension_event

Version: 1.0.0

Parameters:

{
  eventName: string;      // Name of the custom event
  payload?: any;         // Optional data to include
}

Returns:

{
  ok: boolean;
  data?: { success: true };
  error?: {
    code: string;
    message: string;
  };
}

Error Codes:

  • invalid_args: Event name format invalid
  • event_publication_failed: Failed to publish event
  • unauthorized: Extension not authorized to publish events

Best Practices

Event Naming:

  • Use lowercase with underscores: user_created not UserCreated
  • Be specific: file_uploaded not event
  • Include context: payment_processed not processed

Payload Design:

  • Keep payloads small (< 1KB recommended)
  • Use simple JSON structures
  • Avoid sensitive data

Automation Design:

  • Use specific event triggers when possible
  • Add conditions to filter events
  • Set appropriate cooldowns to avoid flooding

Security

  • Extensions must have events.publish capability
  • Event names are validated for allowed characters
  • Standard automation cooldowns and rate limits apply

On this page