Skip to main content

Function Signature

async function createPlugin<Locales extends string[]>(
  options: PluginDefinition<Locales, TransporterOptions>
): Promise<PluginInstance>

Description

Creates a new plugin instance with the specified options. This is the main entry point for building Atomemo plugins. The function handles authentication, plugin registration, and returns an instance object with methods to add credentials, tools, models, and run the plugin.

Parameters

options
PluginDefinition<Locales, TransporterOptions>
required
The plugin configuration object containing metadata and settings.

Returns

PluginInstance
object
An object containing methods to configure and run the plugin

Example

import { createPlugin } from '@choiceopen/atomemo-plugin-sdk'

const plugin = await createPlugin({
  name: 'my-awesome-plugin',
  description: 'A plugin that does amazing things',
  version: '1.0.0',
  transporterOptions: {
    heartbeatIntervalMs: 30000,
    onOpen: () => console.log('Connected to Hub'),
    onError: (error) => console.error('Connection error:', error)
  }
})

// Add plugin features
plugin.addTool(myToolDefinition)
plugin.addCredential(myCredentialDefinition)

// Start the plugin
await plugin.run()

Behavior

Debug Mode

When HUB_MODE environment variable is set to "debug":
  • Fetches user information from OneAuth session
  • Registers the plugin with the Hub using register_plugin message
  • Writes the plugin definition to definition.json
  • Uses debug topic: debug_plugin:{plugin.name}

Release Mode

When HUB_MODE is not "debug":
  • Reads user information from definition.json file
  • Uses release topic: release_plugin:{plugin.name}__{HUB_MODE}__{version}

Signal Handling

The plugin automatically sets up handlers for SIGINT and SIGTERM signals to gracefully shut down the connection when the process is terminated.

Error Handling

  • Throws error if user session cannot be fetched in debug mode
  • Throws error if definition.json cannot be parsed in release mode
  • Exits process with code 1 on authentication or definition errors

Build docs developers (and LLMs) love