Create New Extension
Extensions allow adding additional functionality to omnitool, both on client and server side. They can provide a convenient way for prototyping AI powered applications.
⚠️ Extensions run with the same permissions as the omnitool process and have full access to the omnitool server process. They should be treated like any other npm package or executable code from the internet, with extreme caution. ⚠️
Getting Started
Creating a custom extension for Omnitool is streamlined with our easy-to-use template. Here's a step-by-step guide to create, develop, and test your extension:
Access and Use the Template Repository:
Visit the Omni Extension Template on GitHub. This template provides the basic structure needed for your extension.
Create a new repository from this template, ensuring that it's set to public visibility.
Customize the extension.yaml File:
In your new repository, find and update the
extension.yaml
file.Crucially, change the
origin
field to your repository’s clone URL.
Push Changes and Add Extension to Omnitool:
Commit and push your updated
extension.yaml
file to your GitHub repository.In the Omnitool chat UI, type
/extensions add [your GitHub repository clone URL, ending with .git]
to add your extension.
Verify and Start Development:
Once added, locate your extension in
omnitool/packages/omni-server/extensions/
.You’ll find a new folder named after your GitHub repository here.
Develop Your Extension:
Open the directory in Visual Studio Code or your preferred IDE.
This is your development environment where you can build and customize your extension.
Learn from Existing Extensions:
Explore other extensions in Omnitool for inspiration and understanding.
Observe their structure, functionality, and integration methods.
Iterate and Test:
Develop your extension iteratively, testing it regularly in the Omnitool environment.
Continuously refine based on test results and potentially user feedback.
Finalize and Share:
Once you’re satisfied with your extension, ensure it’s properly documented and shared with the Omnitool community.
Encourage feedback to further enhance your extension.
By following these steps, you can effectively create and develop a functional and innovative extension for Omnitool. This guide is designed to assist both beginners and experienced developers in navigating the extension development process with ease.
Extension Structure
extension.yaml
For an extension to be recoginized by the server, it needs, at minimum, an extension.yaml file in the directory.
Directory Structure
The following directory structure may, optionally, exist under the extension's sub directory
public
- Files in this directory are served to the client underserver_url/extensions/<extension id>
. By default, ifclient.addToWorkbench
is true, the client will attempt to showpublic/index.html
if it exists when a users selects the extension in the extension menuscripts/client
- Files in this directory, following the script format, will be exported to the client, adding to the list of known /chat commands. The chat command will be mapped to the file's name, so test.js would become /test. For more details, see Client Programming/Scripts below.server/extension.js
- This file is loaded by the server on startup and allows hooking extending server functionality. See Server Programming.
Extension Discovery
Currently the server keeps track of known extensions via the /etc/extensions/known_extensions.yaml
file. An entry in this file will make extensions discoverable by the omnitool community. We plan on adding the ability to add additional extensions repositories outside the official one.
The file's format is straightforward:
An entry in this file is not required for an extension to be loaded, only for it to be discoverable by other omnitool users.
Client Extension Programming
The client, after successful login, polls the /extensions endpoint on the server to retrieve a list active extension. It then constructs the extension menu and compiles the received client scripts.
Upon being shown, client extensions are loaded into an iframe overlaying the canvas by default and has access to the omnitool client context via the window.parent object. This is done by calling (window.parent.client.)workbench.showExtension(extension-id, openArgs )
, usually from automatically from within the extensions menu or from a client script.
Closing the extension will show the canvas again but not unload the iframe. However, the extensions state is not guaranteed, as showing any other extension will replace the iframe content. If it is necessary to persist client state, local or session storage can be used or data could be marshalled via server scripts.
Scripts
Scripts in the client/scripts
subdirectory of the extension are automatically registered with each connecting client after successful authentication and become available as /chat commands.
Within scripts, full access to the omnitool client is accessbile via the window.client object.
To display the index.html file surfaced via the extensions public/
directory, the window.client.workbench.showExtension("extension-id", {...});
provides a convenient method that also allow marshalling 'opening args
When the workbench.showExtension
command is used, the full object structure of the arguments object will be serialized (JSON. strigified) into a parameter q
in the opening url.
The following example code shows how to deserialize the opening args inside the extension's index.html
Server Extensions Programming
When the server starts, it will execute the server/extension.js
file for each extension, if present.
This file can:
(1) Attach hooks to server events to allow running code when these events happen (2) Export a list of blocks to be registered with the server.
A minimally viable extension.js
looks like this
Event Hooks
Event hooks are events exported by the server (see server/src/core/ServerExtensionsManager.ts
) that extension can hook into. by default, these hooks are executed synchronously, giving the extension the ability to modify execution parameters or, in some cases, even cancel the execution.
Currently, the following events are implemented:
The first parameter of each event is an event context, followed by a variable list of parameter depending on the event.
For example:
Block Factory
Extensions can add blocks to the omnitool. Unlike API based blocks imported from the registry, extension components have the ability to execute javascript code, allowing them to encapsulate useful nodejs libraries or custom code to provide more sophisticated experiences
To export blocks from an extensions, a createComponents factory function must be exported by the extension.js
file. This function is invoked by the server on startup with the servers block factory function (currently APIOperationsComponent.fromJSON).
Last updated