Skip to main content

Items Generator Module

The Items Generator module handles individual item operations within a work -- submitting new items, removing existing items, and updating item metadata. It operates directly on the data Git repository using branch-based workflows with optional pull request creation.

Sources:

  • packages/agent/src/items-generator/items-generator.module.ts
  • packages/agent/src/items-generator/item-submission.service.ts
  • packages/agent/src/items-generator/dto/
  • packages/agent/src/items-generator/schemas/item-extraction.schemas.ts

Module Structure

items-generator/
dto/
create-items-generator.dto.ts # Generation trigger DTOs
submit-item.dto.ts # Single item submission
submit-item-response.dto.ts # Submission response
remove-item.dto.ts # Item removal request
remove-item-response.dto.ts # Removal response
update-item.dto.ts # Metadata update
extract-item-details.dto.ts # Detail extraction request
extract-item-details-response.dto.ts
items-generator-response.dto.ts # Generation response
delete-items-generator.dto.ts # Work deletion
index.ts # Barrel export
schemas/
item-extraction.schemas.ts # Zod schemas for AI extraction
item-submission.service.ts # Core submission logic
items-generator.module.ts # NestJS module definition
index.ts # Public API

NestJS Module

@Module({
imports: [DatabaseModule, FacadesModule, PipelineModule],
providers: [ItemSubmissionService],
exports: [ItemSubmissionService]
})
export class ItemsGeneratorModule {}

The module is intentionally lightweight. Bulk generation is handled by the PipelineOrchestratorService; this module focuses on single-item operations.

ItemSubmissionService

Submit Item

The submitItem method adds a new item to a work's data repository:

const result = await submissionService.submitItem(work, user, {
name: 'VS Code',
description: 'A popular code editor by Microsoft',
source_url: 'https://code.visualstudio.com',
category: 'Editors',
tags: ['ide', 'microsoft', 'open-source']
});

Workflow

  1. Clone/pull the data repository using the work owner's credentials.
  2. Read config to check autoapproval settings.
  3. Determine commit strategy:
ConditionStrategy
create_pull_request === trueAlways create a PR (forced)
pay_and_publish_now === trueDirect commit to main
config.autoapproval === trueDirect commit to main
DefaultCreate a PR
  1. Branch management:

    • For PRs: Create a new branch named item-{slugified-name}-{timestamp}.
    • For direct commits: Switch to the main branch.
  2. Prepare item data with the MutableItemData structure.

  3. Capture screenshot if the item has a source_url and the screenshot service is available.

  4. Write files to the data repository: item JSON and item markdown.

  5. Commit and push using the current user as the committer (for Git attribution).

  6. Create PR (if applicable) with a descriptive title and body including badge information.

Response Types

// Direct commit response
{
status: 'success',
slug: 'my-work',
item_name: 'VS Code',
item_slug: 'vs-code',
direct_commit: true,
item: { /* full item data */ },
}

// PR creation response
{
status: 'success',
slug: 'my-work',
item_name: 'VS Code',
item_slug: 'vs-code',
pr_number: 42,
pr_url: 'https://github.com/...',
pr_branch_name: 'item-vs-code-1234567890',
auto_merged: false,
item: { /* full item data */ },
}

Remove Item

The removeItem method removes an item from the data repository:

const result = await submissionService.removeItem(work, user, {
item_slug: 'vs-code',
reason: 'No longer maintained',
create_pull_request: true
});

Workflow

  1. Clone/pull the data repository.
  2. Verify the item exists via data.itemExists().
  3. Read item details for the response.
  4. Create a branch (if PR requested) or switch to main.
  5. Remove the item work via data.removeItem().
  6. Commit with an optional reason in the message.
  7. Push and optionally create a PR.

Update Item Metadata

The updateItem method modifies metadata fields on an existing item:

const result = await submissionService.updateItem(work, user, {
item_slug: 'vs-code',
featured: true,
order: 1,
create_pull_request: false
});

Supports updating featured status and order position. Uses the same branch/PR strategy as other operations.

DTOs

SubmitItemDto

FieldTypeRequiredDescription
namestringYesItem display name
descriptionstringYesItem description
source_urlstringYesCanonical URL (must be HTTP/HTTPS)
categorystringConditionalSingle category (required if categories is empty)
categoriesstring[]ConditionalCategory array (required if category is empty)
tagsstring[]NoKeywords and labels
featuredbooleanNoFeatured flag (default: false)
ordernumberNoSort order (min: 0)
slugstringNoURL-friendly identifier (auto-generated from name)
brandstringNoBrand/manufacturer name
brand_logo_urlstringNoBrand logo URL
imagesstring[]NoImage URLs
pay_and_publish_nowbooleanNoSkip PR, commit directly
create_pull_requestbooleanNoForce PR creation

RemoveItemDto

FieldTypeRequiredDescription
item_slugstringYesSlug of the item to remove
reasonstringNoReason for removal (included in commit message)
create_pull_requestbooleanNoWhether to create a PR

CreateItemsGeneratorDto

FieldTypeRequiredDescription
namestringYesWork/generation name (max 200 chars)
promptstringYesAI generation prompt (max 5000 chars)
generation_methodGenerationMethodNoCREATE_UPDATE (default) or RECREATE
update_with_pull_requestbooleanNoCreate PRs for updates (default: true)
website_repository_creation_methodWebsiteRepositoryCreationMethodNoTemplate-based creation (default)
providersProvidersDtoNoPlugin selection for AI, search, etc.
pluginConfigRecord<string, unknown>NoPlugin-specific form configuration

Zod Schemas for AI Extraction

The item-extraction.schemas.ts file defines Zod schemas used by the AI pipeline to validate extracted item data:

Core Schemas

SchemaFieldsPurpose
itemDataSchemaname, description, source_url, featured, brand, brand_logo_url, imagesBase item data from extraction
itemDataWithCategoriesAndTagsSchemaExtends itemDataSchema + slug, category, tagsFull item with taxonomy
itemDataWithBadgesSchemaExtends base + badges (security, license, quality)Items with quality badges
extractedItemsSchema{ items: itemDataSchema[] }Batch extraction result
promptUnderstandingAssessmentSchemacan_proceed, reason_if_cannot_proceed, suggested_clarificationsValidates AI prompt understanding

Badge Schema

const badgeSchema = z.object({
value: z.string(),
evaluated_at: z.string().nullable(),
details: z.string().nullable()
});

const itemBadgesSchema = z.record(badgeSchema.nullable());

Badges provide quality indicators (security score, license type, code quality) that are displayed on the generated website.