@ever-works/plugin

中文文档
1.2.16发布于 2026/11/03AGPL-3.0TypeScriptESM + CJS构建来源已验证近 30 天下载 7176

Plugin system contracts, helpers, and utilities for Ever Works platform

原始使用文档
文档目录16 节
  1. Overview
  2. Installation
  3. Key Features
  4. Package Structure
  5. Usage
  6. Creating a Basic Plugin
  7. Creating a Git Provider Plugin
  8. Creating a Pipeline Modifier Plugin
  9. Testing Plugins
  10. Available Capabilities
  11. Git Provider Architecture
  12. Type Guards
  13. Exports
  14. Main Export
  15. Subpath Exports
  16. License

@ever-works/plugin

Plugin system contracts, helpers, and utilities for the Ever Works platform.

Overview

This package provides everything needed to build plugins for the Ever Works ecosystem:

  • Contracts: TypeScript interfaces defining plugin capabilities
  • Abstract Classes: Base implementations for common plugin types
  • Helpers: Utility functions for settings, validation, and context
  • Testing Utilities: Mocks and test harnesses for plugin development

Installation

pnpm add @ever-works/plugin

Key Features

  • Standalone: No NestJS dependencies - plugins work in any TypeScript environment
  • Type-Safe: Compile-time validation with TypeScript unions and mapped types
  • Capability-Based: Plugins declare capabilities and implement corresponding interfaces
  • Testable: Built-in mocks and test harnesses for comprehensive testing

Package Structure

@ever-works/plugin
├── /contracts      # Plugin interfaces and capability definitions
├── /pipeline       # Pipeline step types and execution context
├── /events         # Event system types
├── /settings       # Settings types and JSON Schema definitions
├── /common         # Shared types (domain, item, form-field)
├── /helpers        # Utility functions
├── /abstract       # Abstract base classes
└── /testing        # Test utilities and mocks

Usage

Creating a Basic Plugin

import { BasePlugin, type PluginContext, type ValidationResult } from '@ever-works/plugin';

export class MyPlugin extends BasePlugin {
    readonly id = 'my-plugin';
    readonly name = 'My Plugin';
    readonly version = '1.0.0';
    readonly category = 'utility';
    readonly capabilities = ['custom'] as const;

    async onLoad(context: PluginContext): Promise<void> {
        await super.onLoad(context);
        this.log('Plugin loaded!');
    }
}

Creating a Git Provider Plugin

Git provider plugins implement IGitProviderPlugin which includes:

  • Authentication methods: getAuth(), getCloneUrl(), getWebUrl()
  • Repository API operations: createRepository(), getRepository(), deleteRepository()
  • User/Org operations: getUser(), getOrganizations()
  • Pull Request operations: createPullRequest(), mergePullRequest()
  • Branch operations: listBranches()

Local git operations (clone, push, commit) are provided by the platform's GitProvider base class in packages/agent.

import { BaseGitProvider, type IGitProviderPlugin, type GitAuth } from '@ever-works/plugin';

export class GitHubPlugin extends BaseGitProvider implements IGitProviderPlugin {
    readonly id = 'github';
    readonly name = 'GitHub';
    readonly version = '1.0.0';
    readonly providerName = 'github';

    // Provider-specific authentication
    getAuth(token: string): GitAuth {
        return { username: 'x-access-token', password: token };
    }

    getCloneUrl(owner: string, repo: string): string {
        return `https://github.com/${owner}/${repo}.git`;
    }

    getWebUrl(owner: string, repo: string): string {
        return `https://github.com/${owner}/${repo}`;
    }

    // API Operations (provider-specific implementation)
    async createRepository(options, token) {
        // Use Octokit or fetch to call GitHub API
    }

    async getRepository(owner, repo, token) {
        // Use Octokit or fetch to call GitHub API
    }

    async getUser(token) {
        // Use Octokit or fetch to call GitHub API
    }

    async getOrganizations(token) {
        // Use Octokit or fetch to call GitHub API
    }

    async listBranches(owner, repo, token) {
        // Use Octokit or fetch to call GitHub API
    }

    async createPullRequest(options, token) {
        // Use Octokit or fetch to call GitHub API
    }

    async mergePullRequest(owner, repo, prNumber, options, token) {
        // Use Octokit or fetch to call GitHub API
    }

    async deleteRepository(owner, repo, token) {
        // Use Octokit or fetch to call GitHub API
    }

    // Local git operations - inherited from platform's GitProvider
    // clone, push, commit, pull, etc. are implemented once and shared
}

Creating a Pipeline Modifier Plugin

Pipeline modifiers add, replace, or disable steps in an existing pipeline:

import { BasePipelineStep, type IPipelineModifierPlugin, type IPipelineContext } from '@ever-works/plugin';

export class MyModifierPlugin extends BasePipelineStep implements IPipelineModifierPlugin {
    readonly id = 'my-modifier';
    readonly name = 'My Modifier';
    readonly version = '1.0.0';
    readonly targetPipelines = ['standard-pipeline'];

    getStepDefinition() {
        return {
            id: 'custom-step',
            name: 'Custom Step',
            position: { type: 'after', stepId: 'web-search' },
            provides: ['customData']
        };
    }

    async execute(context: IPipelineContext): Promise<IPipelineContext> {
        // Your logic here
        return context;
    }
}

Testing Plugins

import { createMockPluginContext, createTestHarness, testBasePluginContract } from '@ever-works/plugin/testing';

