@coze/realtime-api 1.3.0 → 1.3.2-alpha.f7fe14

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.
@@ -1,25 +0,0 @@
1
- export declare enum RealtimeError {
2
- DEVICE_ACCESS_ERROR = "DEVICE_ACCESS_ERROR",
3
- STREAM_CREATION_ERROR = "STREAM_CREATION_ERROR",
4
- CONNECTION_ERROR = "CONNECTION_ERROR",
5
- DISCONNECTION_ERROR = "DISCONNECTION_ERROR",
6
- INTERRUPT_ERROR = "INTERRUPT_ERROR",
7
- EVENT_HANDLER_ERROR = "EVENT_HANDLER_ERROR",
8
- PERMISSION_DENIED = "PERMISSION_DENIED",
9
- NETWORK_ERROR = "NETWORK_ERROR",
10
- INVALID_STATE = "INVALID_STATE",
11
- CREATE_ROOM_ERROR = "CREATE_ROOM_ERROR",
12
- PARSE_MESSAGE_ERROR = "PARSE_MESSAGE_ERROR",
13
- HANDLER_MESSAGE_ERROR = "HANDLER_MESSAGE_ERROR"
14
- }
15
- export declare const ErrorMessages: Record<RealtimeError, string>;
16
- export declare class RealtimeAPIError extends Error {
17
- code: RealtimeError;
18
- error?: unknown;
19
- /**
20
- * @param code - Error code
21
- * @param message - Error message
22
- * @param error - Error object
23
- */
24
- constructor(code: RealtimeError, message: string, error?: unknown);
25
- }
@@ -1,12 +0,0 @@
1
- export type EventCallback = (eventName: string, event: unknown) => void;
2
- export declare class RealtimeEventHandler {
3
- private eventHandlers;
4
- protected _debug: boolean;
5
- constructor(debug?: boolean);
6
- clearEventHandlers(): void;
7
- on(eventName: string, callback: EventCallback): EventCallback;
8
- off(eventName: string, callback: EventCallback): void;
9
- private _dispatchToHandlers;
10
- dispatch(eventName: string, event: unknown, consoleLog?: boolean): void;
11
- _log(message: string, event?: unknown): void;
12
- }
@@ -1,163 +0,0 @@
1
- import { type ScreenConfig, type AudioPropertiesConfig, type IRTCEngine } from '@volcengine/rtc';
2
- import { type CreateRoomData, type GetToken, type RoomMode } from '@coze/api';
3
- import * as RealtimeUtils from './utils';
4
- import EventNames from './event-names';
5
- import { RealtimeEventHandler } from './event-handler';
6
- import { RealtimeAPIError, RealtimeError } from './error';
7
- export interface VideoConfig {
8
- videoOnDefault?: boolean /** optional, Whether to turn on video by default, defaults to true */;
9
- renderDom?: string /** optional, The DOM element to render the video stream to */;
10
- videoInputDeviceId?: string /** optional, The device ID of the video input device to use */;
11
- screenConfig?: ScreenConfig;
12
- }
13
- export interface RealtimeClientConfig {
14
- accessToken: GetToken /** required, Access Token */;
15
- botId: string /** required, Bot Id */;
16
- voiceId?: string /** optional, Voice Id */;
17
- conversationId?: string /** optional, Conversation Id */;
18
- userId?: string /** optional, User Id */;
19
- workflowId?: string /** optional, Workflow Id */;
20
- baseURL?: string /** optional, defaults to "https://api.coze.cn" */;
21
- debug?: boolean /** optional, defaults to false */;
22
- getRoomInfo?: () => Promise<CreateRoomData> /** optional, Customize get room info */;
23
- /** Whether Personal Access Tokens (PAT) are allowed in browser environments */
24
- allowPersonalAccessTokenInBrowser?: boolean;
25
- /** Whether to mute by default, defaults to false
26
- * If set to true, audio streams will not be automatically published and subscribed */
27
- audioMutedDefault?: boolean;
28
- connectorId: string /** required, Connector Id */;
29
- suppressStationaryNoise?: boolean /** optional, Suppress stationary noise, defaults to false */;
30
- suppressNonStationaryNoise?: boolean /** optional, Suppress non-stationary noise, defaults to false */;
31
- videoConfig?: VideoConfig /** optional, Video configuration */;
32
- isAutoSubscribeAudio?: boolean /** optional, Whether to automatically subscribe to bot reply audio streams, defaults to true */;
33
- prologueContent?: string /** optional, Prologue content */;
34
- roomMode?: RoomMode /** optional, Room mode */;
35
- }
36
- declare class RealtimeClient extends RealtimeEventHandler {
37
- _config: RealtimeClientConfig;
38
- private _client;
39
- isConnected: boolean;
40
- private _api;
41
- private _isTestEnv;
42
- _isSupportVideo: boolean;
43
- /**
44
- * Constructor for initializing a RealtimeClient instance.
45
- *
46
- * 构造函数,初始化RealtimeClient实例。
47
- *
48
- * @param config
49
- * @param config.accessToken - Required, Access Token. |
50
- * 必填,Access Token。
51
- * @param config.botId - Required, Bot Id. |
52
- * 必填,Bot Id。
53
- * @param config.voiceId - Optional, Voice Id. |
54
- * 可选,音色Id。
55
- * @param config.conversationId - Optional, Conversation Id. |
56
- * 可选,会话Id。
57
- * @param config.userId - Optional, User Id. |
58
- * 可选,用户Id。
59
- * @param config.baseURL - Optional, defaults to "https://api.coze.cn". |
60
- * 可选,默认值为 "https://api.coze.cn"。
61
- * @param config.debug - Optional, defaults to false.
62
- * 可选,默认值为 false。
63
- * @param config.allowPersonalAccessTokenInBrowser
64
- * - Optional, whether to allow personal access tokens in browser environment. |
65
- * 可选,是否允许在浏览器环境中使用个人访问令牌。
66
- * @param config.audioMutedDefault - Optional, whether audio is muted by default, defaults to false. |
67
- * 可选,默认是否静音,默认值为 false。
68
- * @param config.connectorId - Required, Connector Id. |
69
- * 必填,渠道 Id。
70
- * @param config.suppressStationaryNoise - Optional, suppress stationary noise, defaults to false. |
71
- * 可选,默认是否抑制静态噪声,默认值为 false。
72
- * @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
73
- * 可选,默认是否抑制非静态噪声,默认值为 false。
74
- * @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
75
- * @param config.videoConfig - Optional, Video configuration. |
76
- * 可选,视频配置。
77
- * @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
78
- * 可选,默认是否开启视频,默认值为 true。
79
- * @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
80
- * 可选,渲染视频流的 DOM 元素。
81
- * @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
82
- * 可选,视频输入设备的设备 ID。
83
- * @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
84
- * 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
85
- * @param config.prologueContent - Optional, Prologue content. | 可选,开场白内容。
86
- * @param config.roomMode - Optional, Room mode. | 可选,房间模式。
87
- */
88
- constructor(config: RealtimeClientConfig);
89
- /**
90
- * en: Establish a connection to the Coze API and join the room
91
- *
92
- * zh: 建立与 Coze API 的连接并加入房间
93
- */
94
- connect(): Promise<void>;
95
- /**
96
- * en: Interrupt the current conversation
97
- *
98
- * zh: 中断当前对话
99
- */
100
- interrupt(): Promise<void>;
101
- /**
102
- * en: Disconnect from the current session
103
- *
104
- * zh: 断开与当前会话的连接
105
- */
106
- disconnect(): Promise<void>;
107
- /**
108
- * en: Send a message to the bot
109
- *
110
- * zh: 发送消息给Bot
111
- */
112
- sendMessage(message: Record<string, unknown>): Promise<void>;
113
- /**
114
- * en: Enable or disable audio
115
- *
116
- * zh: 启用或禁用音频
117
- */
118
- setAudioEnable(isEnable: boolean): Promise<void>;
119
- setVideoEnable(isEnable: boolean): Promise<void>;
120
- /**
121
- * en: Enable audio properties reporting (debug mode only)
122
- *
123
- * zh: 启用音频属性报告(仅限调试模式)
124
- */
125
- enableAudioPropertiesReport(config?: AudioPropertiesConfig): boolean;
126
- /**
127
- * en: Start audio playback device test (debug mode only)
128
- *
129
- * zh: 开始音频播放设备测试(仅限调试模式)
130
- */
131
- startAudioPlaybackDeviceTest(): Promise<void>;
132
- /**
133
- * en: Stop audio playback device test (debug mode only)
134
- *
135
- * zh: 停止音频播放设备测试(仅限调试模式)
136
- */
137
- stopAudioPlaybackDeviceTest(): void;
138
- /**
139
- * en: Set the audio input device
140
- *
141
- * zh: 设置音频输入设备
142
- */
143
- setAudioInputDevice(deviceId: string): Promise<void>;
144
- /**
145
- * en: Set the audio output device
146
- *
147
- * zh: 设置音频输出设备
148
- */
149
- setAudioOutputDevice(deviceId: string): Promise<void>;
150
- /**
151
- * en: Set the video input device
152
- *
153
- * zh: 设置视频输入设备
154
- */
155
- setVideoInputDevice(deviceId: string | 'screenShare' | 'user' | 'environment'): Promise<void>;
156
- /**
157
- * en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
158
- *
159
- * zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
160
- */
161
- getRtcEngine(): IRTCEngine | undefined;
162
- }
163
- export { RealtimeUtils, RealtimeClient, RealtimeAPIError, RealtimeError, EventNames, };
@@ -1,49 +0,0 @@
1
- /**
2
- + * Delays execution for the specified duration
3
- + * @param milliseconds The time to sleep in milliseconds
4
- + * @throws {Error} If milliseconds is negative
5
- + * @returns Promise that resolves after the specified duration
6
- + */
7
- export declare const sleep: (milliseconds: number) => Promise<void>;
8
- /**
9
- * @deprecated use checkDevicePermission instead
10
- * Check microphone permission,return boolean
11
- */
12
- export declare const checkPermission: ({ audio, video, }?: {
13
- audio?: boolean;
14
- video?: boolean;
15
- }) => Promise<boolean>;
16
- /**
17
- * Checks device permissions for audio and video
18
- * @param checkVideo Whether to check video permissions (default: false)
19
- * @returns Promise that resolves with the device permission status
20
- */
21
- export declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
22
- video: boolean;
23
- audio: boolean;
24
- videoExceptionError?: DOMException | undefined;
25
- audioExceptionError?: DOMException | undefined;
26
- }>;
27
- /**
28
- * Get audio devices
29
- * @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
30
- */
31
- export declare const getAudioDevices: ({ video, }?: {
32
- video?: boolean;
33
- }) => Promise<{
34
- audioInputs: MediaDeviceInfo[];
35
- audioOutputs: MediaDeviceInfo[];
36
- videoInputs: MediaDeviceInfo[];
37
- }>;
38
- export declare const isScreenShareDevice: (deviceId?: string) => boolean;
39
- /**
40
- * 判断是否前后置摄像头
41
- * @param deviceId
42
- * @returns
43
- */
44
- export declare const isMobileVideoDevice: (deviceId?: string) => boolean;
45
- /**
46
- * Check if browser supports screen sharing
47
- * 检查浏览器是否支持屏幕共享
48
- */
49
- export declare function isScreenShareSupported(): boolean;
@@ -1,208 +0,0 @@
1
- declare enum EventNames {
2
- /**
3
- * en: All events
4
- * zh: 所有事件
5
- */
6
- ALL = "realtime.event",
7
- /**
8
- * en: All client events
9
- * zh: 所有客户端事件
10
- */
11
- ALL_CLIENT = "client.*",
12
- /**
13
- * en: All server events
14
- * zh: 所有服务端事件
15
- */
16
- ALL_SERVER = "server.*",
17
- /**
18
- * en: Room info
19
- * zh: 房间信息
20
- */
21
- ROOM_INFO = "client.room.info",
22
- /**
23
- * en: Client connected
24
- * zh: 客户端连接
25
- */
26
- CONNECTED = "client.connected",
27
- /**
28
- * en: Client connecting
29
- * zh: 客户端连接中
30
- */
31
- CONNECTING = "client.connecting",
32
- /**
33
- * en: Client interrupted
34
- * zh: 客户端中断
35
- */
36
- INTERRUPTED = "client.interrupted",
37
- /**
38
- * en: Client disconnected
39
- * zh: 客户端断开
40
- */
41
- DISCONNECTED = "client.disconnected",
42
- /**
43
- * en: Client audio unmuted
44
- * zh: 客户端音频未静音
45
- */
46
- AUDIO_UNMUTED = "client.audio.unmuted",
47
- /**
48
- * en: Client audio muted
49
- * zh: 客户端音频静音
50
- */
51
- AUDIO_MUTED = "client.audio.muted",
52
- /**
53
- * en: Client video on
54
- * zh: 客户端视频开启
55
- */
56
- VIDEO_ON = "client.video.on",
57
- /**
58
- * en: Client video off
59
- * zh: 客户端视频关闭
60
- */
61
- VIDEO_OFF = "client.video.off",
62
- /**
63
- * en: Client video error
64
- * zh: 客户端视频(或屏幕共享)错误
65
- */
66
- VIDEO_ERROR = "client.video.error",
67
- /**
68
- * en: Client video event
69
- * zh: 客户端视频事件
70
- */
71
- PLAYER_EVENT = "client.video.event",
72
- /**
73
- * en: Client error
74
- * zh: 客户端错误
75
- */
76
- ERROR = "client.error",
77
- /**
78
- * en: Audio noise reduction enabled
79
- * zh: 抑制平稳噪声
80
- */
81
- SUPPRESS_STATIONARY_NOISE = "client.suppress.stationary.noise",
82
- /**
83
- * en: Suppress non-stationary noise
84
- * zh: 抑制非平稳噪声
85
- */
86
- SUPPRESS_NON_STATIONARY_NOISE = "client.suppress.non.stationary.noise",
87
- /**
88
- * en: Audio input device changed
89
- * zh: 音频输入设备改变
90
- */
91
- AUDIO_INPUT_DEVICE_CHANGED = "client.input.device.changed",
92
- /**
93
- * en: Audio output device changed
94
- * zh: 音频输出设备改变
95
- */
96
- AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
97
- /**
98
- * en: Video input device changed
99
- * zh: 视频输入设备改变
100
- */
101
- VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
102
- /**
103
- * en: Network quality changed
104
- * zh: 网络质量改变
105
- */
106
- NETWORK_QUALITY = "client.network.quality",
107
- /**
108
- * en: Bot joined
109
- * zh: Bot 加入
110
- */
111
- BOT_JOIN = "server.bot.join",
112
- /**
113
- * en: Bot left
114
- * zh: Bot 离开
115
- */
116
- BOT_LEAVE = "server.bot.leave",
117
- /**
118
- * en: Audio speech started
119
- * zh: 开始说话
120
- */
121
- AUDIO_AGENT_SPEECH_STARTED = "server.audio.agent.speech_started",
122
- /**
123
- * en: Audio speech stopped
124
- * zh: 停止说话
125
- */
126
- AUDIO_AGENT_SPEECH_STOPPED = "server.audio.agent.speech_stopped",
127
- /**
128
- * en: Server error
129
- * zh: 服务端错误
130
- */
131
- SERVER_ERROR = "server.error",
132
- /**
133
- * en: User speech started
134
- * zh: 用户开始说话
135
- */
136
- AUDIO_USER_SPEECH_STARTED = "server.audio.user.speech_started",
137
- /**
138
- * en: User speech stopped
139
- * zh: 用户停止说话
140
- */
141
- AUDIO_USER_SPEECH_STOPPED = "server.audio.user.speech_stopped",
142
- /**
143
- * en: User successfully enters the room
144
- * zh: 用户成功进入房间后,会收到该事件
145
- */
146
- SESSION_CREATED = "server.session.created",
147
- /**
148
- * en: Session updated
149
- * zh: 会话更新
150
- */
151
- SESSION_UPDATED = "server.session.updated",
152
- /**
153
- * en: Conversation created
154
- * zh: 会话创建
155
- */
156
- CONVERSATION_CREATED = "server.conversation.created",
157
- /**
158
- * en: Conversation chat created
159
- * zh: 会话对话创建
160
- */
161
- CONVERSATION_CHAT_CREATED = "server.conversation.chat.created",
162
- /**
163
- * en: Conversation chat in progress
164
- * zh: 对话正在处理中
165
- */
166
- CONVERSATION_CHAT_IN_PROGRESS = "server.conversation.chat.in_progress",
167
- /**
168
- * en: Conversation message delta received
169
- * zh: 文本消息增量返回
170
- */
171
- CONVERSATION_MESSAGE_DELTA = "server.conversation.message.delta",
172
- /**
173
- * en: Conversation message completed
174
- * zh: 文本消息完成
175
- */
176
- CONVERSATION_MESSAGE_COMPLETED = "server.conversation.message.completed",
177
- /**
178
- * en: Conversation chat completed
179
- * zh: 对话完成
180
- */
181
- CONVERSATION_CHAT_COMPLETED = "server.conversation.chat.completed",
182
- /**
183
- * en: Conversation chat requires action
184
- * zh: 对话需要插件
185
- */
186
- CONVERSATION_CHAT_REQUIRES_ACTION = "server.conversation.chat.requires_action",
187
- /**
188
- * en: Conversation chat failed
189
- * zh: 对话失败
190
- */
191
- CONVERSATION_CHAT_FAILED = "server.conversation.chat.failed",
192
- /**
193
- * en: Session pre answer updated
194
- * zh: 安抚配置更新成功
195
- */
196
- SESSION_PRE_ANSWER_UPDATED = "server.session.pre_answer.updated",
197
- /**
198
- * en: Conversation audio transcript delta
199
- * zh: 用户语音识别字幕
200
- */
201
- CONVERSATION_AUDIO_TRANSCRIPT_DELTA = "server.conversation.audio_transcript.delta",
202
- /**
203
- * en: Mode updated
204
- * zh: 更新房间模式成功
205
- */
206
- MODE_UPDATED = "server.mode.updated"
207
- }
208
- export default EventNames;
@@ -1,49 +0,0 @@
1
- /**
2
- + * Delays execution for the specified duration
3
- + * @param milliseconds The time to sleep in milliseconds
4
- + * @throws {Error} If milliseconds is negative
5
- + * @returns Promise that resolves after the specified duration
6
- + */
7
- export declare const sleep: (milliseconds: number) => Promise<void>;
8
- /**
9
- * @deprecated use checkDevicePermission instead
10
- * Check microphone permission,return boolean
11
- */
12
- export declare const checkPermission: ({ audio, video, }?: {
13
- audio?: boolean;
14
- video?: boolean;
15
- }) => Promise<boolean>;
16
- /**
17
- * Checks device permissions for audio and video
18
- * @param checkVideo Whether to check video permissions (default: false)
19
- * @returns Promise that resolves with the device permission status
20
- */
21
- export declare const checkDevicePermission: (checkVideo?: boolean) => Promise<{
22
- video: boolean;
23
- audio: boolean;
24
- videoExceptionError?: DOMException | undefined;
25
- audioExceptionError?: DOMException | undefined;
26
- }>;
27
- /**
28
- * Get audio devices
29
- * @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
30
- */
31
- export declare const getAudioDevices: ({ video, }?: {
32
- video?: boolean;
33
- }) => Promise<{
34
- audioInputs: MediaDeviceInfo[];
35
- audioOutputs: MediaDeviceInfo[];
36
- videoInputs: MediaDeviceInfo[];
37
- }>;
38
- export declare const isScreenShareDevice: (deviceId?: string) => boolean;
39
- /**
40
- * 判断是否前后置摄像头
41
- * @param deviceId
42
- * @returns
43
- */
44
- export declare const isMobileVideoDevice: (deviceId?: string) => boolean;
45
- /**
46
- * Check if browser supports screen sharing
47
- * 检查浏览器是否支持屏幕共享
48
- */
49
- export declare function isScreenShareSupported(): boolean;