Skip to main content

Plugin

💡 Quick Development Tip: You can use the Ghostie Plugin Development Assistant in the Agent Market to quickly develop plugins. This assistant can help you generate compliant plugin code and provide real-time code suggestions and error checking.

What is a Plugin

Plugins extend the capabilities of AI assistants.

How to Develop

  1. Use TypeScript
  2. Use Node runtime

Example

ts
/**
* @name Time Management Plugin
* @description Provides functionality to get current time
*/

// Parameter definition
interface Params {
/* Timezone */
timezone?: string;
}

/* Get current time */
export async function getCurrentTime(params: Params): Promise<string> {
return new Date().toString();
}
warning
  • Highlight comments must be written, otherwise the Agent may not know the parameter meaning.
  • If it needs to be called by the Agent, it must be exported using export.
  • In the current version, it must be declared using function, not arrow functions.

Plugin Development Guidelines

  1. Plugins should be annotated with @name and @description in documentation comments to specify the plugin name and functionality description.
  2. All tool functions intended for external use must be exported using export, otherwise they will not be visible.
  3. Each tool function should accept only one parameter, with the parameter type unified as object (i.e., Record<string, any>), and its structure should be clearly defined using interface.
  4. Each tool function must have usage instructions added using // or /** */ comments, which should clearly describe the function's purpose.
  5. Each field in the parameter's interface must have a comment using // explaining its meaning.
  6. Plugins should use Deno's package management method (e.g., import { xxx } from "https://deno.land/x/...").
  7. Environment variables should be accessed uniformly through Deno.env.get().

More Examples

ts
/**
* @name Local TXT File Reader Plugin
* @description Reads content from a specified local TXT file
*/

// Parameter definition
interface Params {
// File path
filePath: string; // Complete path including filename and extension
}

/**
* Read local TXT file content
*
* @param params - Object containing file path
* @returns Returns file content as string
*/
export async function readTxtFile(params: Params): Promise<string> {

}

Environment Variables

You can set environment variables above the list in the plugin settings page.

In code, call:

ts
import dotenv from "dotenv";

dotenv.config();

const API_KEY = process.env.API_KEY;

Plugin Get Database

ts

const cookies = __DB__("xxxxxx",(item)=>{item.name === "xxxxxx"})

  1. xxxxxx is the database name.
  2. (item)=>{item.name === "xxxxxx"} is the filter condition.
  3. item is the data object.
  4. item.name is the field name.
  5. xxxxxx is the value.

Plugin Develop

  1. you can edit the plugin in the plugins view.
  2. or you can open the plugin folder with vscode\cursor to edit.

format is same, and you can add a type.d.ts file to declare the type.

ts
type.d.ts

declare function __DB__(key: string, callback: (item: any) => boolean): any;
declare function __IMAGE__(key: string): string;
// ...