@myun/gimi-chat 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/dist/apis/fetch.d.ts +64 -0
  2. package/dist/apis/fetch.js +512 -0
  3. package/dist/apis/useApi.d.ts +57 -0
  4. package/dist/apis/useApi.js +378 -0
  5. package/dist/assets/image/Subtract.png +0 -0
  6. package/dist/assets/image/ai-logo.png +0 -0
  7. package/dist/assets/image/copyIcon.png +0 -0
  8. package/dist/assets/image/deepthinkActive.png +0 -0
  9. package/dist/assets/image/empty-img-dark.png +0 -0
  10. package/dist/assets/image/empty-img.png +0 -0
  11. package/dist/assets/image/like_active.png +0 -0
  12. package/dist/assets/image/love.png +0 -0
  13. package/dist/assets/image/retry.png +0 -0
  14. package/dist/assets/image/soundOut.png +0 -0
  15. package/dist/assets/image/unlike_active.png +0 -0
  16. package/dist/assets/image/unlove.png +0 -0
  17. package/dist/assets/lottie/ai-bg.json +1704 -0
  18. package/dist/assets/lottie/ai-loading.json +192 -0
  19. package/dist/assets/lottie/ai-output-loading.json +272 -0
  20. package/dist/assets/lottie/ai-output-normal.json +17694 -0
  21. package/dist/assets/lottie/ai-output-strengthen.json +17321 -0
  22. package/dist/assets/lottie/ai-voice-play.json +1 -0
  23. package/dist/assets/lottie/living.json +705 -0
  24. package/dist/assets/lottie/myun-living.json +726 -0
  25. package/dist/assets/lottie/myun-loading.json +530 -0
  26. package/dist/components/ai-chat-dialogue/index.d.ts +16 -0
  27. package/dist/components/ai-chat-dialogue/index.js +1056 -0
  28. package/dist/components/ai-chat-dialogue/index.module.css +230 -0
  29. package/dist/components/ai-chat-dialogue/message-parser.d.ts +36 -0
  30. package/dist/components/ai-chat-dialogue/message-parser.js +52 -0
  31. package/dist/components/ai-chat-dialogue/tlv.d.ts +7 -0
  32. package/dist/components/ai-chat-dialogue/tlv.js +32 -0
  33. package/dist/components/ai-chat-dialogue/volc-voice-call-client.d.ts +47 -0
  34. package/dist/components/ai-chat-dialogue/volc-voice-call-client.js +246 -0
  35. package/dist/components/ai-correction/index.d.ts +5 -0
  36. package/dist/components/ai-correction/index.js +45 -0
  37. package/dist/components/ai-loading/index.d.ts +3 -0
  38. package/dist/components/ai-loading/index.js +14 -0
  39. package/dist/components/ai-loading/index.module.css +11 -0
  40. package/dist/components/answer-item/index.d.ts +27 -0
  41. package/dist/components/answer-item/index.js +194 -0
  42. package/dist/components/answer-item/index.module.css +266 -0
  43. package/dist/components/ask-card/index.d.ts +10 -0
  44. package/dist/components/ask-card/index.js +76 -0
  45. package/dist/components/ask-card/index.module.css +122 -0
  46. package/dist/components/chat-input/index.d.ts +31 -0
  47. package/dist/components/chat-input/index.js +433 -0
  48. package/dist/components/chat-input/index.module.css +42 -0
  49. package/dist/components/chat-voice/VoiceCommunication.d.ts +7 -0
  50. package/dist/components/chat-voice/VoiceCommunication.js +69 -0
  51. package/dist/components/chat-voice/VoiceRecord.d.ts +7 -0
  52. package/dist/components/chat-voice/VoiceRecord.js +34 -0
  53. package/dist/components/conversation-delete/index.d.ts +5 -0
  54. package/dist/components/conversation-delete/index.js +24 -0
  55. package/dist/components/dots-loading/index.d.ts +2 -0
  56. package/dist/components/dots-loading/index.js +11 -0
  57. package/dist/components/dots-loading/index.module.css +41 -0
  58. package/dist/components/empty/index.d.ts +9 -0
  59. package/dist/components/empty/index.js +32 -0
  60. package/dist/components/empty/index.module.css +24 -0
  61. package/dist/components/excel-components/ExcelCard.d.ts +11 -0
  62. package/dist/components/excel-components/ExcelCard.js +35 -0
  63. package/dist/components/excel-components/ExcelExcuting.d.ts +10 -0
  64. package/dist/components/excel-components/ExcelExcuting.js +263 -0
  65. package/dist/components/excel-components/ExcelFailCard.d.ts +9 -0
  66. package/dist/components/excel-components/ExcelFailCard.js +20 -0
  67. package/dist/components/excel-components/ExcelSuccessCard.d.ts +5 -0
  68. package/dist/components/excel-components/ExcelSuccessCard.js +50 -0
  69. package/dist/components/excel-components/index.module.css +212 -0
  70. package/dist/components/excel-components/styles.module.css +178 -0
  71. package/dist/components/file-card/fileCardSidebar.d.ts +8 -0
  72. package/dist/components/file-card/fileCardSidebar.js +56 -0
  73. package/dist/components/file-card/index.d.ts +15 -0
  74. package/dist/components/file-card/index.js +97 -0
  75. package/dist/components/file-card/index.module.css +139 -0
  76. package/dist/components/file-preview/index.d.ts +3 -0
  77. package/dist/components/file-preview/index.js +227 -0
  78. package/dist/components/file-preview/index.module.css +83 -0
  79. package/dist/components/file-upload/index.d.ts +16 -0
  80. package/dist/components/file-upload/index.js +238 -0
  81. package/dist/components/file-upload/uploadV1.d.ts +16 -0
  82. package/dist/components/file-upload/uploadV1.js +267 -0
  83. package/dist/components/gimi-sidebar/index.d.ts +17 -0
  84. package/dist/components/gimi-sidebar/index.js +41 -0
  85. package/dist/components/gimi-sidebar/index.module.css +118 -0
  86. package/dist/components/header/index.d.ts +5 -0
  87. package/dist/components/header/index.js +20 -0
  88. package/dist/components/header/index.module.css +19 -0
  89. package/dist/components/iconfont-com/index.d.ts +11 -0
  90. package/dist/components/iconfont-com/index.js +29 -0
  91. package/dist/components/index.d.ts +1 -0
  92. package/dist/components/index.js +1 -0
  93. package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +7 -0
  94. package/dist/components/knowledge-trace/KnowledgeIconComponent.js +101 -0
  95. package/dist/components/knowledge-trace/classList.d.ts +6 -0
  96. package/dist/components/knowledge-trace/classList.js +72 -0
  97. package/dist/components/knowledge-trace/documentList.d.ts +6 -0
  98. package/dist/components/knowledge-trace/documentList.js +75 -0
  99. package/dist/components/knowledge-trace/index.d.ts +18 -0
  100. package/dist/components/knowledge-trace/index.js +155 -0
  101. package/dist/components/knowledge-trace/index.module.css +254 -0
  102. package/dist/components/knowledge-trace/interfaces.d.ts +166 -0
  103. package/dist/components/knowledge-trace/interfaces.js +1 -0
  104. package/dist/components/knowledge-trace/videoList.d.ts +6 -0
  105. package/dist/components/knowledge-trace/videoList.js +91 -0
  106. package/dist/components/lottie-img/index.d.ts +8 -0
  107. package/dist/components/lottie-img/index.js +99 -0
  108. package/dist/components/message-actions/CopyButton.d.ts +7 -0
  109. package/dist/components/message-actions/CopyButton.js +33 -0
  110. package/dist/components/message-actions/LikeButton.d.ts +7 -0
  111. package/dist/components/message-actions/LikeButton.js +34 -0
  112. package/dist/components/message-actions/RegenerateButton.d.ts +5 -0
  113. package/dist/components/message-actions/RegenerateButton.js +27 -0
  114. package/dist/components/message-actions/UnLikeButton.d.ts +7 -0
  115. package/dist/components/message-actions/UnLikeButton.js +34 -0
  116. package/dist/components/message-actions/VoicePlay.d.ts +10 -0
  117. package/dist/components/message-actions/VoicePlay.js +74 -0
  118. package/dist/components/message-list/index.d.ts +19 -0
  119. package/dist/components/message-list/index.js +164 -0
  120. package/dist/components/message-list/index.module.css +261 -0
  121. package/dist/components/no-microphone-root/index.d.ts +6 -0
  122. package/dist/components/no-microphone-root/index.js +36 -0
  123. package/dist/components/no-microphone-root/index.module.css +48 -0
  124. package/dist/components/preset-agent-content/index.d.ts +8 -0
  125. package/dist/components/preset-agent-content/index.js +24 -0
  126. package/dist/components/preset-agent-content/index.module.css +46 -0
  127. package/dist/components/quoted-content/index.d.ts +0 -0
  128. package/dist/components/quoted-content/index.js +171 -0
  129. package/dist/components/quoted-content/index.module.css +80 -0
  130. package/dist/components/reasoning-content/index.d.ts +6 -0
  131. package/dist/components/reasoning-content/index.js +116 -0
  132. package/dist/components/reasoning-content/index.module.css +169 -0
  133. package/dist/components/reference-content/index.d.ts +28 -0
  134. package/dist/components/reference-content/index.js +125 -0
  135. package/dist/components/reference-content/index.module.css +84 -0
  136. package/dist/components/templates/CommonChat.d.ts +5 -0
  137. package/dist/components/templates/CommonChat.js +218 -0
  138. package/dist/components/templates/GimiChatComponent.d.ts +4 -0
  139. package/dist/components/templates/GimiChatComponent.js +23 -0
  140. package/dist/components/templates/demo/demo.d.ts +2 -0
  141. package/dist/components/templates/demo/demo.js +109 -0
  142. package/dist/components/templates/index.module.css +109 -0
  143. package/dist/components/upload-list/index.d.ts +15 -0
  144. package/dist/components/upload-list/index.js +90 -0
  145. package/dist/components/upload-list/index.module.css +119 -0
  146. package/dist/components/voice-bars/index.d.ts +4 -0
  147. package/dist/components/voice-bars/index.js +174 -0
  148. package/dist/components/voice-check-dialog/index.d.ts +8 -0
  149. package/dist/components/voice-check-dialog/index.js +163 -0
  150. package/dist/components/voice-check-dialog/index.module.css +9 -0
  151. package/dist/components/voice-recording/index.d.ts +9 -0
  152. package/dist/components/voice-recording/index.js +54 -0
  153. package/dist/components/voice-recording/index.module.css +41 -0
  154. package/dist/components/work-flow-content/demo.d.ts +3 -0
  155. package/dist/components/work-flow-content/demo.js +11 -0
  156. package/dist/components/work-flow-content/index.d.ts +6 -0
  157. package/dist/components/work-flow-content/index.js +55 -0
  158. package/dist/components/work-flow-content/index.module.css +24 -0
  159. package/dist/constants.d.ts +24 -0
  160. package/dist/constants.js +24 -0
  161. package/dist/hooks/useChatActions.d.ts +12 -0
  162. package/dist/hooks/useChatActions.js +207 -0
  163. package/dist/hooks/useChatHistory.d.ts +8 -0
  164. package/dist/hooks/useChatHistory.js +225 -0
  165. package/dist/hooks/useChatMessage.d.ts +49 -0
  166. package/dist/hooks/useChatMessage.js +87 -0
  167. package/dist/hooks/useChatRecommend.d.ts +8 -0
  168. package/dist/hooks/useChatRecommend.js +126 -0
  169. package/dist/hooks/useChatStream.d.ts +20 -0
  170. package/dist/hooks/useChatStream.js +244 -0
  171. package/dist/hooks/useChatUI.d.ts +32 -0
  172. package/dist/hooks/useChatUI.js +134 -0
  173. package/dist/hooks/useChatVoice.d.ts +11 -0
  174. package/dist/hooks/useChatVoice.js +379 -0
  175. package/dist/hooks/useCommonChatAPI.d.ts +27 -0
  176. package/dist/hooks/useCommonChatAPI.js +1276 -0
  177. package/dist/hooks/useFile.d.ts +13 -0
  178. package/dist/hooks/useFile.js +288 -0
  179. package/dist/hooks/useKnowledgeService.d.ts +17 -0
  180. package/dist/hooks/useKnowledgeService.js +210 -0
  181. package/dist/hooks/useLastEventId.d.ts +8 -0
  182. package/dist/hooks/useLastEventId.js +66 -0
  183. package/dist/hooks/useLongPoll.d.ts +3 -0
  184. package/dist/hooks/useLongPoll.js +111 -0
  185. package/dist/hooks/useScroll.d.ts +4 -0
  186. package/dist/hooks/useScroll.js +172 -0
  187. package/dist/index.d.ts +1 -0
  188. package/dist/index.js +1 -0
  189. package/dist/interfaces/chatMessage.d.ts +139 -0
  190. package/dist/interfaces/fileInterface.d.ts +10 -0
  191. package/dist/interfaces/fileInterface.js +11 -0
  192. package/dist/interfaces/knowledgeTrace.d.ts +177 -0
  193. package/dist/store/hooks.d.ts +4 -0
  194. package/dist/store/hooks.js +3 -0
  195. package/dist/store/index.d.ts +7 -0
  196. package/dist/store/index.js +7 -0
  197. package/dist/store/slices/gimiMenuSlice.d.ts +95 -0
  198. package/dist/store/slices/gimiMenuSlice.js +251 -0
  199. package/dist/utils/chatInputUtil.d.ts +19 -0
  200. package/dist/utils/chatInputUtil.js +45 -0
  201. package/dist/utils/tools.d.ts +50 -0
  202. package/dist/utils/tools.js +474 -0
  203. package/dist/utils/voice-stream.d.ts +119 -0
  204. package/dist/utils/voice-stream.js +1162 -0
  205. package/package.json +5 -6
  206. package/LICENSE +0 -21
