Skip to content

Latest commit

 

History

History
170 lines (128 loc) · 4.2 KB

plugin.md

File metadata and controls

170 lines (128 loc) · 4.2 KB

Creating Plugins for the VA Platform

The VA platform allows developers to extend its functionalities by creating plugins within the market directory. Plugins can be of different types such as Agent, Connector, and Provider, and can be implemented using CommonJS, ESM, or TypeScript. This guide will walk you through creating plugins for the VA platform, focusing on Provider plugins with examples.


Plugin Types in the VA Platform

1. Agent

  • Automates tasks and interactions within the platform.

2. Connector

  • Facilitates integration with external systems and APIs.

3. Provider

  • Supplies services and functionalities, such as connecting to AI services like OpenAI.

Creating a Provider Plugin

A Provider Plugin extends the VA platform by providing external services. Let's explore three implementations using TypeScript, CommonJS, and ESM.


1. Provider Plugin in TypeScript

File Structure:

src/market/providers/mod.ts/index.js
src/market/providers/mod.ts/metadata.json

index.js:

import { Provider } from "../../../shared/plugin/services/provider";

class ModTS extends Provider {
    label = "Demo Module TypeScript";
}

export default ModTS;

metadata.json:

{
    "name": "Demo Module TypeScript Provider",
    "description": "A classified provider plugin allows a platform to interact with ...",
    "scope": "public",
    "config": {
        "temperature": 0.8
    }
}

2. Provider Plugin in CommonJS

File Structure:

src/market/providers/mod.cjs/index.js
src/market/providers/mod.cjs/metadata.json

index.js:

const { Provider } = require("../../../shared/plugin/services/provider");
const path = require("path");

class ModCJS extends Provider {
    label = "Demo Module CommonJs";

    constructor(config) {
        super(config);
        this.name = "modcjs";
        this.routes = {
            "web": {
                "/": { method: "get", handler: this.onList.bind(this) }
            }
        };
        console.log("ModCJS:constructor");
    }

    onList(req, res) {
        res.json({ data: "CJS - Hello!" });
    }
}

exports.default = ModCJS;

metadata.json:

{
    "name": "Demo Module CommonJs Provider",
    "description": "A classified provider plugin allows a platform to interact with an AI service like OpenAI...",
    "scope": "public",
    "config": { "temperature": 0.8 }
}

3. Provider Plugin in ESM

File Structure:

src/market/providers/mod.esm/index.js
src/market/providers/mod.esm/metadata.json
src/market/providers/mod.esm/package.json

index.js:

import { Provider } from "../../../shared/plugin/services/provider.js";

class ModESM extends Provider {
    label = "Demo Module ESM";

    constructor(config) {
        super(config);
        this.name = "modems";
        this.routes = {
            "web": { "/": { method: "get", handler: this.onList.bind(this) } }
        };
        console.log("ModESM:constructor");
    }

    onList(req, res) {
        res.json({ data: "EMS - Hello!" });
    }
}

export default ModESM;

metadata.json:

{
    "name": "Demo Module ESM Provider",
    "description": "A classified provider plugin allows a platform to interact with an AI service like OpenAI...",
    "scope": "public",
    "config": { "temperature": 0.8 }
}

package.json:

{
    "type": "module"
}

Best Practices for Creating Plugins

  • Consistent Metadata: Always include a metadata.json file describing the plugin.
  • Flexible Implementation: Use the appropriate module system based on your project needs.
  • Clear Structure: Follow a clear directory structure within the market folder.
  • Extensible Code: Extend the Provider class for easy integration with the VA platform.

Conclusion

Creating plugins for the VA platform enhances its capabilities and allows seamless integration with external services. Whether you choose CommonJS, ESM, or TypeScript, the VA platform supports diverse implementations to suit your project needs. Follow the examples provided and best practices to create robust and scalable plugins.