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
- Use TypeScript
- 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
- Plugins should be annotated with
@name
and@description
in documentation comments to specify the plugin name and functionality description. - All tool functions intended for external use must be exported using
export
, otherwise they will not be visible. - 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 usinginterface
. - Each tool function must have usage instructions added using
//
or/** */
comments, which should clearly describe the function's purpose. - Each field in the parameter's
interface
must have a comment using//
explaining its meaning. - Plugins should use Deno's package management method (e.g.,
import { xxx } from "https://deno.land/x/..."
). - 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"})
xxxxxx
is the database name.(item)=>{item.name === "xxxxxx"}
is the filter condition.item
is the data object.item.name
is the field name.xxxxxx
is the value.
Plugin Develop
- you can edit the plugin in the plugins view.
- 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;
// ...