Skip to main content

Agent Package Overview

The @ever-works/agent package is the core logic layer of the Ever Works platform. It encapsulates all AI-powered content generation, database access, plugin runtime, git operations, pipeline orchestration, and entity definitions used by the API and background job systems. It is a private NestJS library package that is never published to npm.

Overview

PropertyValue
Package name@ever-works/agent
Locationplatform/packages/agent/
FrameworkNestJS 11 (SWC compiler)
ORMTypeORM 0.3
Test runnerJest (26 suites, 719+ tests)
LicenseUNLICENSED (private)
Node.js>=20

Module Structure

The package is organized into 20 sub-module works, each published as a separate export path:

packages/agent/src/
├── cache/ # Persistent caching layer (TypeORM-backed Keyv adapter)
├── community-pr/ # Community pull request processing
├── comparison-generator/ # Item comparison page generation
├── config/ # Configuration management
├── constants/ # Shared constants
├── database/ # TypeORM database module and repositories
├── work-operations/ # Work lifecycle state management
├── dto/ # Data transfer objects and validation schemas
├── entities/ # TypeORM entity definitions
├── events/ # Domain event classes
├── facades/ # AI facade service (plugin consumer)
├── generators/ # AI content generation engine
├── import/ # Work import from external sources
├── items-generator/ # Item-level content generation
├── notifications/ # Notification system
├── pipeline/ # Generation pipeline orchestration
├── plugins/ # Plugin runtime (discovery, loading, lifecycle)
├── services/ # Shared business services
├── subscriptions/ # Subscription and usage management
├── tasks/ # Background task definitions and types
└── utils/ # Shared utility functions

Package Exports

Each sub-module is exposed as a dedicated export path in package.json, enabling consumers to import only what they need:

// Import specific sub-modules
import { DataGeneratorService } from '@ever-works/agent/generators';
import { WorkRepository } from '@ever-works/agent/database';
import { Work } from '@ever-works/agent/entities';
import { WorkOperationsService } from '@ever-works/agent/work-operations';
import { PluginsModule } from '@ever-works/agent/plugins';
import { AiFacadeService } from '@ever-works/agent/facades';
import { PipelineModule } from '@ever-works/agent/pipeline';

The full list of export paths:

Export PathDescription
@ever-works/agent/generatorsAI content generation engine and data generators
@ever-works/agent/databaseTypeORM module, repositories, and database configuration
@ever-works/agent/dtoData transfer objects with class-validator decorators
@ever-works/agent/entitiesTypeORM entity definitions for all domain models
@ever-works/agent/gitGit operations (isomorphic-git based)
@ever-works/agent/work-operationsWork generation state management
@ever-works/agent/items-generatorItem-level content generation
@ever-works/agent/tasksBackground task type definitions
@ever-works/agent/eventsDomain event classes
@ever-works/agent/servicesShared business services
@ever-works/agent/subscriptionsSubscription and usage tracking
@ever-works/agent/configConfiguration management
@ever-works/agent/cachePersistent caching layer
@ever-works/agent/notificationsNotification delivery
@ever-works/agent/importWork import system
@ever-works/agent/facadesAI facade (consumes AI provider plugins)
@ever-works/agent/pluginsPlugin runtime infrastructure
@ever-works/agent/pipelineGeneration pipeline orchestration
@ever-works/agent/utilsShared utility functions
@ever-works/agent/community-prCommunity pull request processing
@ever-works/agent/comparison-generatorComparison page generation

Key Services

Database Layer

The database/ sub-module provides the DatabaseModule and a comprehensive set of TypeORM repositories:

  • WorkRepository -- CRUD for works
  • WorkGenerationHistoryRepository -- Generation run history
  • WorkMemberRepository -- Work team membership
  • UserRepository -- User records
  • ApiKeyRepository -- API key management
  • SubscriptionPlanRepository and UserSubscriptionRepository -- Subscription data
  • WorkScheduleRepository -- Scheduled generation configuration
  • UsageLedgerRepository -- Usage and quota tracking
  • NotificationRepository -- User notifications

Plugin Runtime

The plugins/ sub-module provides the PluginsModule, a global NestJS dynamic module that manages the full plugin lifecycle:

  • PluginRegistryService -- In-memory registry of loaded plugin instances
  • PluginLoaderService -- Discovers and loads plugins from file system or built-in sources
  • PluginLifecycleManagerService -- State machine for plugin load/unload transitions
  • PluginSettingsService -- Multi-layer settings resolution (work > user > admin > env > default)
  • PluginBootstrapService -- Application-level bootstrap and shutdown coordination
  • PluginContextFactoryService -- Creates isolated PluginContext for each plugin
  • CustomCapabilityRegistryService -- Registry for plugin-defined capabilities

