Scripting

Create and run Kotlin scripts directly on the server with event-driven triggers and AI agent integration.

Bosca includes a built-in scripting engine that lets you write, manage, and execute Kotlin Script (KTS) files directly on the server. Scripts can automate tasks, respond to platform events, and extend AI agent capabilities.

What you get

  • Server-Side Scripts: Write Kotlin scripts that run on the Bosca server with access to platform services.
  • Event Triggers: Bind scripts to platform events so they execute automatically when things happen.
  • Workflow Integration: Scripts can trigger workflow transitions, giving automations control over the content lifecycle.
  • AI Agent Tools: Scripts can serve as tool implementations for AI agents, extending what agents can do.
  • Administration UI: Create, edit, and manage scripts from the admin panel with Monaco editor support.

Script Types

Bosca supports several script categories:

  • General: Standalone scripts for ad-hoc tasks or scheduled execution.
  • Trigger: Scripts bound to platform events that fire automatically.
  • Tool: Scripts that provide tool implementations for AI agents.

How Triggers Work

Trigger bindings connect scripts to platform events. When a matching event occurs, Bosca executes the bound script with a context object that includes event details and access to platform services.

This lets you build reactive automations—for example, a script that generates a summary whenever new content is published, or one that notifies a team when a workflow transition fails.

Script Agent

The Script Agent allows you to manage scripts using natural language through the chat interface. You can create, edit, delete, enable, disable, execute, and validate scripts conversationally.

Multi-Instance Cache Invalidation

In multi-instance deployments, Bosca uses PubSub messaging to keep script caches synchronized across servers. When a script is created, edited, enabled, disabled, or deleted on any instance, an invalidation message is broadcast so all other instances clear their local KTS engine caches immediately.

This means script changes take effect cluster-wide without restarting services. The system supports both NATS and Redis as PubSub backends, with automatic reconnection and retry on failure.

Security

Scripts run in a controlled environment with restrictions to prevent unsafe operations. The scripting engine enforces boundaries on what scripts can access and modify.

Administration

The Administration UI provides:

  • A script editor with Monaco (VS Code) editor support
  • Script listing with enable/disable controls
  • Trigger binding management
  • Manual script execution
  • Script validation before saving

For developers

Related modules:

  • Core interfaces: backend/framework/core-scripting
  • Implementation: backend/framework/scripting
  • GraphQL schema: backend/framework/scripting/src/main/resources/graphql/scripts.graphqls

Script execution contexts provide access to:

  • Database connections and services
  • Content and metadata operations
  • Workflow state management
  • Tool context for agent integrations
  • Trigger context for event-driven execution

Related: