-
Notifications
You must be signed in to change notification settings - Fork 154
Consume generated attributes #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
79f467f
d58fdaa
4b81f5c
f838d14
5ab6704
ac72abd
3d93940
af3bc68
81625ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright 2025 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| extension AgentState: CustomStringConvertible { | ||
| public var description: String { | ||
| rawValue.capitalized | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,19 +25,29 @@ public extension Participant { | |
| } | ||
| } | ||
|
|
||
| @objc | ||
| internal var agentAttributes: AgentAttributes? { | ||
| guard isAgent else { return nil } | ||
|
|
||
| guard let encoded = try? JSONEncoder().encode(attributes), | ||
| let decoded = try? JSONDecoder().decode(AgentAttributes.self, from: encoded) else { return nil } | ||
|
|
||
| return decoded | ||
| } | ||
|
|
||
| var agentState: AgentState { | ||
| guard isAgent else { return .unknown } | ||
| guard let attrString = attributes[agentStateAttributeKey] else { return .unknown } | ||
| guard let state = AgentState.fromString(attrString) else { return .unknown } | ||
| return state | ||
| agentAttributes?.lkAgentState ?? .idle | ||
| } | ||
|
|
||
| @objc | ||
| var agentStateString: String { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sort of breaks Obj-C contract, but IMO it's better than changing the schema for every single language, just for the sake of having |
||
| agentState.rawValue | ||
| } | ||
| } | ||
|
|
||
| public extension Participant { | ||
| private var publishingOnBehalf: [Participant.Identity: Participant] { | ||
| guard let _room else { return [:] } | ||
| return _room.allParticipants.filter { $0.value.attributes[publishOnBehalfAttributeKey] == identity?.stringValue } | ||
| return _room.allParticipants.filter { $0.value.agentAttributes?.lkPublishOnBehalf == identity?.stringValue } | ||
| } | ||
|
|
||
| /// The avatar worker participant associated with the agent. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright 2025 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import Foundation | ||
|
|
||
| // MARK: - AgentAttributes | ||
|
|
||
| struct AgentAttributes: Codable, Sendable { | ||
| let lkAgentInputs: [AgentInput]? | ||
| let lkAgentOutputs: [AgentOutput]? | ||
| let lkAgentState: AgentState? | ||
| let lkPublishOnBehalf: String? | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case lkAgentInputs = "lk.agent.inputs" | ||
| case lkAgentOutputs = "lk.agent.outputs" | ||
| case lkAgentState = "lk.agent.state" | ||
| case lkPublishOnBehalf = "lk.publish_on_behalf" | ||
| } | ||
| } | ||
|
|
||
| enum AgentInput: String, Codable, Sendable { | ||
| case audio | ||
| case text | ||
| case video | ||
| } | ||
|
|
||
| enum AgentOutput: String, Codable, Sendable { | ||
| case audio | ||
| case transcription | ||
| } | ||
|
|
||
| public enum AgentState: String, Codable, Sendable { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
| case idle | ||
| case initializing | ||
| case listening | ||
| case speaking | ||
| case thinking | ||
| } | ||
|
|
||
| /// Schema for transcription-related attributes | ||
|
|
||
| // MARK: - TranscriptionAttributes | ||
|
|
||
| struct TranscriptionAttributes: Codable, Sendable { | ||
| /// The segment id of the transcription | ||
| let lkSegmentID: String? | ||
| /// The associated track id of the transcription | ||
| let lkTranscribedTrackID: String? | ||
| /// Whether the transcription is final | ||
| let lkTranscriptionFinal: Bool? | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case lkSegmentID = "lk.segment_id" | ||
| case lkTranscribedTrackID = "lk.transcribed_track_id" | ||
| case lkTranscriptionFinal = "lk.transcription_final" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to remove this one, looks like leftover that could be handled by the frontend.