import { tool } from "@opencode-ai/plugin"; import { createLogger } from "./logger"; import type * as z from "zod"; import * as zodRuntime from "zod"; export { tool }; export { zodRuntime as z }; export interface ToolDefinition = any> { name: string; description: string; schema: z.ZodType; execute: (args: T, context?: any) => Promise; } export interface ProviderSpec { name: string; displayName: string; envVars: { required: Array<{ name: string; description: string; example?: string; }>; }; capabilities: string[]; comingSoon?: string[]; credentialsUrl?: string; credentialsDocUrl?: string; } export interface ProviderValidationResult { provider: string; configured: boolean; missingVars: string[]; spec?: ProviderSpec; } export interface ProviderValidationReport { hasRequiredProvider: boolean; requiredResults: ProviderValidationResult[]; optionalResults: ProviderValidationResult[]; errors: string[]; } export type ToolRecord = Record; execute: (args: any, context?: any) => Promise; }>; export declare function createPlugin(tools: ToolDefinition[]): { tool: ToolRecord; }; export declare function createSingleTool>(definition: Omit, 'name'>): { description: string; args: z.ZodObject; execute: (args: T, context?: any) => Promise; }; export declare function validateProviders(packageJson: any, pluginDir: string): ProviderValidationReport; export interface EnvConfig { [key: string]: string; } export declare function loadEnv(petId?: string): EnvConfig; export declare function getEnv(key: string, petId?: string): string | undefined; export interface PetSettings { readOnly?: boolean; [key: string]: any; } export interface PetsConfig { enabled?: string[]; disabled?: string[]; envConfig?: Record>; petConfig?: Record; last_updated?: string; } /** * Set environment variables for a pet in .pets/config.json * This is the proper way to persist pet-specific configuration * * @param petId - The pet identifier (e.g., "maps", "github") * @param envVars - Key-value pairs to set * @param projectDir - Optional project directory (defaults to cwd) */ export declare function setEnv(petId: string, envVars: Record, projectDir?: string): { success: boolean; message: string; }; /** * Get the current .pets/config.json configuration */ export declare function getPetsConfig(projectDir?: string): PetsConfig | null; /** * Clear environment variables for a pet from .pets/config.json */ export declare function clearEnv(petId: string, keys?: string[], projectDir?: string): { success: boolean; message: string; }; export interface SyncEnvResult { success: boolean; message: string; synced: number; pets: string[]; } /** * Sync environment variables from .env file into .pets/config.json * This ensures .pets/config.json is the single source of truth at runtime. * * - .env values take precedence and override .pets/config.json values * - Only syncs to pets that are currently configured (in opencode.json) * - Also ensures .pets/ is added to .gitignore * * @param projectDir - Optional project directory (defaults to cwd) */ export declare function syncEnvToConfig(projectDir?: string): SyncEnvResult; /** * Check if a pet is configured in read-only mode. * * Read-only mode prevents write tools from being registered for the pet. * This is useful when users want to ensure they can only read data, not modify it. * * Configuration is checked in the following order (first match wins): * 1. Environment variable: {PETNAME}_READ_ONLY=true (e.g., ASANA_READ_ONLY=true) * 2. Pet-specific config in .pets/config.json: petConfig.{petId}.readOnly * 3. Global config in .pets/config.json: petConfig._global.readOnly * * @param petId - The pet identifier (e.g., "asana", "jira", "github") * @returns true if read-only mode is enabled for this pet * * @example * ```typescript * import { isReadOnly, createPlugin, type ToolDefinition } from "openpets-sdk" * * export const MyPlugin = async () => { * const readOnly = isReadOnly("my-plugin") * * const readTools: ToolDefinition[] = [ * { name: "my-plugin-list", ... }, * { name: "my-plugin-get", ... } * ] * * const writeTools: ToolDefinition[] = [ * { name: "my-plugin-create", ... }, * { name: "my-plugin-update", ... } * ] * * // Only include write tools if not in read-only mode * const tools = readOnly ? readTools : [...readTools, ...writeTools] * * return createPlugin(tools) * } * ``` */ export declare function isReadOnly(petId: string): boolean; /** * Set read-only mode for a pet in .pets/config.json * * @param petId - The pet identifier (e.g., "asana", "jira"). Use "_global" for all pets. * @param enabled - Whether read-only mode should be enabled * @param projectDir - Optional project directory (defaults to cwd) * @returns Result object with success status and message */ export declare function setReadOnly(petId: string, enabled: boolean, projectDir?: string): { success: boolean; message: string; }; /** * Get read-only status for a pet or all pets * * @param petId - Optional pet identifier. If not provided, returns status for all configured pets. * @param projectDir - Optional project directory (defaults to cwd) * @returns Object with read-only status information */ export declare function getReadOnlyStatus(petId?: string, projectDir?: string): { global: boolean | undefined; pets: Record; envOverrides: Record; }; /** * Helper to filter tools based on read-only mode. * Use this in your pet's plugin factory to easily filter out write tools. * * @param tools - Array of tool definitions * @param writePatterns - Array of patterns that identify write operations (e.g., ['create', 'update', 'delete']) * @param isReadOnlyMode - Whether read-only mode is enabled * @param logger - Optional logger for debug output * @returns Filtered array of tools * * @example * ```typescript * const WRITE_PATTERNS = ['create', 'update', 'delete', 'add-comment'] * const filteredTools = filterToolsForReadOnly(allTools, WRITE_PATTERNS, isReadOnly('my-pet')) * ``` */ export declare function filterToolsForReadOnly(tools: ToolDefinition[], writePatterns: string[], isReadOnlyMode: boolean, debugLogger?: ReturnType): ToolDefinition[]; //# sourceMappingURL=plugin-factory.d.ts.map