Plugin minimal

Le plugin le plus simple possible.

Code complet

plugins/hello.ts

import { z } from "zod";

const HelloInputSchema = z.object({
  name: z.string().describe("Person's name"),
});

export async function hello(input: unknown): Promise<string> {
  const { name } = HelloInputSchema.parse(input);
  return `Hello, ${name}!`;
}

tests/hello.test.ts

import { describe, it, expect } from "bun:test";
import { hello } from "../plugins/hello";

describe("hello plugin", () => {
  it("doit dire bonjour", async () => {
    const result = await hello({ name: "Alice" });
    expect(result).toBe("Hello, Alice!");
  });

  it("doit rejeter sans name", async () => {
    expect(() => hello({})).toThrow();
  });
});

package.json

{
  "name": "hello-plugin",
  "version": "1.0.0",
  "scripts": {
    "test": "bun test"
  },
  "dependencies": {
    "zod": "^4.3.0"
  }
}

Exécuter

# Tests
bun test

# Utilisation
import { hello } from "./plugins/hello";
const result = await hello({ name: "Bob" });
console.log(result); // "Hello, Bob!"

Prochaines étapes

Plugin avec API

Previous

← Page précédente

Next

Page suivante →