@@ -0,0 +1,230 @@
1
+ @charset "UTF-8";
2
+ .aiChat {
3
+ z-index: 99999;
4
+ position: fixed;
5
+ inset: 0;
6
+ }
7
+ .aiChat .bgImg {
8
+ position: absolute;
9
+ top: 0;
10
+ left: 0;
11
+ right: 0;
12
+ bottom: 0;
13
+ }
14
+ .aiChat .back {
15
+ position: absolute;
16
+ top: 30px;
17
+ left: 20px;
18
+ z-index: 2;
19
+ display: flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ width: 30px;
23
+ height: 30px;
24
+ border-radius: 50%;
25
+ background: #ffffff;
26
+ box-shadow: 0px 0px 10px 0px rgba(153, 167, 191, 0.2);
27
+ border: 1px solid #ebf2ff;
28
+ cursor: pointer;
29
+ }
30
+ .aiChat .rightWrap {
31
+ position: absolute;
32
+ right: 20px;
33
+ top: 30px;
34
+ z-index: 3;
35
+ display: flex;
36
+ align-items: center;
37
+ }
38
+ .aiChat .rightWrap .iconWrap {
39
+ margin-right: 40px;
40
+ }
41
+ .aiChat .introWrap {
42
+ position: absolute;
43
+ top: 60px;
44
+ right: -420px;
45
+ width: 400px;
46
+ height: calc(100vh - 100px);
47
+ padding: 20px 20px 15px;
48
+ background: #f7faff;
49
+ box-shadow: -6px 2px 20px 0px rgba(153, 167, 191, 0.15);
50
+ border-radius: 12px;
51
+ z-index: 2;
52
+ transition: all 0.3s ease;
53
+ }
54
+ .aiChat .introWrap.block {
55
+ right: 20px;
56
+ }
57
+ .aiChat .introWrap .loading {
58
+ display: flex;
59
+ flex-direction: column;
60
+ justify-content: center;
61
+ height: 80%;
62
+ text-align: center;
63
+ }
64
+ .aiChat .introWrap .introHeader {
65
+ display: flex;
66
+ justify-content: space-between;
67
+ align-items: center;
68
+ margin-bottom: 20px;
69
+ }
70
+ .aiChat .introWrap .introHeader .title {
71
+ font-size: 18px;
72
+ font-weight: 600;
73
+ }
74
+ .aiChat .introWrap .introContent {
75
+ height: calc(100% - 60px);
76
+ overflow-y: scroll;
77
+ padding-right: 10px;
78
+ }
79
+ .aiChat .main {
80
+ position: relative;
81
+ height: 100%;
82
+ display: flex;
83
+ flex-direction: column;
84
+ transition: all 0.3s ease;
85
+ }
86
+ .aiChat .main.translate {
87
+ transform: translateX(-160px);
88
+ }
89
+ .aiChat .main .content {
90
+ height: calc(100% - 380px);
91
+ overflow-y: scroll;
92
+ overflow-x: hidden;
93
+ }
94
+ .aiChat .main .content .container {
95
+ width: 800px;
96
+ margin: 0 auto;
97
+ height: 100%;
98
+ }
99
+ .aiChat .main .header {
100
+ display: flex;
101
+ justify-content: center;
102
+ margin-bottom: 30px;
103
+ height: 26px;
104
+ }
105
+ .aiChat .main .header .logo {
106
+ width: 18px;
107
+ height: 18px;
108
+ margin-right: 8px;
109
+ flex-shrink: 0;
110
+ margin-top: 3px;
111
+ }
112
+ .aiChat .main .header .title {
113
+ font-size: 18px;
114
+ text-align: center;
115
+ }
116
+ .aiChat .main .tips {
117
+ font-weight: 400;
118
+ color: #54698c;
119
+ font-size: 17px;
120
+ }
121
+ .aiChat .main .item {
122
+ margin-bottom: 10px;
123
+ font-weight: 400;
124
+ color: #333;
125
+ font-size: 17px;
126
+ line-height: 28px;
127
+ word-break: break-all;
128
+ /* 强制换行 */
129
+ overflow-wrap: break-word;
130
+ /* 在适当位置换行 */
131
+ white-space: pre-wrap;
132
+ }
133
+ .aiChat .main .item.answer {
134
+ font-size: 16;
135
+ color: #b0b0b0;
136
+ }
137
+ .aiChat .main .voiceWrap {
138
+ height: 100%;
139
+ display: flex;
140
+ align-items: center;
141
+ }
142
+ .aiChat .main .bottom {
143
+ display: flex;
144
+ flex-direction: column;
145
+ align-items: center;
146
+ position: absolute;
147
+ bottom: 60px;
148
+ left: 50%;
149
+ transform: translateX(-50%);
150
+ text-align: center;
151
+ }
152
+ .aiChat .main .bottom .pointer {
153
+ cursor: pointer;
154
+ }
155
+ .aiChat .main .bottom .status {
156
+ display: flex;
157
+ flex-direction: column;
158
+ width: 220px;
159
+ margin-bottom: 30px;
160
+ }
161
+ .aiChat .main .bottom .status .iconOutside {
162
+ width: 30px;
163
+ height: 30px;
164
+ display: flex;
165
+ justify-content: center;
166
+ align-items: center;
167
+ border: 3px solid #000000;
168
+ border-radius: 50%;
169
+ }
170
+ .aiChat .main .bottom .status .iconInside {
171
+ width: 13px;
172
+ height: 13px;
173
+ background-color: #000000;
174
+ }
175
+ .aiChat .main .bottom .status .statusImg {
176
+ width: 24px;
177
+ height: 24px;
178
+ border-radius: 8px;
179
+ margin: 0 auto;
180
+ margin-bottom: 15px;
181
+ }
182
+ .aiChat .main .bottom .status .statusText {
183
+ font-size: 16px;
184
+ color: #7d91b3;
185
+ }
186
+ .aiChat .main .bottom .status .statusText.danger {
187
+ color: red;
188
+ }
189
+ .aiChat .main .bottom .btnWrap {
190
+ display: flex;
191
+ justify-content: center;
192
+ }
193
+ .aiChat .main .bottom .btnWrap .btnItem {
194
+ display: flex;
195
+ align-items: center;
196
+ justify-content: center;
197
+ width: 76px;
198
+ height: 76px;
199
+ border-radius: 50%;
200
+ margin-right: 118px;
201
+ background: #ffffff;
202
+ box-shadow: 0px 2px 10px 0px rgba(153, 167, 191, 0.1);
203
+ cursor: pointer;
204
+ }
205
+ .aiChat .main .bottom .btnWrap .btnItem.disable {
206
+ pointer-events: none;
207
+ opacity: 0.5;
208
+ cursor: not-allowed;
209
+ }
210
+ .aiChat .main .bottom .btnWrap .btnItem:last-child {
211
+ margin-right: 0;
212
+ }
213
+
214
+ :global .out-tooltip .ant-tooltip-content .ant-tooltip-arrow {
215
+ left: 55px;
216
+ }
217
+ :global .ai-chat-tooltip {
218
+ z-index: 100000 !important;
219
+ }
220
+
221
+ :global(.ant-message) {
222
+ position: fixed !important;
223
+ z-index: 99999999 !important;
224
+ }
225
+
226
+ .disable {
227
+ opacity: 0.4;
228
+ pointer-events: none;
229
+ cursor: not-allowed;
230
+ }
@@ -0,0 +1,36 @@
1
+ export declare enum MESSAGE_TYPE {
2
+ /** AI 状态消息(说话中/结束/被打断)*/
3
+ BRIEF = "conv",
4
+ /** 语音字幕消息(AI/用户的语音转文字) */
5
+ SUBTITLE = "subv",
6
+ /** 扩展:函数调用消息 */
7
+ FUNCTION_CALL = "tool"
8
+ }
9
+ export declare enum AGENT_BRIEF {
10
+ /** 未知状态 */
11
+ UNKNOWN = 0,
12
+ /** 正在聆听 */
13
+ LISTENING = 1,
14
+ /** 思考中(AI 处理用户问题) */
15
+ THINKING = 2,
16
+ /** 正在说话 */
17
+ SPEAKING = 3,
18
+ /** 被打断 */
19
+ INTERRUPTED = 4,
20
+ /** 说话结束 */
21
+ FINISHED = 5
22
+ }
23
+ export declare type VolcSubtitleEvent = {
24
+ kind: 'subtitle';
25
+ text: string;
26
+ userId?: string;
27
+ definite?: boolean;
28
+ paragraph?: string | number;
29
+ };
30
+ export declare type VolcBriefEvent = {
31
+ kind: 'brief';
32
+ stageCode?: number;
33
+ stageDescription?: string;
34
+ };
35
+ export declare type VolcParsedEvent = VolcSubtitleEvent | VolcBriefEvent;
36
+ export declare function parseVolcBinaryMessage(buffer: ArrayBuffer): VolcParsedEvent | null;
@@ -0,0 +1,52 @@
1
+ import { tlv2String } from "./tlv";
2
+ export var MESSAGE_TYPE = /*#__PURE__*/function (MESSAGE_TYPE) {
3
+ MESSAGE_TYPE["BRIEF"] = "conv";
4
+ MESSAGE_TYPE["SUBTITLE"] = "subv";
5
+ MESSAGE_TYPE["FUNCTION_CALL"] = "tool";
6
+ return MESSAGE_TYPE;
7
+ }({});
8
+
9
+ // 2. AI 状态枚举:定义 BRIEF 消息中“状态码”的语义
10
+ export var AGENT_BRIEF = /*#__PURE__*/function (AGENT_BRIEF) {
11
+ AGENT_BRIEF[AGENT_BRIEF["UNKNOWN"] = 0] = "UNKNOWN";
12
+ AGENT_BRIEF[AGENT_BRIEF["LISTENING"] = 1] = "LISTENING";
13
+ AGENT_BRIEF[AGENT_BRIEF["THINKING"] = 2] = "THINKING";
14
+ AGENT_BRIEF[AGENT_BRIEF["SPEAKING"] = 3] = "SPEAKING";
15
+ AGENT_BRIEF[AGENT_BRIEF["INTERRUPTED"] = 4] = "INTERRUPTED";
16
+ AGENT_BRIEF[AGENT_BRIEF["FINISHED"] = 5] = "FINISHED";
17
+ return AGENT_BRIEF;
18
+ }({});
19
+ // 解析TLV 格式的二进制 buffer
20
+ export function parseVolcBinaryMessage(buffer) {
21
+ try {
22
+ var _tlv2String = tlv2String(buffer),
23
+ type = _tlv2String.type,
24
+ value = _tlv2String.value;
25
+ // 解析字幕消息(SUBTITLE)
26
+ if (type === MESSAGE_TYPE.SUBTITLE) {
27
+ var _parsed$data;
28
+ var parsed = JSON.parse(value);
29
+ var data = (parsed === null || parsed === void 0 || (_parsed$data = parsed.data) === null || _parsed$data === void 0 ? void 0 : _parsed$data[0]) || {};
30
+ return {
31
+ kind: 'subtitle',
32
+ text: data.text || '',
33
+ userId: data.userId,
34
+ definite: data.definite,
35
+ paragraph: data.paragraph
36
+ };
37
+ }
38
+ // 解析 AI 状态消息(BRIEF)
39
+ if (type === MESSAGE_TYPE.BRIEF) {
40
+ var _parsed = JSON.parse(value);
41
+ var stage = (_parsed === null || _parsed === void 0 ? void 0 : _parsed.Stage) || {};
42
+ return {
43
+ kind: 'brief',
44
+ stageCode: stage === null || stage === void 0 ? void 0 : stage.Code,
45
+ stageDescription: stage === null || stage === void 0 ? void 0 : stage.Description
46
+ };
47
+ }
48
+ return null;
49
+ } catch (_unused) {
50
+ return null;
51
+ }
52
+ }
@@ -0,0 +1,7 @@
1
+ /** 字符串转换成 TLV 二进制 前端指令符合 RTC 传输格式*/
2
+ export declare const string2tlv: (str: string, type: string) => ArrayBufferLike;
3
+ /** TLV 二进制 → 字符串 前端读取 RTC 收到的二进制消息 */
4
+ export declare const tlv2String: (tlvBuffer: ArrayBufferLike) => {
5
+ type: string;
6
+ value: string;
7
+ };
@@ -0,0 +1,32 @@
1
+ /** 字符串转换成 TLV 二进制 前端指令符合 RTC 传输格式*/
2
+ export var string2tlv = function string2tlv(str, type) {
3
+ // 1. 读取 Type:前 4 字节转字符串(比如 0x63 0x6f 0x6e 0x76 → 'conv')
4
+ var typeBuffer = new Uint8Array(4);
5
+ for (var i = 0; i < type.length; i++) typeBuffer[i] = type.charCodeAt(i);
6
+ var lengthBuffer = new Uint32Array(1);
7
+ var valueBuffer = new TextEncoder().encode(str);
8
+ lengthBuffer[0] = valueBuffer.length;
9
+ var tlvBuffer = new Uint8Array(typeBuffer.length + 4 + valueBuffer.length);
10
+ tlvBuffer.set(typeBuffer, 0);
11
+ tlvBuffer[4] = lengthBuffer[0] >> 24 & 0xff;
12
+ tlvBuffer[5] = lengthBuffer[0] >> 16 & 0xff;
13
+ tlvBuffer[6] = lengthBuffer[0] >> 8 & 0xff;
14
+ tlvBuffer[7] = lengthBuffer[0] & 0xff;
15
+ tlvBuffer.set(valueBuffer, 8);
16
+ return tlvBuffer.buffer;
17
+ };
18
+
19
+ /** TLV 二进制 → 字符串 前端读取 RTC 收到的二进制消息 */
20
+ export var tlv2String = function tlv2String(tlvBuffer) {
21
+ var typeBuffer = new Uint8Array(tlvBuffer, 0, 4);
22
+ var lengthBuffer = new Uint8Array(tlvBuffer, 4, 4);
23
+ var valueBuffer = new Uint8Array(tlvBuffer, 8);
24
+ var type = '';
25
+ for (var i = 0; i < typeBuffer.length; i++) type += String.fromCharCode(typeBuffer[i]);
26
+ var length = lengthBuffer[0] << 24 | lengthBuffer[1] << 16 | lengthBuffer[2] << 8 | lengthBuffer[3];
27
+ var value = new TextDecoder().decode(valueBuffer.subarray(0, length));
28
+ return {
29
+ type: type,
30
+ value: value
31
+ };
32
+ };
@@ -0,0 +1,47 @@
1
+ export declare enum COMMAND {
2
+ /** 指令打断ai发言 */
3
+ INTERRUPT = "interrupt"
4
+ }
5
+ export declare enum INTERRUPT_PRIORITY {
6
+ /** 无优先级 */
7
+ NONE = 0,
8
+ /** 高优先级 */
9
+ HIGH = 1,
10
+ /** 中优先级 */
11
+ MEDIUM = 2,
12
+ /** 低优先级 */
13
+ LOW = 3
14
+ }
15
+ export declare type RtcConfig = {
16
+ appId: string;
17
+ roomId: string;
18
+ userId: string;
19
+ token: string;
20
+ agentName: string;
21
+ };
22
+ export declare type VoiceChatStartParams = Record<string, any>;
23
+ export declare type VoiceChatStopParams = Record<string, any>;
24
+ export declare class VolcVoiceCallClient {
25
+ private engine;
26
+ private cfg;
27
+ private handlers;
28
+ private startVoiceChat;
29
+ private stopVoiceChat;
30
+ private startVoiceChatParams?;
31
+ private stopVoiceChatParams?;
32
+ constructor(opts: {
33
+ rtcConfig: RtcConfig;
34
+ startVoiceChat: (p: VoiceChatStartParams) => Promise<any>;
35
+ stopVoiceChat: (p: VoiceChatStopParams) => Promise<any>;
36
+ startVoiceChatParams?: VoiceChatStartParams;
37
+ stopVoiceChatParams?: VoiceChatStopParams;
38
+ });
39
+ onBinaryMessage(cb: (buffer: ArrayBuffer) => void): void;
40
+ onError(cb: (e: any) => void): void;
41
+ private bindEvents;
42
+ connect(): Promise<void>;
43
+ disconnect(): Promise<void>;
44
+ setAudioEnable(enable: boolean): Promise<void>;
45
+ mutePlayback(): void;
46
+ interrupt(interruptMode?: INTERRUPT_PRIORITY, message?: string): void;
47
+ }
@@ -0,0 +1,246 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
11
+ import VERTC, { MediaType, RoomProfileType, StreamIndex } from '@volcengine/rtc';
12
+ import { string2tlv } from "./tlv";
13
+ export var COMMAND = /*#__PURE__*/function (COMMAND) {
14
+ COMMAND["INTERRUPT"] = "interrupt";
15
+ return COMMAND;
16
+ }({});
17
+
18
+ // 2打断优先级枚举
19
+ export var INTERRUPT_PRIORITY = /*#__PURE__*/function (INTERRUPT_PRIORITY) {
20
+ INTERRUPT_PRIORITY[INTERRUPT_PRIORITY["NONE"] = 0] = "NONE";
21
+ INTERRUPT_PRIORITY[INTERRUPT_PRIORITY["HIGH"] = 1] = "HIGH";
22
+ INTERRUPT_PRIORITY[INTERRUPT_PRIORITY["MEDIUM"] = 2] = "MEDIUM";
23
+ INTERRUPT_PRIORITY[INTERRUPT_PRIORITY["LOW"] = 3] = "LOW";
24
+ return INTERRUPT_PRIORITY;
25
+ }({});
26
+ export var VolcVoiceCallClient = /*#__PURE__*/function () {
27
+ function VolcVoiceCallClient(opts) {
28
+ _classCallCheck(this, VolcVoiceCallClient);
29
+ _defineProperty(this, "engine", null);
30
+ _defineProperty(this, "cfg", void 0);
31
+ _defineProperty(this, "handlers", {});
32
+ // 后端接口:在 init 传入即可
33
+ _defineProperty(this, "startVoiceChat", void 0);
34
+ _defineProperty(this, "stopVoiceChat", void 0);
35
+ _defineProperty(this, "startVoiceChatParams", void 0);
36
+ _defineProperty(this, "stopVoiceChatParams", void 0);
37
+ this.cfg = opts.rtcConfig;
38
+ this.startVoiceChat = opts.startVoiceChat;
39
+ this.stopVoiceChat = opts.stopVoiceChat;
40
+ this.startVoiceChatParams = opts.startVoiceChatParams;
41
+ this.stopVoiceChatParams = opts.stopVoiceChatParams;
42
+ }
43
+
44
+ // 注册“接收二进制消息”的回调(AI 推送的状态/字幕)
45
+ _createClass(VolcVoiceCallClient, [{
46
+ key: "onBinaryMessage",
47
+ value: function onBinaryMessage(cb) {
48
+ this.handlers.onBinaryMessage = cb;
49
+ }
50
+ // 注册“错误”回调(RTC 引擎异常)
51
+ }, {
52
+ key: "onError",
53
+ value: function onError(cb) {
54
+ this.handlers.onError = cb;
55
+ }
56
+ }, {
57
+ key: "bindEvents",
58
+ value: function bindEvents() {
59
+ var _this = this;
60
+ if (!this.engine) return;
61
+ // 1. 监听 RTC 引擎的全局错误事件
62
+ this.engine.on(VERTC.events.onError, function (e) {
63
+ var _this$handlers$onErro, _this$handlers;
64
+ (_this$handlers$onErro = (_this$handlers = _this.handlers).onError) === null || _this$handlers$onErro === void 0 || _this$handlers$onErro.call(_this$handlers, e);
65
+ });
66
+
67
+ // 注册接收二进制消息(机器人发送的字幕、状态等二进制数据)
68
+ this.engine.on(VERTC.events.onRoomBinaryMessageReceived, function (e) {
69
+ var _this$handlers$onBina, _this$handlers2;
70
+ (_this$handlers$onBina = (_this$handlers2 = _this.handlers).onBinaryMessage) === null || _this$handlers$onBina === void 0 || _this$handlers$onBina.call(_this$handlers2, e.message);
71
+ });
72
+ }
73
+ }, {
74
+ key: "connect",
75
+ value: function () {
76
+ var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) switch (_context.prev = _context.next) {
79
+ case 0:
80
+ if (!this.engine) {
81
+ // 创建 RTC 引擎
82
+ this.engine = VERTC.createEngine(this.cfg.appId);
83
+ // 监听RTC引擎,注册事件
84
+ this.bindEvents();
85
+ }
86
+
87
+ // 加入房间
88
+ _context.next = 3;
89
+ return this.engine.joinRoom(
90
+ // 1. 房间鉴权 Token(必填)
91
+ this.cfg.token, // 2. 房间 ID(必填)
92
+ "".concat(this.cfg.roomId), {
93
+ userId: this.cfg.userId,
94
+ extraInfo: JSON.stringify({
95
+ call_scene: 'RTC-AIGC',
96
+ user_name: this.cfg.userId,
97
+ user_id: this.cfg.userId
98
+ })
99
+ }, {
100
+ isAutoPublish: true,
101
+ // 自动发布本地音频流(麦克风采集的声音)到房间
102
+ isAutoSubscribeAudio: true,
103
+ // 自动订阅房间内其他用户的音频流(比如AI机器人的语音)
104
+ roomProfileType: RoomProfileType.chat // 房间场景类型:聊天场景(适配语音交互的音频参数)
105
+ });
106
+ case 3:
107
+ _context.next = 5;
108
+ return this.engine.startAudioCapture();
109
+ case 5:
110
+ _context.next = 7;
111
+ return this.startVoiceChat(this.startVoiceChatParams || {});
112
+ case 7:
113
+ case "end":
114
+ return _context.stop();
115
+ }
116
+ }, _callee, this);
117
+ }));
118
+ function connect() {
119
+ return _connect.apply(this, arguments);
120
+ }
121
+ return connect;
122
+ }() // 清理资源 + 离开房间
123
+ }, {
124
+ key: "disconnect",
125
+ value: function () {
126
+ var _disconnect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
127
+ var _this$engine, _this$engine2;
128
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
129
+ while (1) switch (_context2.prev = _context2.next) {
130
+ case 0:
131
+ _context2.prev = 0;
132
+ _context2.next = 3;
133
+ return this.stopVoiceChat(this.stopVoiceChatParams || {});
134
+ case 3:
135
+ _context2.next = 7;
136
+ break;
137
+ case 5:
138
+ _context2.prev = 5;
139
+ _context2.t0 = _context2["catch"](0);
140
+ case 7:
141
+ _context2.prev = 7;
142
+ _context2.next = 10;
143
+ return (_this$engine = this.engine) === null || _this$engine === void 0 ? void 0 : _this$engine.stopAudioCapture();
144
+ case 10:
145
+ _context2.next = 14;
146
+ break;
147
+ case 12:
148
+ _context2.prev = 12;
149
+ _context2.t1 = _context2["catch"](7);
150
+ case 14:
151
+ _context2.prev = 14;
152
+ _context2.next = 17;
153
+ return (_this$engine2 = this.engine) === null || _this$engine2 === void 0 ? void 0 : _this$engine2.leaveRoom();
154
+ case 17:
155
+ _context2.next = 21;
156
+ break;
157
+ case 19:
158
+ _context2.prev = 19;
159
+ _context2.t2 = _context2["catch"](14);
160
+ case 21:
161
+ if (this.engine) {
162
+ try {
163
+ VERTC.destroyEngine(this.engine);
164
+ } catch (_unused4) {}
165
+ }
166
+ this.engine = null;
167
+ case 23:
168
+ case "end":
169
+ return _context2.stop();
170
+ }
171
+ }, _callee2, this, [[0, 5], [7, 12], [14, 19]]);
172
+ }));
173
+ function disconnect() {
174
+ return _disconnect.apply(this, arguments);
175
+ }
176
+ return disconnect;
177
+ }() // 静音 音频采集控制:
178
+ }, {
179
+ key: "setAudioEnable",
180
+ value: function () {
181
+ var _setAudioEnable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(enable) {
182
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
183
+ while (1) switch (_context3.prev = _context3.next) {
184
+ case 0:
185
+ if (this.engine) {
186
+ _context3.next = 2;
187
+ break;
188
+ }
189
+ return _context3.abrupt("return");
190
+ case 2:
191
+ if (!enable) {
192
+ _context3.next = 8;
193
+ break;
194
+ }
195
+ _context3.next = 5;
196
+ return this.engine.startAudioCapture();
197
+ case 5:
198
+ // 音频发布(控制是否把自己的语音发送到房间)
199
+ this.engine.publishStream(MediaType.AUDIO);
200
+ _context3.next = 11;
201
+ break;
202
+ case 8:
203
+ // 取消发布(控制是否把自己的语音发送到房间)
204
+ this.engine.unpublishStream(MediaType.AUDIO);
205
+ // stopAudioCapture(关闭麦克风)
206
+ _context3.next = 11;
207
+ return this.engine.stopAudioCapture();
208
+ case 11:
209
+ case "end":
210
+ return _context3.stop();
211
+ }
212
+ }, _callee3, this);
213
+ }));
214
+ function setAudioEnable(_x) {
215
+ return _setAudioEnable.apply(this, arguments);
216
+ }
217
+ return setAudioEnable;
218
+ }() // 静音机器人播报(把机器人远端音频在本地播放音量置 0)
219
+ }, {
220
+ key: "mutePlayback",
221
+ value: function mutePlayback() {
222
+ if (!this.engine) return;
223
+ var botUserId = this.cfg.agentName;
224
+ if (!botUserId) return;
225
+ this.engine.setPlaybackVolume(this.cfg.agentName, StreamIndex.STREAM_INDEX_MAIN, 0);
226
+ }
227
+
228
+ // 打断 AI 发言 (发送二进制控制指令给机器人,实现 “打断 AI 说话” 的功能)
229
+ }, {
230
+ key: "interrupt",
231
+ value: function interrupt() {
232
+ var interruptMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INTERRUPT_PRIORITY.HIGH;
233
+ var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
234
+ if (!this.engine) return;
235
+
236
+ // demo 协议:type='ctrl',body 里 Command/InterruptMode/Message
237
+ var payload = {
238
+ Command: COMMAND.INTERRUPT,
239
+ InterruptMode: interruptMode,
240
+ Message: message
241
+ };
242
+ this.engine.sendUserBinaryMessage(this.cfg.agentName, string2tlv(JSON.stringify(payload), 'ctrl'));
243
+ }
244
+ }]);
245
+ return VolcVoiceCallClient;
246
+ }();
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ declare const AICorrection: ({ value }: {
3
+ value: any;
4
+ }) => React.JSX.Element | null;
5
+ export default AICorrection;