AI Facades

The facades/ sub-module contains AiFacadeService, which provides a unified interface for all AI operations. It consumes AI provider plugins (OpenAI, Anthropic, Google, etc.) and routes requests to the currently configured provider with resolved settings.

Generation Pipeline

The pipeline/ sub-module orchestrates multi-step content generation workflows. It coordinates the generators, git operations, deployment triggers, and status updates into a coherent pipeline.

Entity Model

Core TypeORM entities defined in entities/:

EntityTableDescription
WorkworksCentral domain entity representing a work project
WorkGenerationHistorywork_generation_historyAudit log of every generation run
WorkSchedulework_schedulesScheduled update configuration
WorkMemberwork_membersTeam membership and roles
WorkCustomDomainwork_custom_domainsCustom domain mappings
UserusersPlatform user accounts

Configuration

The package uses NestJS @nestjs/config for configuration management. Database connection settings are resolved through the DatabaseConfigFactory:

import { DatabaseModule } from '@ever-works/agent/database';

@Module({
imports: [
DatabaseModule.forRoot({
type: 'postgres',
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT, 10),
database: process.env.DB_NAME,
username: process.env.DB_USER,
password: process.env.DB_PASSWORD
})
]
})
export class AppModule {}

The package supports PostgreSQL, MySQL, and SQLite (via optional peer dependencies).

Dependencies

Runtime Dependencies

PackagePurpose
@ever-works/contractsShared TypeScript types (workspace)
@ever-works/pluginPlugin system contracts and utilities (workspace)
typeormDatabase ORM
@nestjs/typeormNestJS TypeORM integration
@nestjs/configConfiguration management
@nestjs/swaggerAPI documentation decorators
@nestjs/cache-managerCache abstraction
@langchain/textsplittersText chunking for AI operations
zod / ajvSchema validation
class-transformer / class-validatorDTO transformation and validation
lodashUtility functions
p-mapConcurrent async mapping
yamlYAML parsing
superjsonExtended JSON serialization
github-sluggerURL-safe slug generation
semverSemantic version comparison
date-fnsDate utility functions

Peer Dependencies

PackageVersionNotes
@nestjs/common^11.1Required
@nestjs/core^11.1Required
@nestjs/event-emitter^3.0Required
@nestjs/platform-express^11.1Required
reflect-metadata^0.2Required
rxjs^7.8Required
better-sqlite3^12.2Optional -- SQLite support
pg^8.16Optional -- PostgreSQL support
mysql2^3.14Optional -- MySQL support

Build and Test

Build

The package uses a dual build: SWC for fast JavaScript compilation and tsc for declaration file generation:

# Full build
cd packages/agent && pnpm build

# Watch mode (development)
cd packages/agent && pnpm dev

The build script runs nest build -b swc followed by tsc -p tsconfig.types.json to produce both JavaScript output and .d.ts type declarations under dist/.

Test

# Run all tests
cd packages/agent && pnpm test

# Run tests matching a pattern
cd packages/agent && npx jest --testPathPattern='work-operations'

# Watch mode
cd packages/agent && pnpm test:watch

# Coverage report
cd packages/agent && pnpm test:cov

Jest is configured with moduleNameMapper entries that resolve @ever-works/plugin and @ever-works/contracts to their source works, avoiding the need to build workspace dependencies before running tests.

Usage Examples

Importing the Package in an API Module

import { Module } from '@nestjs/common';
import { DatabaseModule } from '@ever-works/agent/database';
import { WorkOperationsModule } from '@ever-works/agent/work-operations';
import { PluginsModule } from '@ever-works/agent/plugins';

@Module({
imports: [
DatabaseModule.forRoot(/* config */),
WorkOperationsModule,
PluginsModule.forRoot({
autoLoadBuiltIn: true,
environment: 'production'
})
]
})
export class ApiModule {}

Working with Entities

import { Work } from '@ever-works/agent/entities';
import { WorkRepository } from '@ever-works/agent/database';

@Injectable()
export class WorkService {
constructor(private readonly workRepo: WorkRepository) {}

async findBySlug(slug: string): Promise<Work | null> {
return this.workRepo.findOne({ where: { slug } });
}
}

Using the AI Facade

import { AiFacadeService } from '@ever-works/agent/facades';

@Injectable()
export class ContentService {
constructor(private readonly aiFacade: AiFacadeService) {}

async generateDescription(prompt: string): Promise<string> {
const response = await this.aiFacade.createChatCompletion({
messages: [{ role: 'user', content: prompt }]
});
return response.content;
}
}