sharkfin

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalEnvelope

func MarshalEnvelope(msgType string, data any, ref string) ([]byte, error)

MarshalEnvelope creates an Envelope with the given type and data payload.

func ParseData

func ParseData[T any](env Envelope) (T, error)

ParseData unmarshals the D field of an envelope into the given target.

Types

type Channel

type Channel struct {
	Name   string `json:"name"`
	Public bool   `json:"public"`
	Member bool   `json:"member"`
}

Channel represents a chat channel from the server.

type ChannelCreateRequest

type ChannelCreateRequest struct {
	Name    string   `json:"name"`
	Public  bool     `json:"public"`
	Members []string `json:"members,omitempty"`
}

ChannelCreateRequest creates a new channel.

type ChannelInviteRequest

type ChannelInviteRequest struct {
	Channel  string `json:"channel"`
	Username string `json:"username"`
}

ChannelInviteRequest invites a user to a channel.

type ChannelJoinMsg

type ChannelJoinMsg struct{}

type ChannelJoinRequest

type ChannelJoinRequest struct {
	Channel string `json:"channel"`
}

ChannelJoinRequest joins a public channel.

type ChannelListMsg

type ChannelListMsg struct {
	Channels []Channel
}

type ChannelListResponse

type ChannelListResponse struct {
	Channels []Channel `json:"channels"`
}

ChannelListResponse is the payload of a channel_list response.

type ChannelUnreadCount

type ChannelUnreadCount struct {
	Channel      string `json:"channel"`
	ChannelType  string `json:"type"`
	UnreadCount  int    `json:"unread_count"`
	MentionCount int    `json:"mention_count"`
}

ChannelUnreadCount holds per-channel unread and mention counts.

type Client

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

Client manages a WebSocket connection to a sharkfin daemon.

func New

func New(host string) *Client

New creates a new sharkfin client for the given WebSocket URL.

func (*Client) Close

func (c *Client) Close()

Close shuts down the client.

func (*Client) Connect

func (c *Client) Connect() (*Hello, error)

Connect dials the sharkfin WebSocket and reads the hello message.

func (*Client) CreateChannel

func (c *Client) CreateChannel(name string, public bool, members []string)

CreateChannel creates a new channel.

func (*Client) DMOpen

func (c *Client) DMOpen(username string)

DMOpen opens or creates a DM with the given user.

func (*Client) Identify

func (c *Client) Identify(username string) error

Identify authenticates as an existing user, falling back to register. Writes directly to the connection (WritePump is not yet running during handshake).

func (*Client) InviteUser

func (c *Client) InviteUser(channel, username string)

InviteUser invites a user to a channel.

func (*Client) JoinChannel

func (c *Client) JoinChannel(channel string)

JoinChannel joins a public channel.

func (*Client) MarkRead

func (c *Client) MarkRead(channel string, messageID *int)

MarkRead advances the read cursor for a channel.

func (*Client) ReadPump

func (c *Client) ReadPump(p *tea.Program)

ReadPump reads messages from the WebSocket and dispatches them as tea.Msg via p.Send().

func (*Client) Reconnect

func (c *Client) Reconnect() tea.Cmd

Reconnect returns a tea.Cmd that attempts to reconnect with exponential backoff. It blocks until a connection is re-established, sending ReconnectingMsg on each attempt.

func (*Client) RequestChannels

func (c *Client) RequestChannels()

RequestChannels requests the channel list.

func (*Client) RequestDMList

func (c *Client) RequestDMList()

RequestDMList requests the DM conversation list.

func (*Client) RequestHistory

func (c *Client) RequestHistory(channel string, before, limit int)

RequestHistory requests paginated message history.

func (*Client) RequestUnread

func (c *Client) RequestUnread(channel string)

RequestUnread requests unread messages for a channel (advances read cursor).

func (*Client) RequestUnreadCounts

func (c *Client) RequestUnreadCounts()

RequestUnreadCounts requests per-channel unread and mention counts.

func (*Client) RequestUsers

func (c *Client) RequestUsers()

RequestUsers requests the user list.

func (*Client) SendMessage

func (c *Client) SendMessage(channel, body string)

SendMessage sends a chat message to a channel.

func (*Client) WritePump

func (c *Client) WritePump()

WritePump writes outbound messages to the WebSocket. Single writer goroutine.

type ConnectedMsg

type ConnectedMsg struct{}

type DM

type DM struct {
	Channel      string   `json:"channel"`
	Participant  string   `json:"participant,omitempty"`  // MCP (user-scoped)
	Participants []string `json:"participants,omitempty"` // WS (admin-scoped)
	Member       bool     `json:"member"`
}

DM represents a direct message conversation.

type DMListMsg

type DMListMsg struct {
	DMs []DM
}

type DMListResponse

type DMListResponse struct {
	DMs []DM `json:"dms"`
}

DMListResponse is the payload of a dm_list response.

type DMOpenMsg

