okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
859 B35 linesraw
1package daemon
2
3import (
4	"crypto/rand"
5	"encoding/hex"
6	"strings"
7	"sync"
8)
9
10// ChatClient retains the cursor and live progress keys for one subscription.
11// Callers must serialize stream subscriptions and reset operations.
12type ChatClient struct {
13	conn            *Connection
14	progressCallIDs map[string]struct{}
15	agentID         string
16	clientID        string
17	afterSeq        int64
18	afterGeneration string
19	mu              sync.Mutex
20}
21
22// NewChatClient shares conn's HTTP transport. A nil connection panics.
23func NewChatClient(conn *Connection, agentID string) *ChatClient {
24	if conn == nil {
25		panic("daemon.NewChatClient: nil connection")
26	}
27	identity := make([]byte, 16)
28	_, _ = rand.Read(identity)
29	return &ChatClient{
30		conn:     conn,
31		agentID:  strings.TrimSpace(agentID),
32		clientID: "cli-" + hex.EncodeToString(identity),
33		afterSeq: -1,
34	}
35}