import type { Effect } from "effect"; import type { ToolRegistry } from "./tools"; import type { SecretStore } from "./secrets"; import type { PolicyEngine } from "./policies"; import type { SourceRegistry } from "./sources"; import type { Scope } from "./scope"; // --------------------------------------------------------------------------- // Plugin context — what the SDK gives a plugin when it starts // --------------------------------------------------------------------------- export interface PluginContext { readonly scope: Scope; readonly tools: Context.Tag.Service; readonly sources: Context.Tag.Service; readonly secrets: Context.Tag.Service; readonly policies: Context.Tag.Service; } // --------------------------------------------------------------------------- // Plugin definition — what a plugin provides to the SDK // --------------------------------------------------------------------------- export interface ExecutorPlugin { /** Unique plugin key — becomes a property on the Executor type */ readonly key: TKey; /** * Called when the executor starts. The plugin should register its tools * and return any cleanup logic + its public extension API. */ readonly init: (ctx: PluginContext) => Effect.Effect, Error>; } export interface PluginHandle { /** Plugin's public API — exposed on the executor as `executor[plugin.key]` */ readonly extension: TExtension; /** Called when the executor shuts down */ readonly close?: () => Effect.Effect; } // --------------------------------------------------------------------------- // Type-level helpers — expand the Executor type based on plugins // --------------------------------------------------------------------------- /** Maps a tuple of plugins to their extensions keyed by plugin key */ export type PluginExtensions[]> = { readonly [P in TPlugins[number] as P["key"]]: P extends ExecutorPlugin ? TExt : never; }; // We need Context imported for the Tag.Service usage import type { Context } from "effect"; // --------------------------------------------------------------------------- // definePlugin — helper for type inference // --------------------------------------------------------------------------- export const definePlugin = ( plugin: ExecutorPlugin, ): ExecutorPlugin => plugin;