Skip to content

feat: Export AI module components for public use#40

Open
konard wants to merge 3 commits intoivansglazunov:mainfrom
konard:issue-19-bda9f8b8
Open

feat: Export AI module components for public use#40
konard wants to merge 3 commits intoivansglazunov:mainfrom
konard:issue-19-bda9f8b8

Conversation

@konard
Copy link

@konard konard commented Oct 26, 2025

Summary

This PR implements issue #19 by exporting the complete AI module from the Hasyx package, making all AI components publicly available for import and use.

Problem

The Hasyx AI module (documented in AI.md) was fully implemented but not exported from lib/server.ts, making it impossible for applications to import and use the AI functionality.

Related issues:

Solution

Added comprehensive exports to lib/server.ts for all AI module components:

Core Components

  • AI - Base AI class with memory management
  • Dialog - Event-driven conversation orchestrator
  • DialogParser - Thinking buffer parser for streaming
  • Tool - Abstract base class for tools
  • Tooler - Tool execution manager

Utilities

  • createSystemPrompt - System prompt builder
  • printConsole - Console output formatting
  • Terminal and Telegram integration helpers

AI Providers

  • OllamaProvider - Local model support via Ollama
  • OpenRouterProvider - Cloud model support via OpenRouter
  • ApiRouteProvider - API route provider

Tools

  • ExecJSTool - JavaScript code execution
  • ExecTsxTool - TypeScript code execution
  • TerminalTool - Terminal command execution

Handlers

  • api-dialog - API dialog handler

Architecture

The AI module provides an event-driven architecture for LLM interactions:

import { Dialog, OpenRouterProvider, ExecJSTool, TerminalTool } from 'hasyx/lib/server';

const dialog = new Dialog({
  provider: new OpenRouterProvider({ 
    token: process.env.OPENROUTER_API_KEY,
    model: 'deepseek/deepseek-chat-v3-0324:free'
  }),
  tools: [new ExecJSTool(), new TerminalTool()],
  systemPrompt: 'You are a helpful AI assistant.',
  onChange: (event) => {
    console.log('[AI Event]', event.type);
  }
});

await dialog.ask('Calculate the factorial of 5 using JavaScript');

Testing

The AI module includes comprehensive tests:

  • lib/ai/ai.test.ts - Core AI class tests
  • lib/ai/dialog.test.ts - Dialog orchestrator tests
  • lib/ai/dialog-parser.test.ts - Parser tests
  • lib/ai/tooler.test.ts - Tooler tests
  • lib/ai/providers/*.test.ts - Provider tests
  • lib/ai/tools/tools.test.ts - Tool tests

Documentation

Full documentation available in:

Impact

This change enables applications to:

  • Build custom AI assistants with Hasyx
  • Use local models (Ollama) or cloud models (OpenRouter)
  • Create custom tools for AI interactions
  • Implement event-driven AI workflows
  • Leverage the full AI module architecture

Closes #19

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: undefined
@vercel
Copy link

vercel bot commented Oct 26, 2025

@konard is attempting to deploy a commit to the ivansglazunov's projects Team on Vercel.

A member of the Team first needs to authorize it.

This commit adds comprehensive exports for the AI module, making all core
components publicly available for import. This resolves issue ivansglazunov#19.

Exported components:
- Core AI classes: AI, Dialog, DialogParser, Tool, Tooler
- Utilities: core-prompts, console, terminal, telegram
- Providers: OllamaProvider, OpenRouterProvider, ApiRouteProvider
- Tools: ExecJSTool, ExecTsxTool, TerminalTool
- Handlers: api-dialog

The AI module architecture is fully documented in AI.md and includes:
- Event-driven conversation management via Dialog class
- Pluggable AI provider interface (Ollama for local, OpenRouter for cloud)
- Tool system for executing code and terminal commands
- Real-time streaming support

Related issues: ivansglazunov#20 (Ask CLI), ivansglazunov#21 (Ollama), ivansglazunov#22 (OpenRouter)

Fixes ivansglazunov#19
@konard konard changed the title [WIP] AI feat: Export AI module components for public use Oct 26, 2025
@konard konard marked this pull request as ready for review October 26, 2025 16:09
@konard
Copy link
Author

konard commented Oct 26, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

📎 Log file uploaded as GitHub Gist (389KB)
🔗 View complete solution draft log


Now working session is ended, feel free to review and add any feedback on the solution draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI

1 participant