SDK Plugin API
Référence complète du SDK pour créer des plugins.
Installation
bun install @plugin-factory/sdk
Imports
import { definePlugin, createHandler } from "@plugin-factory/sdk";
import { z } from "zod";
definePlugin()
Déclare un nouveau plugin.
Signature
function definePlugin(config: PluginConfig): Plugin
Exemple
import { definePlugin } from "@plugin-factory/sdk";
const myPlugin = definePlugin({
id: "my-plugin",
name: "My Plugin",
description: "A simple plugin",
version: "1.0.0",
handlers: [
// Liste des handlers
],
});
createHandler()
Crée un handler pour votre plugin.
Signature
function createHandler<T extends ZodSchema>(config: {
name: string;
input: T;
handler: (input: z.infer<T>) => Promise<string>;
}): Handler
Exemple
import { createHandler } from "@plugin-factory/sdk";
import { z } from "zod";
const greetHandler = createHandler({
name: "greet",
input: z.object({
name: z.string().describe("Person's name"),
}),
handler: async (input) => {
return `Hello, ${input.name}!`;
},
});
Types
PluginConfig
interface PluginConfig {
id: string;
name: string;
description: string;
version: string;
author?: string;
license?: string;
handlers: Handler[];
}
Handler
interface Handler {
name: string;
input: ZodSchema;
handler: (input: any) => Promise<string>;
}
Bonnes pratiques
- Toujours utiliser
createHandler()pour la validation automatique - Retourner des strings structurées (JSON si complexe)
- Utiliser
.describe()sur les schémas Zod - Gérer les erreurs dans le handler avec try/catch