daemon

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

SPDX-License-Identifier: GPL-2.0-only

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub manages connected WebSocket clients and broadcasts events.

func NewHub

func NewHub() *Hub

NewHub creates a new hub.

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(channelID int64, channelName string, channelType string, msg db.Message, mentions []string, threadID *int64, database *db.DB)

BroadcastMessage sends a message.new event to all connected members of a channel.

func (*Hub) BroadcastPresence

func (h *Hub) BroadcastPresence(username string, online bool)

BroadcastPresence sends a presence event to all connected clients.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Register

func (h *Hub) Register(client *WSClient)

Register adds a client to the hub.

func (*Hub) Unregister

func (h *Hub) Unregister(client *WSClient)

Unregister removes a client from the hub.

type IdentityToken

type IdentityToken struct {
	Token        string
	Username     string // empty until identified
	Identified   bool
	MCPSessionID string
	PresenceDone chan struct{} // closed when presence should disconnect
	HasPresence  bool
	CreatedAt    time.Time
}

IdentityToken tracks the lifecycle of an identity token.

type MCPSession

type MCPSession struct {
	ID       string
	TokenID  string
	Username string
}

MCPSession links an MCP session ID to a token and user.

type PresenceHandler

type PresenceHandler struct {
	// contains filtered or unexported fields
}

PresenceHandler handles WebSocket presence connections. On connect: creates an identity token and sends it as the first message. Keeps the connection alive with ping/pong. When the client disconnects (or pong times out), the user is marked offline.

func NewPresenceHandler

func NewPresenceHandler(sessions *SessionManager, hub *Hub, pongTimeout time.Duration) *PresenceHandler

NewPresenceHandler creates a new presence handler.

func (*PresenceHandler) ServeHTTP

func (h *PresenceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the sharkfind HTTP server.

func NewServer

func NewServer(addr, dbPath string, allowChannelCreation bool, pongTimeout time.Duration, webhookURL string) (*Server, error)

NewServer creates a new sharkfind server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the server.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for connections.

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

SessionManager manages identity tokens, MCP sessions, and presence state.

func NewSessionManager

func NewSessionManager(database *db.DB) *SessionManager

NewSessionManager creates a new session manager.

func (*SessionManager) AttachPresence

func (sm *SessionManager) AttachPresence(token string) (<-chan struct{}, error)

AttachPresence links a presence connection to a token. Returns a channel that is closed when the presence should disconnect.

func (*SessionManager) CreateIdentityToken

func (sm *SessionManager) CreateIdentityToken() string

CreateIdentityToken generates a new pending identity token.

func (*SessionManager) DisconnectPresence

func (sm *SessionManager) DisconnectPresence(token string)

DisconnectPresence removes the presence for a token and marks the user offline.

func (*SessionManager) GetSession

func (sm *SessionManager) GetSession(mcpSessionID string) (*MCPSession, error)

GetSession returns the MCP session for a given session ID.

func (*SessionManager) Identify

func (sm *SessionManager) Identify(token, username, password string) (string, error)

Identify associates a token with an existing user. Returns an MCP session ID.

func (*SessionManager) IsUserOnline

func (sm *SessionManager) IsUserOnline(username string) bool

IsUserOnline returns true if the user has an active presence connection.

func (*SessionManager) Register

func (sm *SessionManager) Register(token, username, password string) (string, error)

Register creates a new user and associates the token with them. Returns an MCP session ID.

type SharkfinMCP

type SharkfinMCP struct {
	// contains filtered or unexported fields
}

SharkfinMCP wraps an mcp-go MCPServer with Sharkfin's business logic.

func NewSharkfinMCP

func NewSharkfinMCP(sm *SessionManager, database *db.DB, hub *Hub) *SharkfinMCP

NewSharkfinMCP creates the MCP server and registers all tools.

func (*SharkfinMCP) Server

func (s *SharkfinMCP) Server() *server.MCPServer

Server returns the underlying mcp-go MCPServer.

type WSClient

type WSClient struct {
	// contains filtered or unexported fields
}

WSClient represents a connected WebSocket client.

type WSHandler

type WSHandler struct {
	// contains filtered or unexported fields
}

WSHandler handles WebSocket connections for non-MCP clients.

func NewWSHandler

func NewWSHandler(sessions *SessionManager, database *db.DB, hub *Hub, pongTimeout time.Duration) *WSHandler

NewWSHandler creates a new WebSocket handler.

func (*WSHandler) ServeHTTP

func (h *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebhookEvent

type WebhookEvent struct {
	ChannelName string
	ChannelType string
	From        string
	MessageID   int64
	SentAt      time.Time
	Recipients  []string
}

WebhookEvent contains the data needed to fire webhooks for a message.

type WebhookPayload

type WebhookPayload struct {
	Event       string `json:"event"`
	Recipient   string `json:"recipient"`
	Channel     string `json:"channel"`
	ChannelType string `json:"channel_type"`
	From        string `json:"from"`
	MessageID   int64  `json:"message_id"`
	SentAt      string `json:"sent_at"`
}

WebhookPayload is the JSON body POSTed to the webhook URL.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL