# Class TemplateRegistry

Template registry implementation. Manages both built-in and custom workflow templates.

#### Implements

- ITemplateRegistry

- Defined in packages/nexus-agents/src/workflows/template-registry.ts:33

##### Index

### Constructors

constructor

### Accessors

size
isEmpty

### Methods

initialize
getBuiltIn
getAll
getById
register
unregister
loadFromDirectory
search
getByCategory
clearCustom
get
has
getAllIds
query
clear
getStats

## Constructors

### constructor

- new TemplateRegistry(): TemplateRegistry

  #### Returns TemplateRegistry

## Accessors

### size

- get size(): number

  Get the number of registered templates. IRegistry interface method.

  #### Returns number

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:304

### isEmpty

- get isEmpty(): boolean

  Check if the registry is empty. IRegistry interface method.

  #### Returns boolean

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:312

## Methods

### initialize

- initialize(): Promise<void>

  Initialize the registry with built-in templates. Called automatically on first access if not already initialized. Uses promise coalescing to prevent duplicate init from concurrent calls.

  #### Returns Promise<void>

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:44

### getBuiltIn

- getBuiltIn(): TemplateMetadata[]

  Get all built-in templates.

  #### Returns TemplateMetadata[]

  Implementation of ITemplateRegistry.getBuiltIn

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:75

### getAll

- getAll(): TemplateMetadata[]

  Get all registered templates.

  #### Returns TemplateMetadata[]

  Implementation of ITemplateRegistry.getAll

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:82

### getById

- getById(id: string): WorkflowDefinition | undefined

  Get a workflow definition by ID.

  #### Parameters

  - id: string

  #### Returns WorkflowDefinition | undefined

  Implementation of ITemplateRegistry.getById

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:89

### register

- register(
  workflow: WorkflowDefinition,
  partialMetadata?: Partial<TemplateMetadata>,
  ): void

  Register a custom workflow template.

  #### Parameters

  - workflow: WorkflowDefinition
  - `Optional` partialMetadata: Partial<TemplateMetadata>

  #### Returns void

  Implementation of ITemplateRegistry.register

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:96

### unregister

- unregister(id: string): boolean

  Unregister a custom template.

  #### Parameters

  - id: string

  #### Returns boolean

  Implementation of ITemplateRegistry.unregister

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:145

### loadFromDirectory

- loadFromDirectory(directoryPath: string): Promise<number>

  Load templates from a directory.

  #### Parameters

  - directoryPath: string

  #### Returns Promise<number>

  Implementation of ITemplateRegistry.loadFromDirectory

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:164

### search

- search(query: string): TemplateMetadata[]

  Search templates by keyword.

  #### Parameters

  - query: string

  #### Returns TemplateMetadata[]

  Implementation of ITemplateRegistry.search

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:202

### getByCategory

- getByCategory(category: TemplateCategory): TemplateMetadata[]

  Get templates by category.

  #### Parameters

  - category: TemplateCategory

  #### Returns TemplateMetadata[]

  Implementation of ITemplateRegistry.getByCategory

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:220

### clearCustom

- clearCustom(): void

  Clear all custom templates (keeps built-in).

  #### Returns void

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:227

### get

- get(id: string): Result<TemplateMetadata, TemplateRegistryError>

  Get template metadata by ID. IRegistry interface method.

  #### Parameters

  - id: string

    Template ID to retrieve

  #### Returns Result<TemplateMetadata, TemplateRegistryError>

  Result with TemplateMetadata or TemplateRegistryError

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:253

### has

- has(id: string): boolean

  Check if a template is registered. IRegistry interface method.

  #### Parameters

  - id: string

    Template ID to check

  #### Returns boolean

  True if template is registered

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:275

### getAllIds

- getAllIds(): string[]

  Get all registered template IDs. IRegistry interface method.

  #### Returns string[]

  Array of all registered template IDs

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:285

### query

- query(predicate: (item: TemplateMetadata) => boolean): TemplateMetadata[]

  Query templates with predicate function. IRegistry interface method.

  #### Parameters

  - predicate: (item: TemplateMetadata) => boolean

    Function to test each template

  #### Returns TemplateMetadata[]

  Array of matching templates

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:296

### clear

- clear(): void

  Clear all templates (built-in and custom). IRegistry interface method.

  WARNING: This removes built-in templates. Use clearCustom() to only clear custom templates.

  #### Returns void

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:322

### getStats

- getStats(): IRegistryStats & { builtIn: number; custom: number }

  Get registry statistics. IRegistry interface method with domain-specific extensions.

  #### Returns IRegistryStats & { builtIn: number; custom: number }

  - Defined in packages/nexus-agents/src/workflows/template-registry.ts:332