Atomic-Germ/AIm

AI Instant Messenger - It's more of a game.

★ 0Forks 0GoGitHub ↗Compare

README

AI Instant Messenger (AIM)

Written in Go with the following components:

  • Protocol Layer (internal/protocol/)
  • FLAP framing — implements the OSCAR protocol's frame layer with proper sequence number tracking per direction, 6-byte headers, and payload length encoding
  • SNAC encoding/decoding — handles all foodgroup messages (OSERVICE, BUDDY, ICQ, CBMESSAGE) with TLV serialization/deserialization in network byte order
  • Hash-based memory — MemoryKey() computes SHA-256 of source text so identical texts reinforce rather than duplicate; MemoryStore tracks hidden/active states

It's constructed in layers:

  • Server Layer (internal/oscar/, cmd/server/main.go)

    • TCP listener on port 5190 accepting OSCAR clients, wrapping each in a FLAP session with per-connection state machine
    • Foodgroup dispatch — routes BUDDY (presence/rights), ICQ (status), CBMESSAGE (chat) messages to handlers
    • HTTP API on port 8080 for user management, sessions, messaging, and AI memory endpoints
    • Bootstrap — starts OSCAR server + session manager automatically
  • Store Layer (internal/store/)

    • In-memory store with thread-safe access for users, memories, and conversations
    • SQLite-backed store with schema for users, memories, conversations, and messages (persistent)
    • Hash-based memory keys — MemoryKey() uses SHA-256 so identical texts collapse to same key
  • AI Layer (internal/ai/)

    • Character profiles with system prompts (Riley, Max included by default)
    • Prompt assembly — combines profile + active memories into OpenAI-compatible chat messages
    • LLM client — calls configurable endpoint via AIM_LLM_BASE_URL, AIM_LLM_API_KEY, AIM_LLM_MODEL
    • Presence (internal/presence/)
    • Online/offline/invisible status tracking with session management and periodic cleanup
  • Web Client (cmd/client/)

    • Static HTML/CSS/JS implementing the classic AIM interface: buddy list with avatars/status colors, chat windows, login screen — all styled to match Windows 9x AIM aesthetics

Development

Quickstart

go run cmd/server/main.go &  # API on :8080, OSCAR on :5190
go run cmd/client/main.go &  # web client on :9000

Architecture

  • internal/protocol/ — FLAP framing + SNAC encoding, OSCAR foodgroup constants, hash-based memory
  • internal/oscar/ — TCP listener, per-connection state machine, foodgroup dispatch
  • internal/store/ — in-memory and SQLite-backed stores for users/memory/conversations
  • internal/presence/ — online/offline/invisible status manager + session tracking
  • internal/ai/ — character profiles, memory-augmented prompt assembly, OpenAI-compatible LLM client
  • cmd/server/main.go — HTTP API (users, sessions, messages, memories) + bootstrap
  • cmd/client/main.go — static web client (buddy list + chat windows)

Key Concepts

  • Hash-based memory: SHA-256 keyed memories; identical texts reinforce rather than duplicate.
  • AIM profile-driven: characters act based on profile + active memories.
  • Unprompted messaging: AI characters can message users without direct request.
  • OpenAI-compatible endpoint via env vars: AIM_LLM_BASE_URL, AIM_LLM_API_KEY, AIM_LLM_MODEL.

Testing

go test ./tests/... -v

Contributors

Atomic-Germ

Issues