Skip to main content

Core Library Overview

The @janhq/core library is the foundation for building extensions in Jan. It provides type definitions, base classes, and an event system that enables seamless integration with the Jan platform.

What is @janhq/core?

@janhq/core is a TypeScript library that exports:
  • Type definitions for models, messages, threads, and more
  • Base extension classes to build custom extensions
  • Event system for communication between components
  • Interfaces for implementing model management and inference capabilities

Installation

npm install @janhq/core

Core Exports

The library exports from several modules:
export * from './types'
export * from './browser'

Available Type Modules

Model Types

Types for model definitions, settings, and parameters

Message Types

Types for messages, threads, and conversations

Assistant Types

Types for assistant configuration and tools

Inference Types

Types for chat completion and inference requests

Key Concepts

Extensions

Extensions are the building blocks of Jan. Each extension extends the BaseExtension class and implements specific functionality.
import { BaseExtension, ExtensionTypeEnum } from '@janhq/core'

export default class MyExtension extends BaseExtension {
  type(): ExtensionTypeEnum {
    return ExtensionTypeEnum.Model
  }

  onLoad(): void {
    console.log('Extension loaded')
  }

  onUnload(): void {
    console.log('Extension unloaded')
  }
}

Event System

The event system enables communication between extensions and the core application.
import { events, MessageEvent } from '@janhq/core'

// Listen for events
events.on(MessageEvent.OnMessageSent, (data) => {
  console.log('Message sent:', data)
})

// Emit events
events.emit(MessageEvent.OnMessageResponse, messageData)

Type Safety

All types are fully typed with TypeScript, providing excellent IntelliSense support and compile-time safety.
import { Model, Thread, ThreadMessage } from '@janhq/core'

const model: Model = {
  id: 'my-model',
  name: 'My Model',
  // ... TypeScript ensures all required fields are present
}

Global Core Object

The library declares a global core object used internally:
declare global {
  var core: any | undefined
}
The global core object is for internal use. Extensions should use the exported APIs and events system.

Next Steps

Type Definitions

Explore all available TypeScript types

Event System

Learn about the event-driven architecture

Extension Base Classes

Build your first extension

Model Interface

Implement model management

Build docs developers (and LLMs) love