describe('MyPlugin', () => {
    it('passes contract tests', async () => {
        const plugin = new MyPlugin();
        const results = await testBasePluginContract(plugin);
        expect(results.every((r) => r.passed)).toBe(true);
    });

    it('loads correctly', async () => {
        const plugin = new MyPlugin();
        const harness = createTestHarness(plugin, {
            settings: { apiKey: 'test-key' }
        });

        await harness.load();

        expect(harness.isLoaded).toBe(true);
    });
});

Available Capabilities

CapabilityInterfaceDescription
git-providerIGitProviderPluginGit repository & API operations
oauthIOAuthPluginOAuth-based authentication
deploymentIDeploymentPluginDeploy to hosting platforms
screenshotIScreenshotPluginCapture web page screenshots
searchISearchPluginWeb search integration
content-extractorIContentExtractorPluginExtract content from web pages
data-sourceIDataSourcePluginExternal data sources
ai-providerIAiProviderPluginAI/LLM providers
pipelineIPipelinePluginPipeline implementations
pipeline-modifierIPipelineModifierPluginPipeline step modifiers
form-fieldIFormFieldPluginCustom form fields
sub-providerISubProviderPluginSub-provider implementations
config-awareIConfigAwarePluginReact to config changes
custom-capabilityICustomCapabilityPluginDefine custom capabilities

Git Provider Architecture

The git provider system separates concerns:

  1. IGitOperations - Local git operations (clone, push, commit, pull)

    • Implemented once in the platform using isomorphic-git
    • Shared by all git providers (GitHub, GitLab, etc.)
  2. IGitProviderPlugin - Provider-specific API operations

    • Each provider implements their own API calls
    • Includes: createRepository, getPullRequest, getUser, etc.
  3. IOAuthPlugin - OAuth authentication (separate capability)

    • For providers that support OAuth
    • Can be combined with git-provider capability
┌─────────────────────────────────────────────────────────────────┐
│                    GIT PROVIDER ARCHITECTURE                     │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  IGitOperations (local git - shared implementation)             │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ cloneOrPull(), pull(), push(), commit(), add(), addAll()│    │
│  │ getCurrentBranch(), switchBranch(), getStatus()         │    │
│  │ getLocalDir(), removeLocalDir()                         │    │
│  │                                                          │    │
│  │ Implemented once in platform (packages/agent)           │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                  │
│  IGitProviderPlugin (provider API - each plugin implements)     │
│  ┌─────────────────────────────────────────────────────────┐    │
│  │ getAuth(), getCloneUrl(), getWebUrl()                   │    │
│  │ createRepository(), getRepository(), deleteRepository() │    │
│  │ getUser(), getOrganizations()                           │    │
│  │ createPullRequest(), mergePullRequest(), listBranches() │    │
│  │                                                          │    │
│  │ GitHub uses Octokit, GitLab uses their API, etc.        │    │
│  └─────────────────────────────────────────────────────────┘    │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Type Guards

import { isGitProviderPlugin, isAiProviderPlugin, hasCapability } from '@ever-works/plugin';

if (isGitProviderPlugin(plugin)) {
    const repo = await plugin.getRepository('owner', 'repo', token);
}

if (hasCapability(plugin, 'ai-provider')) {
    const models = await plugin.listModels();
}

Exports

Main Export

import { IPlugin, BasePlugin, createMockPluginContext } from '@ever-works/plugin';

Subpath Exports

// Contracts only
import { IPlugin, IGitProviderPlugin, IGitOperations } from '@ever-works/plugin/contracts';

// Pipeline types
import { IPipelineContext, PipelineStepDefinition } from '@ever-works/plugin/pipeline';

// Events
import { PluginEventName, PluginEventPayloads } from '@ever-works/plugin/events';

// Settings
import { JsonSchema, ValidationResult } from '@ever-works/plugin/settings';

// Common types
import { DomainType, ItemData, Category } from '@ever-works/plugin/common';

// Helpers
import { resolveSetting, validateString } from '@ever-works/plugin/helpers';

// Abstract classes
import { BasePlugin, BaseGitProvider } from '@ever-works/plugin/abstract';

// Testing
import { createMockPluginContext, createTestHarness } from '@ever-works/plugin/testing';

License

AGPL-3.0

版本与发布记录

@ever-works/plugin 共发布 17 个版本,首次发布于 2026/09/21;过去 12 个月发布了 17 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.2.16latest2026/11/0310 天前
1.2.152026/10/2816 天前
1.2.142026/10/2816 天前
1.2.132026/10/2817 天前
1.2.122026/10/2717 天前
1.2.112026/10/2717 天前

关于 @ever-works/plugin 的常见问题

@ever-works/plugin 是什么?

Plugin system contracts, helpers, and utilities for Ever Works platform

如何安装 @ever-works/plugin?

在项目目录运行 npm install @ever-works/plugin,或使用 pnpm add / yarn add / bun add。

@ever-works/plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ever-works/plugin 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ever-works/plugin 可以商用吗?

@ever-works/plugin 使用 AGPL-3.0 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@ever-works/plugin 的下载量有多少?

根据 npm 官方下载统计,@ever-works/plugin 在 2026/10/14 – 2026/11/12 这 30 天内被下载 7,176 次,日均约 239 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ever-works/plugin 还在维护吗?

最新版本 1.2.16 发布于 2026/11/03(10 天前);至今共发布 17 个版本,其中过去 12 个月发布了 17 个;首次发布于 2026/09/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。