src — types

Module: src-types Cohesion: 0.80 Members: 0

src — types

The src/types module serves as the central repository for core TypeScript type definitions and interfaces used throughout the codebase. Its primary purpose is to establish clear contracts for data structures, API interactions, agent behaviors, and utility objects, ensuring consistency, type safety, and maintainability across different components.

By centralizing these definitions, src/types prevents type duplication, reduces the risk of inconsistencies, and provides a single source of truth for understanding the shape of critical data.

Module Overview

This module is organized into several files, each focusing on a specific domain of types:

Detailed Type Categories

Agent Core Types (src/types/agent.ts)

This file defines the Agent interface, which is the cornerstone for any AI agent implementation within the system. It outlines the essential capabilities an agent must provide to interact with users, manage chat history, and handle its lifecycle.

export interface Agent {
  processUserMessage(message: string): Promise<ChatEntry[]>;
  processUserMessageStream(message: string): AsyncGenerator<StreamingChunk, void, unknown>;
  getChatHistory(): ChatEntry[];
  clearChat(): void;
  dispose(): void;
}

API Interaction Types (src/types/api.ts)

This module provides a robust set of types for defining and interacting with LLM APIs, particularly focusing on chat completions and function calling. It ensures that API requests and responses conform to expected structures, facilitating integration with various LLM providers.

Key interfaces include:

Utility Functions

This module also includes critical utility functions for handling tool calls:

API Type Relationships

The following Mermaid diagram illustrates the relationships between key API types, particularly how tool definitions and calls are structured:

graph TD
    A[ChatRequestPayload] --> B[ChatMessage]
    B -- "messages[]" --> B
    B -- "tool_calls?[]" --> C[ToolCall]
    A -- "tools?[]" --> D[ToolDefinition]
    D -- "function" --> E[ToolFunction]
    C -- "function" --> F[ToolCallFunction]
    E -- "parameters" --> G[ToolParameter]
    C -- "parsed by" --> H[ParsedToolCall]
    F[ToolCallFunction] -- "name, arguments: string"
    H[ParsedToolCall] -- "name, arguments: T"

Cache Management Types (src/types/cache-types.ts)

This comprehensive module provides a standardized set of types for implementing and interacting with various caching mechanisms. It promotes consistency across different cache implementations (e.g., in-memory, LRU, semantic).

Key categories of types include:

Utility Functions

The module also provides helper functions:

Tooling & Execution Types (src/types/index.ts)

This file serves as an aggregation point for various core types and also defines types specific to tool execution and agent state management.

Key interfaces and types include:

Utility Functions

Error Handling Types (src/types/errors.ts)

This module is deprecated. It exists solely for backward compatibility and re-exports all error-related types and utilities from ../errors/index.js. New code should directly import from src/errors/index.ts.

Usage Patterns

The types defined in src/types are foundational and are used across almost every major component of the application:

By providing a consistent and well-defined type system, src/types significantly enhances the clarity, robustness, and extensibility of the entire codebase.