~bigbes/lethe

ref: 12df3f43091141353457bf5058e9524e6d7a910c lethe/internal/shared/wire/wire.go -rw-r--r-- 1.7 KiB
12df3f43 — Eugene Blikh web: adapter — add Session.sessionId, SavedSearch DTO; fix composite-id call sites a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Package wire defines the locked NDJSON ingest contract shared with the
// lethe-collector. Changes here ripple into the collector — be deliberate.
package wire

import "encoding/json"

// TurnEvent is the on-the-wire representation of a single turn in a session.
// It is the only message type accepted by POST /api/v1/ingest. Sessions are
// upserted from SessionMeta carried on each turn; there is no separate
// session event on the wire.
type TurnEvent struct {
	Tool        string          `json:"tool"`
	Host        string          `json:"host"`
	SessionID   string          `json:"session_id"`
	TurnID      string          `json:"turn_id"`
	Seq         int64           `json:"seq"`
	Role        string          `json:"role"`      // user | assistant | tool | system
	Timestamp   int64           `json:"timestamp"` // unix epoch seconds
	Content     string          `json:"content"`
	Model       *string         `json:"model,omitempty"`
	TokensIn    *int64          `json:"tokens_in,omitempty"`
	TokensOut   *int64          `json:"tokens_out,omitempty"`
	CostUSD     *float64        `json:"cost_usd,omitempty"`
	ToolCalls   json.RawMessage `json:"tool_calls,omitempty"`
	SessionMeta SessionMeta     `json:"session_meta"`
	Metadata    json.RawMessage `json:"metadata,omitempty"`
}

// SessionMeta carries the per-session attributes that the server uses to
// upsert the parent session row on first-seen turn for that session.
type SessionMeta struct {
	WorkingDir *string         `json:"working_dir,omitempty"`
	SourceFile string          `json:"source_file"`
	StartedAt  *int64          `json:"started_at,omitempty"` // optional; server falls back to MIN(turn.timestamp)
	Metadata   json.RawMessage `json:"metadata,omitempty"`
}