Skip to content
45 changes: 37 additions & 8 deletions auth/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ func checkOutputForCredentials(output any) error {
}

type ClaimGrants struct {
Identity string `json:"identity,omitempty"`
Name string `json:"name,omitempty"`
Kind string `json:"kind,omitempty"`
Video *VideoGrant `json:"video,omitempty"`
SIP *SIPGrant `json:"sip,omitempty"`
Agent *AgentGrant `json:"agent,omitempty"`
Inference *InferenceGrant `json:"inference,omitempty"`
Identity string `json:"identity,omitempty"`
Name string `json:"name,omitempty"`
Kind string `json:"kind,omitempty"`
Video *VideoGrant `json:"video,omitempty"`
SIP *SIPGrant `json:"sip,omitempty"`
Agent *AgentGrant `json:"agent,omitempty"`
Inference *InferenceGrant `json:"inference,omitempty"`
Observability *ObservabilityGrant `json:"observability,omitempty"`
// Room configuration to use if this participant initiates the room
RoomConfig *RoomConfiguration `json:"roomConfig,omitempty"`
// Cloud-only, config preset to use
Expand Down Expand Up @@ -206,6 +207,7 @@ func (c *ClaimGrants) Clone() *ClaimGrants {
clone.SIP = c.SIP.Clone()
clone.Agent = c.Agent.Clone()
clone.Inference = c.Inference.Clone()
clone.Observability = c.Observability.Clone()
clone.Attributes = maps.Clone(c.Attributes)
clone.RoomConfig = c.RoomConfig.Clone()

Expand All @@ -223,6 +225,7 @@ func (c *ClaimGrants) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddObject("SIP", c.SIP)
e.AddObject("Agent", c.Agent)
e.AddObject("Inference", c.Inference)
e.AddObject("Observability", c.Observability)
e.AddObject("RoomConfig", logger.Proto((*livekit.RoomConfiguration)(c.RoomConfig)))
e.AddString("RoomPreset", c.RoomPreset)
return nil
Expand Down Expand Up @@ -560,7 +563,7 @@ func (s *AgentGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
// ------------------------------------------------------------------

type InferenceGrant struct {
// Admin grants to all inference features (LLM, STT, TTS)
// Perform grants to all inference features (LLM, STT, TTS)
Perform bool `json:"perform,omitempty"`
}

Expand All @@ -585,6 +588,32 @@ func (s *InferenceGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {

// ------------------------------------------------------------------

type ObservabilityGrant struct {
// Write grants to publish observability data
Write bool `json:"write,omitempty"`
}

func (s *ObservabilityGrant) Clone() *ObservabilityGrant {
if s == nil {
return nil
}

clone := *s

return &clone
}

func (s *ObservabilityGrant) MarshalLogObject(e zapcore.ObjectEncoder) error {
if s == nil {
return nil
}

e.AddBool("Write", s.Write)
return nil
}

// ------------------------------------------------------------------

func sourceToString(source livekit.TrackSource) string {
return strings.ToLower(source.String())
}
Expand Down
84 changes: 71 additions & 13 deletions livekit/livekit_metrics.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion protobufs/livekit_metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ message MetricsBatch {
// This is useful for storing participant identities, track names, etc.
// There is also a predefined list of labels that can be used to reference common metrics.
// They have reserved indices from 0 to (METRIC_LABEL_PREDEFINED_MAX_VALUE - 1).
// Indexes pointing at str_data should start from METRIC_LABEL_PREDEFINED_MAX_VALUE,
// Indexes pointing at str_data should start from METRIC_LABEL_PREDEFINED_MAX_VALUE,
// such that str_data[0] == index of METRIC_LABEL_PREDEFINED_MAX_VALUE.
repeated string str_data = 3;
repeated TimeSeriesMetric time_series = 4;
Expand Down Expand Up @@ -87,3 +87,8 @@ message EventMetric {
string metadata = 8;
uint32 rid = 9; // index into 'str_data'
}

message MetricsRecordingHeader {
string room_id = 1;
optional bool enable_user_data_training = 2;
}
7 changes: 7 additions & 0 deletions utils/guid/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
mrand "math/rand/v2"
"os"
"regexp"
"sync"
"unsafe"

Expand Down Expand Up @@ -199,3 +200,9 @@ func Unmarshal[T livekit.Guid](b livekit.GuidBlock) T {
}
return T(unsafe.String(unsafe.SliceData(id), len(id)))
}

var validIDPattern = regexp.MustCompile(`^([a-zA-Z0-9]{1,16}_){1,2}[a-zA-Z0-9]{0,12}$`)

func IsValidID[T ~string](id T) bool {
return validIDPattern.MatchString(string(id))
}
9 changes: 9 additions & 0 deletions utils/guid/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ func BenchmarkNew(b *testing.B) {
_ = guid
})
}

func TestIsValidID(t *testing.T) {
require.True(t, IsValidID("A_SFo4igEG5Dg5"))
require.True(t, IsValidID("NM_OJOHANNESBURG1A_K6SMQw2ZCZyB"))
require.False(t, IsValidID("A_A_A_SFo4igEG5Dg5"))
require.False(t, IsValidID("_A_SFo4igEG5Dg5"))
require.False(t, IsValidID("_SFo4igEG5Dg5"))
require.False(t, IsValidID("SFo4igEG5Dg5"))
}
Loading