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.
- Automates tasks and interactions within the platform.
- Facilitates integration with external systems and APIs.
- Supplies services and functionalities, such as connecting to AI services like OpenAI.
A Provider Plugin extends the VA platform by providing external services. Let's explore three implementations using TypeScript, CommonJS, and ESM.
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
}
}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 }
}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"
}- Consistent Metadata: Always include a
metadata.jsonfile describing the plugin. - Flexible Implementation: Use the appropriate module system based on your project needs.
- Clear Structure: Follow a clear directory structure within the
marketfolder. - Extensible Code: Extend the
Providerclass for easy integration with the VA platform.
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.