type DMOpenMsg struct {
	Channel     string
	Participant string
	Created     bool
}

type DMOpenRequest

type DMOpenRequest struct {
	Username string `json:"username"`
}

DMOpenRequest opens or creates a DM with a user.

type DMOpenResponse

type DMOpenResponse struct {
	Channel     string `json:"channel"`
	Participant string `json:"participant"`
	Created     bool   `json:"created"`
}

DMOpenResponse is the payload of a dm_open response.

type DisconnectedMsg

type DisconnectedMsg struct {
	Err error
}

type Envelope

type Envelope struct {
	Type string          `json:"type"`
	D    json.RawMessage `json:"d,omitempty"`
	Ref  string          `json:"ref,omitempty"`
	OK   *bool           `json:"ok,omitempty"`
}

Envelope is the top-level JSON structure for all sharkfin WS messages.

func ParseEnvelope

func ParseEnvelope(raw []byte) (Envelope, error)

ParseEnvelope parses a raw JSON message into an Envelope.

type Hello

type Hello struct {
	HeartbeatInterval int `json:"heartbeat_interval"`
}

Hello is sent by the server on connection.

type HistoryMsg

type HistoryMsg struct {
	Channel  string
	Messages []Message
}

type HistoryRequest

type HistoryRequest struct {
	Channel string `json:"channel"`
	Before  int    `json:"before,omitempty"`
	Limit   int    `json:"limit,omitempty"`
}

HistoryRequest requests message history for a channel.

type HistoryResponse

type HistoryResponse struct {
	Channel  string    `json:"channel"`
	Messages []Message `json:"messages"`
}

HistoryResponse is the payload of a history response.

type IdentifyRequest

type IdentifyRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

IdentifyRequest is sent to authenticate as an existing user.

type MarkReadRequest

type MarkReadRequest struct {
	Channel   string `json:"channel"`
	MessageID *int   `json:"message_id,omitempty"`
}

MarkReadRequest advances the read cursor for a channel.

type Message

type Message struct {
	ID       int       `json:"id"`
	Channel  string    `json:"channel"`
	From     string    `json:"from"`
	Body     string    `json:"body"`
	SentAt   time.Time `json:"sent_at"`
	ThreadID *int      `json:"thread_id,omitempty"`
}

Message represents a chat message from the server.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type MessageNewEvent

type MessageNewEvent struct {
	ID          int       `json:"id"`
	Channel     string    `json:"channel"`
	ChannelType string    `json:"channel_type"`
	From        string    `json:"from"`
	Body        string    `json:"body"`
	SentAt      time.Time `json:"sent_at"`
	ThreadID    *int      `json:"thread_id,omitempty"`
	Mentions    []string  `json:"mentions,omitempty"`
}

MessageNewEvent is a server push for new messages.

func (*MessageNewEvent) UnmarshalJSON

func (e *MessageNewEvent) UnmarshalJSON(data []byte) error

type MessageNewMsg

type MessageNewMsg = MessageNewEvent

type MessageSentMsg

type MessageSentMsg struct{}

type PresenceEvent

type PresenceEvent struct {
	Username string `json:"username"`
	Online   bool   `json:"online"`
}

PresenceEvent is a server push for user presence changes.

type PresenceMsg

type PresenceMsg = PresenceEvent

type ReconnectingMsg

type ReconnectingMsg struct {
	Attempt int
}

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

RegisterRequest is sent to create a new user.

type SendMessageRequest

type SendMessageRequest struct {
	Channel  string `json:"channel"`
	Body     string `json:"body"`
	ThreadID *int   `json:"thread_id,omitempty"`
}

SendMessageRequest sends a message to a channel.

type UnreadCountsMsg

type UnreadCountsMsg struct {
	Counts []ChannelUnreadCount
}

type UnreadCountsResponse

type UnreadCountsResponse struct {
	Counts []ChannelUnreadCount `json:"counts"`
}

UnreadCountsResponse is the payload of an unread_counts response.

type UnreadMsg

type UnreadMsg struct {
	Channel  string
	Messages []Message
}

type UnreadRequest

type UnreadRequest struct {
	Channel      string `json:"channel,omitempty"`
	MentionsOnly bool   `json:"mentions_only,omitempty"`
	ThreadID     *int   `json:"thread_id,omitempty"`
}

UnreadRequest requests unread messages.

type UnreadResponse

type UnreadResponse struct {
	Channel  string    `json:"channel,omitempty"`
	Messages []Message `json:"messages"`
}

UnreadResponse is the payload of an unread_messages response.

type User

type User struct {
	Username string `json:"username"`
	Online   bool   `json:"online"`
}

User represents a user from the server.

type UserListMsg

type UserListMsg struct {
	Users []User
}

type UserListResponse

type UserListResponse struct {
	Users []User `json:"users"`
}

UserListResponse is the payload of a user_list response.

Jump to

Keyboard shortcuts

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