Skip to content

Abstract Class: BaseLogImporter<TRecord, TState>

Makaio Framework


Makaio Framework / ai-adapters-core / BaseLogImporter

Abstract Class: BaseLogImporter<TRecord, TState>

Section titled “Abstract Class: BaseLogImporter<TRecord, TState>”

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:27

Abstract base class for log importers.

Provides default processLogFile() implementation that composes extractSessionContext() + processRecords(). Adapters implement the abstract methods for their specific log format.

TRecord

The tool’s native log record type

TState = unknown

The resumable state type

new BaseLogImporter<TRecord, TState>(): BaseLogImporter<TRecord, TState>

BaseLogImporter<TRecord, TState>

abstract canHandle(sample): boolean | { confidence: number; }

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:29

Check if this importer can handle the given log sample.

Used for auto-detection during log upload to match importers with unknown log formats. Inspects a sample record/line to determine compatibility.

string | JsonObject

Sample log content (JSONL line or parsed JSON object)

boolean | { confidence: number; }

Boolean or confidence score (0-1) indicating compatibility

Simple implementations return boolean. Advanced implementations can return a confidence score for disambiguation when multiple importers claim support.

Example implementations:

  • Claude Code: Check for type field in ['started', 'message', 'tool_use']
  • Codex: Check for event field matching Codex schema patterns
  • Gemini: Check for Gemini-specific log structure

Return { confidence: 0.95 } for high confidence matches, { confidence: 0.5 } for ambiguous formats, or false for incompatible.

LogImporter.canHandle


abstract deserializeState(raw): TState

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:48

Restore adapter state from cursor.

Converts the serialized state back to the adapter’s typed state when resuming from a persisted cursor.

JsonObject

Serialized state from cursor storage

TState

Restored adapter-specific state

LogImporter.deserializeState


abstract extractDiscoveryMetadata(filePath): Promise<DiscoveryMetadata>

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:44

Extract discovery metadata from a log file without importing full message history.

string

Absolute path to the source log file

Promise<DiscoveryMetadata>

Discovery metadata when parsing succeeds; rejects on unrecoverable read/parse errors

LogImporter.extractDiscoveryMetadata


abstract extractSessionContext(records): LogImportSessionContext<TState>

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:45

Extract session context from records (called on first read only).

Creates the session context including session/started events and initial adapter state. This is only called when no existing cursor context exists (i.e., first time reading this file).

TRecord[]

Initial batch of parsed records from the file

LogImportSessionContext<TState>

Session context with events and initial state

The returned context is persisted in the cursor and restored on subsequent reads via deserializeState.

LogImporter.extractSessionContext


abstract getLogDirectory(): string

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:30

Get the root directory containing this tool’s log files.

string

Absolute path to the log directory (may contain subdirectories)

Examples of log directories:

  • Claude Code: ~/.claude/projects/ (contains session.jsonl files)
  • Codex: ~/.codex/sessions/ (date-organized subdirectories)
  • Gemini: ~/.gemini/tmp/ (hash-organized project directories)

LogImporter.getLogDirectory


abstract isMakaioManaged(sessionId): Promise<boolean>

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:38

Check if a session is managed by Makaio (should be skipped during import).

string

The external tool’s session identifier

Promise<boolean>

True if Makaio manages this session, false if it should be imported

This prevents re-importing sessions that Makaio already tracks via live streaming. Implementation typically queries AdapterSessionStorage for the sessionId to check if the session has status=‘live’.

May be async to support database lookups.

LogImporter.isMakaioManaged


abstract parseRecord(line, sourceFilePath?): TRecord | null

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:37

Parse a single log record from raw input.

string | JsonObject

Raw log line or parsed JSON object to parse

string

Optional source file path for format-specific context

TRecord | null

Parsed record or null when the input does not match the adapter format

LogImporter.parseRecord


processLogFile(records): ProcessLogFileResult

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:59

Process a complete log file in a single call.

Composes extractSessionContext + processRecords + message extraction. Adapters that need special handling (fork detection, field normalization) should override this method.

TRecord | TRecord[]

All parsed records from the log file

ProcessLogFileResult

Combined session metadata, events, and message payloads

LogImporter.processLogFile


abstract processRecords(records, context): NormalizedEvent[]

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:46

Process records into events (context always provided).

Converts adapter-specific records to normalized Makaio events using the provided session context. Updates context.state as needed for stateful processing (e.g., turn tracking).

TRecord[]

Batch of parsed records to process

LogImportSessionContext<TState>

Session context (from extractSessionContext or restored)

NormalizedEvent[]

Array of normalized events (may be empty)

This replaces the stateless toNormalizedEvents method. The context provides session metadata and mutable adapter state for tracking things like conversation turns across chunks.

Implementations should add ImportMetadata to payloads under the _import key for provenance tracking.

LogImporter.processRecords


abstract serializeState(state): JsonObject

Defined in: ../../../adapters/core/src/log-importer/base-importer.ts:47

Serialize adapter state for cursor persistence.

Converts the adapter’s typed state to a JSON-serializable object for storage in the cursor.

TState

Adapter-specific state to serialize

JsonObject

JSON-serializable representation of the state

LogImporter.serializeState