|
| 1 | +// To parse this JSON data, do |
| 2 | +// |
| 3 | +// final agentAttributes = agentAttributesFromJson(jsonString); |
| 4 | +// final transcriptionAttributes = transcriptionAttributesFromJson(jsonString); |
| 5 | + |
| 6 | +import 'dart:convert'; |
| 7 | + |
| 8 | +AgentAttributes agentAttributesFromJson(String str) => AgentAttributes.fromJson(json.decode(str)); |
| 9 | + |
| 10 | +String agentAttributesToJson(AgentAttributes data) => json.encode(data.toJson()); |
| 11 | + |
| 12 | +TranscriptionAttributes transcriptionAttributesFromJson(String str) => |
| 13 | + TranscriptionAttributes.fromJson(json.decode(str)); |
| 14 | + |
| 15 | +String transcriptionAttributesToJson(TranscriptionAttributes data) => json.encode(data.toJson()); |
| 16 | + |
| 17 | +class AgentAttributes { |
| 18 | + List<AgentInput>? lkAgentInputs; |
| 19 | + List<AgentOutput>? lkAgentOutputs; |
| 20 | + AgentState? lkAgentState; |
| 21 | + String? lkPublishOnBehalf; |
| 22 | + |
| 23 | + AgentAttributes({ |
| 24 | + this.lkAgentInputs, |
| 25 | + this.lkAgentOutputs, |
| 26 | + this.lkAgentState, |
| 27 | + this.lkPublishOnBehalf, |
| 28 | + }); |
| 29 | + |
| 30 | + factory AgentAttributes.fromJson(Map<String, dynamic> json) => AgentAttributes( |
| 31 | + lkAgentInputs: json['lk.agent.inputs'] == null |
| 32 | + ? [] |
| 33 | + : List<AgentInput>.from(json['lk.agent.inputs']!.map((x) => agentInputValues.map[x]!)), |
| 34 | + lkAgentOutputs: json['lk.agent.outputs'] == null |
| 35 | + ? [] |
| 36 | + : List<AgentOutput>.from(json['lk.agent.outputs']!.map((x) => agentOutputValues.map[x]!)), |
| 37 | + lkAgentState: agentStateValues.map[json['lk.agent.state']]!, |
| 38 | + lkPublishOnBehalf: json['lk.publish_on_behalf'], |
| 39 | + ); |
| 40 | + |
| 41 | + Map<String, dynamic> toJson() => { |
| 42 | + 'lk.agent.inputs': |
| 43 | + lkAgentInputs == null ? [] : List<dynamic>.from(lkAgentInputs!.map((x) => agentInputValues.reverse[x])), |
| 44 | + 'lk.agent.outputs': |
| 45 | + lkAgentOutputs == null ? [] : List<dynamic>.from(lkAgentOutputs!.map((x) => agentOutputValues.reverse[x])), |
| 46 | + 'lk.agent.state': agentStateValues.reverse[lkAgentState], |
| 47 | + 'lk.publish_on_behalf': lkPublishOnBehalf, |
| 48 | + }; |
| 49 | +} |
| 50 | + |
| 51 | +enum AgentInput { AUDIO, TEXT, VIDEO } |
| 52 | + |
| 53 | +final agentInputValues = EnumValues({'audio': AgentInput.AUDIO, 'text': AgentInput.TEXT, 'video': AgentInput.VIDEO}); |
| 54 | + |
| 55 | +enum AgentOutput { AUDIO, TRANSCRIPTION } |
| 56 | + |
| 57 | +final agentOutputValues = EnumValues({'audio': AgentOutput.AUDIO, 'transcription': AgentOutput.TRANSCRIPTION}); |
| 58 | + |
| 59 | +enum AgentState { IDLE, INITIALIZING, LISTENING, SPEAKING, THINKING } |
| 60 | + |
| 61 | +final agentStateValues = EnumValues({ |
| 62 | + 'idle': AgentState.IDLE, |
| 63 | + 'initializing': AgentState.INITIALIZING, |
| 64 | + 'listening': AgentState.LISTENING, |
| 65 | + 'speaking': AgentState.SPEAKING, |
| 66 | + 'thinking': AgentState.THINKING |
| 67 | +}); |
| 68 | + |
| 69 | +///Schema for transcription-related attributes |
| 70 | +class TranscriptionAttributes { |
| 71 | + ///The segment id of the transcription |
| 72 | + String? lkSegmentId; |
| 73 | + |
| 74 | + ///The associated track id of the transcription |
| 75 | + String? lkTranscribedTrackId; |
| 76 | + |
| 77 | + ///Whether the transcription is final |
| 78 | + bool? lkTranscriptionFinal; |
| 79 | + |
| 80 | + TranscriptionAttributes({ |
| 81 | + this.lkSegmentId, |
| 82 | + this.lkTranscribedTrackId, |
| 83 | + this.lkTranscriptionFinal, |
| 84 | + }); |
| 85 | + |
| 86 | + factory TranscriptionAttributes.fromJson(Map<String, dynamic> json) => TranscriptionAttributes( |
| 87 | + lkSegmentId: json['lk.segment_id'], |
| 88 | + lkTranscribedTrackId: json['lk.transcribed_track_id'], |
| 89 | + lkTranscriptionFinal: json['lk.transcription_final'], |
| 90 | + ); |
| 91 | + |
| 92 | + Map<String, dynamic> toJson() => { |
| 93 | + 'lk.segment_id': lkSegmentId, |
| 94 | + 'lk.transcribed_track_id': lkTranscribedTrackId, |
| 95 | + 'lk.transcription_final': lkTranscriptionFinal, |
| 96 | + }; |
| 97 | +} |
| 98 | + |
| 99 | +class EnumValues<T> { |
| 100 | + Map<String, T> map; |
| 101 | + late Map<T, String> reverseMap; |
| 102 | + |
| 103 | + EnumValues(this.map); |
| 104 | + |
| 105 | + Map<T, String> get reverse { |
| 106 | + reverseMap = map.map((k, v) => MapEntry(v, k)); |
| 107 | + return reverseMap; |
| 108 | + } |
| 109 | +} |
0 commit comments