Hooks SDK

Les hooks permettent d'intercepter le cycle de vie des appels de plugins.

Hooks disponibles

onBeforeCall

Exécuté avant chaque appel d'outil. Utile pour la validation, le logging, l'authentification.

export const myPlugin = createPlugin({
  onBeforeCall: async (ctx, toolName, input) => {
    if (!ctx.user) throw new Error("Authentication required");
    ctx.logger.info({ toolName }, "Plugin call started");
  },
});

onAfterCall

Exécuté après chaque appel d'outil, même en cas d'erreur.

export const myPlugin = createPlugin({
  onAfterCall: async (ctx, toolName, result, durationMs) => {
    ctx.logger.info({ toolName, durationMs }, "Plugin call completed");
  },
});

onError

Exécuté uniquement en cas d'erreur non gérée.

export const myPlugin = createPlugin({
  onError: async (ctx, toolName, error) => {
    await ctx.alerting.notify({ severity: "error", message: error.message });
  },
});

Previous

← Page précédente

Next

Page suivante →