@coze/realtime-api 1.0.4-beta.2 → 1.0.5-alpha.126a93

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.
package/dist/esm/index.js CHANGED
@@ -1,9 +1,16 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
2
  var __webpack_modules__ = {
3
+ "../../common/temp/default/node_modules/.pnpm/ws@8.18.0/node_modules/ws/browser.js": function(module) {
4
+ module.exports = function() {
5
+ throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object");
6
+ };
7
+ },
3
8
  "?666e": function() {
4
9
  /* (ignored) */ },
5
10
  "?79fd": function() {
6
11
  /* (ignored) */ },
12
+ "?8dee": function() {
13
+ /* (ignored) */ },
7
14
  "?9050": function() {
8
15
  /* (ignored) */ }
9
16
  };
@@ -229,8 +236,6 @@ class error_APIError extends CozeError {
229
236
  if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
230
237
  const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
231
238
  if (logId) list.push(`logid: ${logId}`);
232
- const help_doc = null == error ? void 0 : error.help_doc;
233
- if (help_doc) list.push(`help doc: ${help_doc}`);
234
239
  return list.join(', ');
235
240
  }
236
241
  if (status) return `http status code: ${status} (no body)`;
@@ -253,21 +258,20 @@ class error_APIError extends CozeError {
253
258
  return new error_APIError(status, error, message, headers);
254
259
  }
255
260
  constructor(status, error, message, headers){
256
- var _error_error, _error_error1;
261
+ var _error_detail, _error_error;
257
262
  super(`${error_APIError.makeMessage(status, error, message, headers)}`);
258
263
  this.status = status;
259
264
  this.headers = headers;
260
- this.logid = null == headers ? void 0 : headers['x-tt-logid'];
265
+ this.logid = (null == error ? void 0 : null === (_error_detail = error.detail) || void 0 === _error_detail ? void 0 : _error_detail.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
261
266
  // this.error = error;
262
267
  this.code = null == error ? void 0 : error.code;
263
268
  this.msg = null == error ? void 0 : error.msg;
264
269
  this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
265
- this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
266
270
  this.rawError = error;
267
271
  }
268
272
  }
269
273
  class APIConnectionError extends error_APIError {
270
- constructor({ message, cause }){
274
+ constructor({ message }){
271
275
  super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
272
276
  // if (cause) {
273
277
  // this.cause = cause;
@@ -3502,6 +3506,17 @@ class Runs extends APIResource {
3502
3506
  const response = await this._client.post(apiUrl, params, false, options);
3503
3507
  return response;
3504
3508
  }
3509
+ /**
3510
+ * Get the workflow run history | 工作流异步运行后,查看执行结果
3511
+ * @docs zh: https://www.coze.cn/open/docs/developer_guides/workflow_history
3512
+ * @param workflowId - Required The ID of the workflow. | 必选 工作流 ID。
3513
+ * @param executeId - Required The ID of the workflow execution. | 必选 工作流执行 ID。
3514
+ * @returns WorkflowExecuteHistory[] | 工作流执行历史
3515
+ */ async history(workflowId, executeId, options) {
3516
+ const apiUrl = `/v1/workflows/${workflowId}/run_histories/${executeId}`;
3517
+ const response = await this._client.get(apiUrl, void 0, false, options);
3518
+ return response.data;
3519
+ }
3505
3520
  }
3506
3521
  class WorkflowEvent {
3507
3522
  constructor(id, event, data){
@@ -3663,7 +3678,7 @@ class documents_Documents extends APIResource {
3663
3678
  * @returns ListDocumentData | 知识库文件列表
3664
3679
  */ async list(params, options) {
3665
3680
  const apiUrl = '/open_api/knowledge/document/list';
3666
- const response = await this._client.get(apiUrl, params, false, mergeConfig(options, {
3681
+ const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
3667
3682
  headers: documents_documents_headers
3668
3683
  }));
3669
3684
  return response;
@@ -3914,10 +3929,705 @@ class Templates extends APIResource {
3914
3929
  return response.data;
3915
3930
  }
3916
3931
  }
3932
+ class chat_Chat extends APIResource {
3933
+ async create(botId, options) {
3934
+ const apiUrl = `/v1/chat?bot_id=${botId}`;
3935
+ return await this._client.makeWebsocket(apiUrl, options);
3936
+ }
3937
+ }
3938
+ class transcriptions_Transcriptions extends APIResource {
3939
+ async create(options) {
3940
+ const apiUrl = '/v1/audio/transcriptions';
3941
+ return await this._client.makeWebsocket(apiUrl, options);
3942
+ }
3943
+ }
3944
+ class speech_Speech extends APIResource {
3945
+ async create(options) {
3946
+ const apiUrl = '/v1/audio/speech';
3947
+ return await this._client.makeWebsocket(apiUrl, options);
3948
+ }
3949
+ }
3950
+ class websockets_audio_Audio extends APIResource {
3951
+ constructor(...args){
3952
+ super(...args), this.speech = new speech_Speech(this._client), this.transcriptions = new transcriptions_Transcriptions(this._client);
3953
+ }
3954
+ }
3955
+ // Common types (not exported)
3956
+ // Keep all existing exports but use the base types where applicable
3957
+ var types_WebsocketsEventType = /*#__PURE__*/ function(WebsocketsEventType) {
3958
+ // Common
3959
+ /** SDK error */ WebsocketsEventType["CLIENT_ERROR"] = "client_error";
3960
+ /** Connection closed */ WebsocketsEventType["CLOSED"] = "closed";
3961
+ // Error
3962
+ /** Received error event */ WebsocketsEventType["ERROR"] = "error";
3963
+ // v1/audio/speech
3964
+ /** Send text to server */ WebsocketsEventType["INPUT_TEXT_BUFFER_APPEND"] = "input_text_buffer.append";
3965
+ /** No text to send, after audio all received, can close connection */ WebsocketsEventType["INPUT_TEXT_BUFFER_COMPLETE"] = "input_text_buffer.complete";
3966
+ /** Send speech config to server */ WebsocketsEventType["SPEECH_UPDATE"] = "speech.update";
3967
+ /** Received `speech.updated` event */ WebsocketsEventType["SPEECH_UPDATED"] = "speech.updated";
3968
+ /** After speech created */ WebsocketsEventType["SPEECH_CREATED"] = "speech.created";
3969
+ /** Received `input_text_buffer.complete` event */ WebsocketsEventType["INPUT_TEXT_BUFFER_COMPLETED"] = "input_text_buffer.completed";
3970
+ /** Received `speech.update` event */ WebsocketsEventType["SPEECH_AUDIO_UPDATE"] = "speech.audio.update";
3971
+ /** All audio received, can close connection */ WebsocketsEventType["SPEECH_AUDIO_COMPLETED"] = "speech.audio.completed";
3972
+ // v1/audio/transcriptions
3973
+ /** Send audio to server */ WebsocketsEventType["INPUT_AUDIO_BUFFER_APPEND"] = "input_audio_buffer.append";
3974
+ /** No audio to send, after text all received, can close connection */ WebsocketsEventType["INPUT_AUDIO_BUFFER_COMPLETE"] = "input_audio_buffer.complete";
3975
+ /** Send transcriptions config to server */ WebsocketsEventType["TRANSCRIPTIONS_UPDATE"] = "transcriptions.update";
3976
+ /** Send `input_audio_buffer.clear` event */ WebsocketsEventType["INPUT_AUDIO_BUFFER_CLEAR"] = "input_audio_buffer.clear";
3977
+ /** After transcriptions created */ WebsocketsEventType["TRANSCRIPTIONS_CREATED"] = "transcriptions.created";
3978
+ /** Received `input_audio_buffer.complete` event */ WebsocketsEventType["INPUT_AUDIO_BUFFER_COMPLETED"] = "input_audio_buffer.completed";
3979
+ /** Received `transcriptions.update` event */ WebsocketsEventType["TRANSCRIPTIONS_MESSAGE_UPDATE"] = "transcriptions.message.update";
3980
+ /** All audio received, can close connection */ WebsocketsEventType["TRANSCRIPTIONS_MESSAGE_COMPLETED"] = "transcriptions.message.completed";
3981
+ /** Received `input_audio_buffer.cleared` event */ WebsocketsEventType["INPUT_AUDIO_BUFFER_CLEARED"] = "input_audio_buffer.cleared";
3982
+ /** Received `transcriptions.updated` event */ WebsocketsEventType["TRANSCRIPTIONS_UPDATED"] = "transcriptions.updated";
3983
+ // v1/chat
3984
+ /** Send chat config to server */ WebsocketsEventType["CHAT_UPDATE"] = "chat.update";
3985
+ /** Send tool outputs to server */ WebsocketsEventType["CONVERSATION_CHAT_SUBMIT_TOOL_OUTPUTS"] = "conversation.chat.submit_tool_outputs";
3986
+ /** After chat created */ WebsocketsEventType["CHAT_CREATED"] = "chat.created";
3987
+ /** After chat updated */ WebsocketsEventType["CHAT_UPDATED"] = "chat.updated";
3988
+ /** Audio AST completed, chat started */ WebsocketsEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
3989
+ /** Message created */ WebsocketsEventType["CONVERSATION_MESSAGE_CREATE"] = "conversation.message.create";
3990
+ /** Clear conversation */ WebsocketsEventType["CONVERSATION_CLEAR"] = "conversation.clear";
3991
+ /** Chat in progress */ WebsocketsEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
3992
+ /** Get agent text message update */ WebsocketsEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
3993
+ /** Need plugin submit */ WebsocketsEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
3994
+ /** Message completed */ WebsocketsEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
3995
+ /** Get agent audio message update */ WebsocketsEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
3996
+ /** Audio message completed */ WebsocketsEventType["CONVERSATION_AUDIO_COMPLETED"] = "conversation.audio.completed";
3997
+ /** All message received, can close connection */ WebsocketsEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
3998
+ /** Chat failed */ WebsocketsEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
3999
+ /** Received `conversation.cleared` event */ WebsocketsEventType["CONVERSATION_CLEARED"] = "conversation.cleared";
4000
+ return WebsocketsEventType;
4001
+ }({});
4002
+ class Websockets extends APIResource {
4003
+ constructor(...args){
4004
+ super(...args), this.audio = new websockets_audio_Audio(this._client), this.chat = new chat_Chat(this._client);
4005
+ }
4006
+ }
4007
+ // EXTERNAL MODULE: ../../common/temp/default/node_modules/.pnpm/ws@8.18.0/node_modules/ws/browser.js
4008
+ var ws_browser = __webpack_require__("../../common/temp/default/node_modules/.pnpm/ws@8.18.0/node_modules/ws/browser.js");
4009
+ var browser_default = /*#__PURE__*/ __webpack_require__.n(ws_browser);
4010
+ /*! *****************************************************************************
4011
+ Copyright (c) Microsoft Corporation. All rights reserved.
4012
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4013
+ this file except in compliance with the License. You may obtain a copy of the
4014
+ License at http://www.apache.org/licenses/LICENSE-2.0
4015
+
4016
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
4017
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
4018
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
4019
+ MERCHANTABLITY OR NON-INFRINGEMENT.
4020
+
4021
+ See the Apache Version 2.0 License for specific language governing permissions
4022
+ and limitations under the License.
4023
+ ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) {
4024
+ extendStatics = Object.setPrototypeOf || ({
4025
+ __proto__: []
4026
+ }) instanceof Array && function(d, b) {
4027
+ d.__proto__ = b;
4028
+ } || function(d, b) {
4029
+ for(var p in b)if (b.hasOwnProperty(p)) d[p] = b[p];
4030
+ };
4031
+ return extendStatics(d, b);
4032
+ };
4033
+ function __extends(d, b) {
4034
+ extendStatics(d, b);
4035
+ function __() {
4036
+ this.constructor = d;
4037
+ }
4038
+ d.prototype = null === b ? Object.create(b) : (__.prototype = b.prototype, new __());
4039
+ }
4040
+ function __values(o) {
4041
+ var m = "function" == typeof Symbol && o[Symbol.iterator], i = 0;
4042
+ if (m) return m.call(o);
4043
+ return {
4044
+ next: function() {
4045
+ if (o && i >= o.length) o = void 0;
4046
+ return {
4047
+ value: o && o[i++],
4048
+ done: !o
4049
+ };
4050
+ }
4051
+ };
4052
+ }
4053
+ function __read(o, n) {
4054
+ var m = "function" == typeof Symbol && o[Symbol.iterator];
4055
+ if (!m) return o;
4056
+ var i = m.call(o), r, ar = [], e;
4057
+ try {
4058
+ while((void 0 === n || n-- > 0) && !(r = i.next()).done)ar.push(r.value);
4059
+ } catch (error) {
4060
+ e = {
4061
+ error: error
4062
+ };
4063
+ } finally{
4064
+ try {
4065
+ if (r && !r.done && (m = i["return"])) m.call(i);
4066
+ } finally{
4067
+ if (e) throw e.error;
4068
+ }
4069
+ }
4070
+ return ar;
4071
+ }
4072
+ function __spread() {
4073
+ for(var ar = [], i = 0; i < arguments.length; i++)ar = ar.concat(__read(arguments[i]));
4074
+ return ar;
4075
+ }
4076
+ var reconnecting_websocket_mjs_Event = /** @class */ function() {
4077
+ function Event1(type, target) {
4078
+ this.target = target;
4079
+ this.type = type;
4080
+ }
4081
+ return Event1;
4082
+ }();
4083
+ var reconnecting_websocket_mjs_ErrorEvent = /** @class */ function(_super) {
4084
+ __extends(ErrorEvent, _super);
4085
+ function ErrorEvent(error, target) {
4086
+ var _this = _super.call(this, 'error', target) || this;
4087
+ _this.message = error.message;
4088
+ _this.error = error;
4089
+ return _this;
4090
+ }
4091
+ return ErrorEvent;
4092
+ }(reconnecting_websocket_mjs_Event);
4093
+ var reconnecting_websocket_mjs_CloseEvent = /** @class */ function(_super) {
4094
+ __extends(CloseEvent, _super);
4095
+ function CloseEvent(code, reason, target) {
4096
+ if (void 0 === code) code = 1000;
4097
+ if (void 0 === reason) reason = '';
4098
+ var _this = _super.call(this, 'close', target) || this;
4099
+ _this.wasClean = true;
4100
+ _this.code = code;
4101
+ _this.reason = reason;
4102
+ return _this;
4103
+ }
4104
+ return CloseEvent;
4105
+ }(reconnecting_websocket_mjs_Event);
4106
+ /*!
4107
+ * Reconnecting WebSocket
4108
+ * by Pedro Ladaria <pedro.ladaria@gmail.com>
4109
+ * https://github.com/pladaria/reconnecting-websocket
4110
+ * License MIT
4111
+ */ var getGlobalWebSocket = function() {
4112
+ if ('undefined' != typeof WebSocket) // @ts-ignore
4113
+ return WebSocket;
4114
+ };
4115
+ /**
4116
+ * Returns true if given argument looks like a WebSocket class
4117
+ */ var isWebSocket = function(w) {
4118
+ return void 0 !== w && !!w && 2 === w.CLOSING;
4119
+ };
4120
+ var DEFAULT = {
4121
+ maxReconnectionDelay: 10000,
4122
+ minReconnectionDelay: 1000 + 4000 * Math.random(),
4123
+ minUptime: 5000,
4124
+ reconnectionDelayGrowFactor: 1.3,
4125
+ connectionTimeout: 4000,
4126
+ maxRetries: 1 / 0,
4127
+ maxEnqueuedMessages: 1 / 0,
4128
+ startClosed: false,
4129
+ debug: false
4130
+ };
4131
+ var reconnecting_websocket_mjs_ReconnectingWebSocket = /** @class */ function() {
4132
+ function ReconnectingWebSocket(url, protocols, options) {
4133
+ var _this = this;
4134
+ if (void 0 === options) options = {};
4135
+ this._listeners = {
4136
+ error: [],
4137
+ message: [],
4138
+ open: [],
4139
+ close: []
4140
+ };
4141
+ this._retryCount = -1;
4142
+ this._shouldReconnect = true;
4143
+ this._connectLock = false;
4144
+ this._binaryType = 'blob';
4145
+ this._closeCalled = false;
4146
+ this._messageQueue = [];
4147
+ /**
4148
+ * An event listener to be called when the WebSocket connection's readyState changes to CLOSED
4149
+ */ this.onclose = null;
4150
+ /**
4151
+ * An event listener to be called when an error occurs
4152
+ */ this.onerror = null;
4153
+ /**
4154
+ * An event listener to be called when a message is received from the server
4155
+ */ this.onmessage = null;
4156
+ /**
4157
+ * An event listener to be called when the WebSocket connection's readyState changes to OPEN;
4158
+ * this indicates that the connection is ready to send and receive data
4159
+ */ this.onopen = null;
4160
+ this._handleOpen = function(event) {
4161
+ _this._debug('open event');
4162
+ var _a = _this._options.minUptime, minUptime = void 0 === _a ? DEFAULT.minUptime : _a;
4163
+ clearTimeout(_this._connectTimeout);
4164
+ _this._uptimeTimeout = setTimeout(function() {
4165
+ return _this._acceptOpen();
4166
+ }, minUptime);
4167
+ _this._ws.binaryType = _this._binaryType;
4168
+ // send enqueued messages (messages sent before websocket open event)
4169
+ _this._messageQueue.forEach(function(message) {
4170
+ return _this._ws.send(message);
4171
+ });
4172
+ _this._messageQueue = [];
4173
+ if (_this.onopen) _this.onopen(event);
4174
+ _this._listeners.open.forEach(function(listener) {
4175
+ return _this._callEventListener(event, listener);
4176
+ });
4177
+ };
4178
+ this._handleMessage = function(event) {
4179
+ _this._debug('message event');
4180
+ if (_this.onmessage) _this.onmessage(event);
4181
+ _this._listeners.message.forEach(function(listener) {
4182
+ return _this._callEventListener(event, listener);
4183
+ });
4184
+ };
4185
+ this._handleError = function(event) {
4186
+ _this._debug('error event', event.message);
4187
+ _this._disconnect(void 0, 'TIMEOUT' === event.message ? 'timeout' : void 0);
4188
+ if (_this.onerror) _this.onerror(event);
4189
+ _this._debug('exec error listeners');
4190
+ _this._listeners.error.forEach(function(listener) {
4191
+ return _this._callEventListener(event, listener);
4192
+ });
4193
+ _this._connect();
4194
+ };
4195
+ this._handleClose = function(event) {
4196
+ _this._debug('close event');
4197
+ _this._clearTimeouts();
4198
+ if (_this._shouldReconnect) _this._connect();
4199
+ if (_this.onclose) _this.onclose(event);
4200
+ _this._listeners.close.forEach(function(listener) {
4201
+ return _this._callEventListener(event, listener);
4202
+ });
4203
+ };
4204
+ this._url = url;
4205
+ this._protocols = protocols;
4206
+ this._options = options;
4207
+ if (this._options.startClosed) this._shouldReconnect = false;
4208
+ this._connect();
4209
+ }
4210
+ Object.defineProperty(ReconnectingWebSocket, "CONNECTING", {
4211
+ get: function() {
4212
+ return 0;
4213
+ },
4214
+ enumerable: true,
4215
+ configurable: true
4216
+ });
4217
+ Object.defineProperty(ReconnectingWebSocket, "OPEN", {
4218
+ get: function() {
4219
+ return 1;
4220
+ },
4221
+ enumerable: true,
4222
+ configurable: true
4223
+ });
4224
+ Object.defineProperty(ReconnectingWebSocket, "CLOSING", {
4225
+ get: function() {
4226
+ return 2;
4227
+ },
4228
+ enumerable: true,
4229
+ configurable: true
4230
+ });
4231
+ Object.defineProperty(ReconnectingWebSocket, "CLOSED", {
4232
+ get: function() {
4233
+ return 3;
4234
+ },
4235
+ enumerable: true,
4236
+ configurable: true
4237
+ });
4238
+ Object.defineProperty(ReconnectingWebSocket.prototype, "CONNECTING", {
4239
+ get: function() {
4240
+ return ReconnectingWebSocket.CONNECTING;
4241
+ },
4242
+ enumerable: true,
4243
+ configurable: true
4244
+ });
4245
+ Object.defineProperty(ReconnectingWebSocket.prototype, "OPEN", {
4246
+ get: function() {
4247
+ return ReconnectingWebSocket.OPEN;
4248
+ },
4249
+ enumerable: true,
4250
+ configurable: true
4251
+ });
4252
+ Object.defineProperty(ReconnectingWebSocket.prototype, "CLOSING", {
4253
+ get: function() {
4254
+ return ReconnectingWebSocket.CLOSING;
4255
+ },
4256
+ enumerable: true,
4257
+ configurable: true
4258
+ });
4259
+ Object.defineProperty(ReconnectingWebSocket.prototype, "CLOSED", {
4260
+ get: function() {
4261
+ return ReconnectingWebSocket.CLOSED;
4262
+ },
4263
+ enumerable: true,
4264
+ configurable: true
4265
+ });
4266
+ Object.defineProperty(ReconnectingWebSocket.prototype, "binaryType", {
4267
+ get: function() {
4268
+ return this._ws ? this._ws.binaryType : this._binaryType;
4269
+ },
4270
+ set: function(value) {
4271
+ this._binaryType = value;
4272
+ if (this._ws) this._ws.binaryType = value;
4273
+ },
4274
+ enumerable: true,
4275
+ configurable: true
4276
+ });
4277
+ Object.defineProperty(ReconnectingWebSocket.prototype, "retryCount", {
4278
+ /**
4279
+ * Returns the number or connection retries
4280
+ */ get: function() {
4281
+ return Math.max(this._retryCount, 0);
4282
+ },
4283
+ enumerable: true,
4284
+ configurable: true
4285
+ });
4286
+ Object.defineProperty(ReconnectingWebSocket.prototype, "bufferedAmount", {
4287
+ /**
4288
+ * The number of bytes of data that have been queued using calls to send() but not yet
4289
+ * transmitted to the network. This value resets to zero once all queued data has been sent.
4290
+ * This value does not reset to zero when the connection is closed; if you keep calling send(),
4291
+ * this will continue to climb. Read only
4292
+ */ get: function() {
4293
+ var bytes = this._messageQueue.reduce(function(acc, message) {
4294
+ if ('string' == typeof message) acc += message.length; // not byte size
4295
+ else if (message instanceof Blob) acc += message.size;
4296
+ else acc += message.byteLength;
4297
+ return acc;
4298
+ }, 0);
4299
+ return bytes + (this._ws ? this._ws.bufferedAmount : 0);
4300
+ },
4301
+ enumerable: true,
4302
+ configurable: true
4303
+ });
4304
+ Object.defineProperty(ReconnectingWebSocket.prototype, "extensions", {
4305
+ /**
4306
+ * The extensions selected by the server. This is currently only the empty string or a list of
4307
+ * extensions as negotiated by the connection
4308
+ */ get: function() {
4309
+ return this._ws ? this._ws.extensions : '';
4310
+ },
4311
+ enumerable: true,
4312
+ configurable: true
4313
+ });
4314
+ Object.defineProperty(ReconnectingWebSocket.prototype, "protocol", {
4315
+ /**
4316
+ * A string indicating the name of the sub-protocol the server selected;
4317
+ * this will be one of the strings specified in the protocols parameter when creating the
4318
+ * WebSocket object
4319
+ */ get: function() {
4320
+ return this._ws ? this._ws.protocol : '';
4321
+ },
4322
+ enumerable: true,
4323
+ configurable: true
4324
+ });
4325
+ Object.defineProperty(ReconnectingWebSocket.prototype, "readyState", {
4326
+ /**
4327
+ * The current state of the connection; this is one of the Ready state constants
4328
+ */ get: function() {
4329
+ if (this._ws) return this._ws.readyState;
4330
+ return this._options.startClosed ? ReconnectingWebSocket.CLOSED : ReconnectingWebSocket.CONNECTING;
4331
+ },
4332
+ enumerable: true,
4333
+ configurable: true
4334
+ });
4335
+ Object.defineProperty(ReconnectingWebSocket.prototype, "url", {
4336
+ /**
4337
+ * The URL as resolved by the constructor
4338
+ */ get: function() {
4339
+ return this._ws ? this._ws.url : '';
4340
+ },
4341
+ enumerable: true,
4342
+ configurable: true
4343
+ });
4344
+ /**
4345
+ * Closes the WebSocket connection or connection attempt, if any. If the connection is already
4346
+ * CLOSED, this method does nothing
4347
+ */ ReconnectingWebSocket.prototype.close = function(code, reason) {
4348
+ if (void 0 === code) code = 1000;
4349
+ this._closeCalled = true;
4350
+ this._shouldReconnect = false;
4351
+ this._clearTimeouts();
4352
+ if (!this._ws) {
4353
+ this._debug('close enqueued: no ws instance');
4354
+ return;
4355
+ }
4356
+ if (this._ws.readyState === this.CLOSED) {
4357
+ this._debug('close: already closed');
4358
+ return;
4359
+ }
4360
+ this._ws.close(code, reason);
4361
+ };
4362
+ /**
4363
+ * Closes the WebSocket connection or connection attempt and connects again.
4364
+ * Resets retry counter;
4365
+ */ ReconnectingWebSocket.prototype.reconnect = function(code, reason) {
4366
+ this._shouldReconnect = true;
4367
+ this._closeCalled = false;
4368
+ this._retryCount = -1;
4369
+ if (this._ws && this._ws.readyState !== this.CLOSED) {
4370
+ this._disconnect(code, reason);
4371
+ this._connect();
4372
+ } else this._connect();
4373
+ };
4374
+ /**
4375
+ * Enqueue specified data to be transmitted to the server over the WebSocket connection
4376
+ */ ReconnectingWebSocket.prototype.send = function(data) {
4377
+ if (this._ws && this._ws.readyState === this.OPEN) {
4378
+ this._debug('send', data);
4379
+ this._ws.send(data);
4380
+ } else {
4381
+ var _a = this._options.maxEnqueuedMessages, maxEnqueuedMessages = void 0 === _a ? DEFAULT.maxEnqueuedMessages : _a;
4382
+ if (this._messageQueue.length < maxEnqueuedMessages) {
4383
+ this._debug('enqueue', data);
4384
+ this._messageQueue.push(data);
4385
+ }
4386
+ }
4387
+ };
4388
+ /**
4389
+ * Register an event handler of a specific event type
4390
+ */ ReconnectingWebSocket.prototype.addEventListener = function(type, listener) {
4391
+ if (this._listeners[type]) // @ts-ignore
4392
+ this._listeners[type].push(listener);
4393
+ };
4394
+ ReconnectingWebSocket.prototype.dispatchEvent = function(event) {
4395
+ var e_1, _a;
4396
+ var listeners = this._listeners[event.type];
4397
+ if (listeners) try {
4398
+ for(var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()){
4399
+ var listener = listeners_1_1.value;
4400
+ this._callEventListener(event, listener);
4401
+ }
4402
+ } catch (e_1_1) {
4403
+ e_1 = {
4404
+ error: e_1_1
4405
+ };
4406
+ } finally{
4407
+ try {
4408
+ if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1);
4409
+ } finally{
4410
+ if (e_1) throw e_1.error;
4411
+ }
4412
+ }
4413
+ return true;
4414
+ };
4415
+ /**
4416
+ * Removes an event listener
4417
+ */ ReconnectingWebSocket.prototype.removeEventListener = function(type, listener) {
4418
+ if (this._listeners[type]) // @ts-ignore
4419
+ this._listeners[type] = this._listeners[type].filter(function(l) {
4420
+ return l !== listener;
4421
+ });
4422
+ };
4423
+ ReconnectingWebSocket.prototype._debug = function() {
4424
+ var args = [];
4425
+ for(var _i = 0; _i < arguments.length; _i++)args[_i] = arguments[_i];
4426
+ if (this._options.debug) // not using spread because compiled version uses Symbols
4427
+ // tslint:disable-next-line
4428
+ console.log.apply(console, __spread([
4429
+ 'RWS>'
4430
+ ], args));
4431
+ };
4432
+ ReconnectingWebSocket.prototype._getNextDelay = function() {
4433
+ var _a = this._options, _b = _a.reconnectionDelayGrowFactor, reconnectionDelayGrowFactor = void 0 === _b ? DEFAULT.reconnectionDelayGrowFactor : _b, _c = _a.minReconnectionDelay, minReconnectionDelay = void 0 === _c ? DEFAULT.minReconnectionDelay : _c, _d = _a.maxReconnectionDelay, maxReconnectionDelay = void 0 === _d ? DEFAULT.maxReconnectionDelay : _d;
4434
+ var delay = 0;
4435
+ if (this._retryCount > 0) {
4436
+ delay = minReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, this._retryCount - 1);
4437
+ if (delay > maxReconnectionDelay) delay = maxReconnectionDelay;
4438
+ }
4439
+ this._debug('next delay', delay);
4440
+ return delay;
4441
+ };
4442
+ ReconnectingWebSocket.prototype._wait = function() {
4443
+ var _this = this;
4444
+ return new Promise(function(resolve) {
4445
+ setTimeout(resolve, _this._getNextDelay());
4446
+ });
4447
+ };
4448
+ ReconnectingWebSocket.prototype._getNextUrl = function(urlProvider) {
4449
+ if ('string' == typeof urlProvider) return Promise.resolve(urlProvider);
4450
+ if ('function' == typeof urlProvider) {
4451
+ var url = urlProvider();
4452
+ if ('string' == typeof url) return Promise.resolve(url);
4453
+ if (!!url.then) return url;
4454
+ }
4455
+ throw Error('Invalid URL');
4456
+ };
4457
+ ReconnectingWebSocket.prototype._connect = function() {
4458
+ var _this = this;
4459
+ if (this._connectLock || !this._shouldReconnect) return;
4460
+ this._connectLock = true;
4461
+ var _a = this._options, _b = _a.maxRetries, maxRetries = void 0 === _b ? DEFAULT.maxRetries : _b, _c = _a.connectionTimeout, connectionTimeout = void 0 === _c ? DEFAULT.connectionTimeout : _c, _d = _a.WebSocket, WebSocket1 = void 0 === _d ? getGlobalWebSocket() : _d;
4462
+ if (this._retryCount >= maxRetries) {
4463
+ this._debug('max retries reached', this._retryCount, '>=', maxRetries);
4464
+ return;
4465
+ }
4466
+ this._retryCount++;
4467
+ this._debug('connect', this._retryCount);
4468
+ this._removeListeners();
4469
+ if (!isWebSocket(WebSocket1)) throw Error('No valid WebSocket class provided');
4470
+ this._wait().then(function() {
4471
+ return _this._getNextUrl(_this._url);
4472
+ }).then(function(url) {
4473
+ // close could be called before creating the ws
4474
+ if (_this._closeCalled) return;
4475
+ _this._debug('connect', {
4476
+ url: url,
4477
+ protocols: _this._protocols
4478
+ });
4479
+ _this._ws = _this._protocols ? new WebSocket1(url, _this._protocols) : new WebSocket1(url);
4480
+ _this._ws.binaryType = _this._binaryType;
4481
+ _this._connectLock = false;
4482
+ _this._addListeners();
4483
+ _this._connectTimeout = setTimeout(function() {
4484
+ return _this._handleTimeout();
4485
+ }, connectionTimeout);
4486
+ });
4487
+ };
4488
+ ReconnectingWebSocket.prototype._handleTimeout = function() {
4489
+ this._debug('timeout event');
4490
+ this._handleError(new reconnecting_websocket_mjs_ErrorEvent(Error('TIMEOUT'), this));
4491
+ };
4492
+ ReconnectingWebSocket.prototype._disconnect = function(code, reason) {
4493
+ if (void 0 === code) code = 1000;
4494
+ this._clearTimeouts();
4495
+ if (!this._ws) return;
4496
+ this._removeListeners();
4497
+ try {
4498
+ this._ws.close(code, reason);
4499
+ this._handleClose(new reconnecting_websocket_mjs_CloseEvent(code, reason, this));
4500
+ } catch (error) {
4501
+ // ignore
4502
+ }
4503
+ };
4504
+ ReconnectingWebSocket.prototype._acceptOpen = function() {
4505
+ this._debug('accept open');
4506
+ this._retryCount = 0;
4507
+ };
4508
+ ReconnectingWebSocket.prototype._callEventListener = function(event, listener) {
4509
+ if ('handleEvent' in listener) // @ts-ignore
4510
+ listener.handleEvent(event);
4511
+ else // @ts-ignore
4512
+ listener(event);
4513
+ };
4514
+ ReconnectingWebSocket.prototype._removeListeners = function() {
4515
+ if (!this._ws) return;
4516
+ this._debug('removeListeners');
4517
+ this._ws.removeEventListener('open', this._handleOpen);
4518
+ this._ws.removeEventListener('close', this._handleClose);
4519
+ this._ws.removeEventListener('message', this._handleMessage);
4520
+ // @ts-ignore
4521
+ this._ws.removeEventListener('error', this._handleError);
4522
+ };
4523
+ ReconnectingWebSocket.prototype._addListeners = function() {
4524
+ if (!this._ws) return;
4525
+ this._debug('addListeners');
4526
+ this._ws.addEventListener('open', this._handleOpen);
4527
+ this._ws.addEventListener('close', this._handleClose);
4528
+ this._ws.addEventListener('message', this._handleMessage);
4529
+ // @ts-ignore
4530
+ this._ws.addEventListener('error', this._handleError);
4531
+ };
4532
+ ReconnectingWebSocket.prototype._clearTimeouts = function() {
4533
+ clearTimeout(this._connectTimeout);
4534
+ clearTimeout(this._uptimeTimeout);
4535
+ };
4536
+ return ReconnectingWebSocket;
4537
+ }();
4538
+ /* ESM default export */ const reconnecting_websocket_mjs = reconnecting_websocket_mjs_ReconnectingWebSocket;
4539
+ class WebSocketAPI {
4540
+ // Standard WebSocket properties
4541
+ get readyState() {
4542
+ return this.rws.readyState;
4543
+ }
4544
+ // Standard WebSocket methods
4545
+ send(data) {
4546
+ return this.rws.send(JSON.stringify(data));
4547
+ }
4548
+ close(code, reason) {
4549
+ return this.rws.close(code, reason);
4550
+ }
4551
+ reconnect(code, reason) {
4552
+ return this.rws.reconnect(code, reason);
4553
+ }
4554
+ // Event listener methods
4555
+ addEventListener(type, listener) {
4556
+ this.rws.addEventListener(type, listener);
4557
+ }
4558
+ removeEventListener(type, listener) {
4559
+ this.rws.removeEventListener(type, listener);
4560
+ }
4561
+ constructor(url, options = {}){
4562
+ // Event handler methods
4563
+ this.onmessage = null;
4564
+ this.onopen = null;
4565
+ this.onclose = null;
4566
+ this.onerror = null;
4567
+ const separator = url.includes('?') ? '&' : '?';
4568
+ const { authorization } = options.headers || {};
4569
+ this.rws = new reconnecting_websocket_mjs(`${url}${separator}authorization=${authorization}`, [], {
4570
+ WebSocket: utils_isBrowser() ? window.WebSocket : class extends browser_default() {
4571
+ constructor(url2, protocols){
4572
+ super(url2, protocols, {
4573
+ headers: options.headers
4574
+ });
4575
+ }
4576
+ },
4577
+ ...options
4578
+ });
4579
+ this.rws.addEventListener('message', (event)=>{
4580
+ try {
4581
+ var _this_onmessage, _this;
4582
+ const data = JSON.parse(event.data);
4583
+ null === (_this_onmessage = (_this = this).onmessage) || void 0 === _this_onmessage || _this_onmessage.call(_this, data, event);
4584
+ } catch (error) {
4585
+ console.error('WebSocketAPI onmessage error', error);
4586
+ }
4587
+ });
4588
+ this.rws.addEventListener('open', (event)=>{
4589
+ var _this_onopen, _this;
4590
+ null === (_this_onopen = (_this = this).onopen) || void 0 === _this_onopen || _this_onopen.call(_this, event);
4591
+ });
4592
+ this.rws.addEventListener('close', (event)=>{
4593
+ var _this_onclose, _this;
4594
+ null === (_this_onclose = (_this = this).onclose) || void 0 === _this_onclose || _this_onclose.call(_this, event);
4595
+ });
4596
+ this.rws.addEventListener('error', (event)=>{
4597
+ var _event_target__req_res, _event_target__req, _event_target, _event_target__req_res1, _event_target__req1, _event_target1, _this_onerror, _this;
4598
+ const statusCode = null === (_event_target = event.target) || void 0 === _event_target ? void 0 : null === (_event_target__req = _event_target._req) || void 0 === _event_target__req ? void 0 : null === (_event_target__req_res = _event_target__req.res) || void 0 === _event_target__req_res ? void 0 : _event_target__req_res.statusCode;
4599
+ const rawHeaders = (null === (_event_target1 = event.target) || void 0 === _event_target1 ? void 0 : null === (_event_target__req1 = _event_target1._req) || void 0 === _event_target__req1 ? void 0 : null === (_event_target__req_res1 = _event_target__req1.res) || void 0 === _event_target__req_res1 ? void 0 : _event_target__req_res1.rawHeaders) || [];
4600
+ const logidIndex = rawHeaders.findIndex((header)=>'X-Tt-Logid' === header);
4601
+ const logid = -1 !== logidIndex ? rawHeaders[logidIndex + 1] : void 0;
4602
+ const error = {
4603
+ id: '0',
4604
+ event_type: types_WebsocketsEventType.ERROR,
4605
+ data: {
4606
+ code: -1,
4607
+ msg: 'WebSocket error'
4608
+ },
4609
+ detail: {
4610
+ logid
4611
+ }
4612
+ };
4613
+ if (401 === statusCode) {
4614
+ error.data.code = 401;
4615
+ error.data.msg = 'Unauthorized';
4616
+ } else if (403 === statusCode) {
4617
+ error.data.code = 403;
4618
+ error.data.msg = 'Forbidden';
4619
+ } else {
4620
+ error.data.code = 500;
4621
+ error.data.msg = String(null == event ? void 0 : event.error) || 'WebSocket error';
4622
+ }
4623
+ null === (_this_onerror = (_this = this).onerror) || void 0 === _this_onerror || _this_onerror.call(_this, error, event);
4624
+ });
4625
+ }
4626
+ }
3917
4627
  // EXTERNAL MODULE: os (ignored)
3918
4628
  var os_ignored_ = __webpack_require__("?9050");
3919
4629
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
3920
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","exports":{".":"./src/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
4630
+ var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.21-beta.2","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","exports":{".":"./src/index.ts","./ws-tools":"./src/ws-tools/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false,"node-fetch":false},"typesVersions":{"*":{".":["dist/types/index.d.ts"],"ws-tools":["dist/types/ws-tools/ws-tools/index.d.ts"]}},"files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2","node-fetch":"^2.x","reconnecting-websocket":"^4.4.0","uuid":"^10.0.0","ws":"^8.11.0"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/node-fetch":"^2.x","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@types/ws":"^8.5.1","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"},"./ws-tools":{"require":"./dist/cjs/ws-tools/index.cjs","import":"./dist/esm/ws-tools/index.js","types":"./dist/types/ws-tools/ws-tools/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
3921
4631
  const { version: version_version } = package_namespaceObject;
3922
4632
  const getEnv = ()=>{
3923
4633
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -4016,6 +4726,9 @@ const getBrowserClientUserAgent = ()=>{
4016
4726
  };
4017
4727
  return JSON.stringify(ua);
4018
4728
  };
4729
+ // EXTERNAL MODULE: node-fetch (ignored)
4730
+ var node_fetch_ignored_ = __webpack_require__("?8dee");
4731
+ var node_fetch_ignored_default = /*#__PURE__*/ __webpack_require__.n(node_fetch_ignored_);
4019
4732
  /* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
4020
4733
  if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
4021
4734
  if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
@@ -4028,6 +4741,23 @@ const getBrowserClientUserAgent = ()=>{
4028
4741
  return error_APIError.generate((null === (_error_response1 = error.response) || void 0 === _error_response1 ? void 0 : _error_response1.status) || 500, null === (_error_response2 = error.response) || void 0 === _error_response2 ? void 0 : _error_response2.data, error.message, null === (_error_response3 = error.response) || void 0 === _error_response3 ? void 0 : _error_response3.headers);
4029
4742
  }
4030
4743
  };
4744
+ // node-fetch is used for streaming requests
4745
+ const adapterFetch = async (options)=>{
4746
+ const response = await node_fetch_ignored_default()(options.url, {
4747
+ body: options.data,
4748
+ ...options
4749
+ });
4750
+ return {
4751
+ data: response.body,
4752
+ ...response
4753
+ };
4754
+ };
4755
+ const isSupportNativeFetch = ()=>{
4756
+ if (utils_isBrowser()) return true;
4757
+ // native fetch is supported in node 18.0.0 or higher
4758
+ const version = process.version.slice(1);
4759
+ return compareVersions(version, '18.0.0') >= 0;
4760
+ };
4031
4761
  async function fetchAPI(url) {
4032
4762
  let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
4033
4763
  const axiosInstance = options.axiosInstance || lib_axios;
@@ -4039,7 +4769,7 @@ async function fetchAPI(url) {
4039
4769
  const response = await axiosInstance({
4040
4770
  url,
4041
4771
  responseType: options.isStreaming ? 'stream' : 'json',
4042
- adapter: options.isStreaming ? 'fetch' : void 0,
4772
+ adapter: options.isStreaming ? isSupportNativeFetch() ? 'fetch' : adapterFetch : void 0,
4043
4773
  ...options
4044
4774
  }).catch((error)=>{
4045
4775
  throw fetcher_handleError(error);
@@ -4105,6 +4835,9 @@ function isAxiosStatic(instance) {
4105
4835
  /**
4106
4836
  * default coze base URL is api.coze.com
4107
4837
  */ const constant_COZE_COM_BASE_URL = 'https://api.coze.com';
4838
+ /**
4839
+ * default base websocket URL is wss://ws.coze.com
4840
+ */ const COZE_COM_BASE_WS_URL = 'wss://ws.coze.com';
4108
4841
  /* eslint-disable max-params */ class core_APIClient {
4109
4842
  async getToken() {
4110
4843
  if ('function' == typeof this.token) return await this.token();
@@ -4129,6 +4862,26 @@ function isAxiosStatic(instance) {
4129
4862
  config.data = body;
4130
4863
  return config;
4131
4864
  }
4865
+ async buildWebsocketOptions(options) {
4866
+ const token = await this.getToken();
4867
+ const headers = {
4868
+ authorization: `Bearer ${token}`
4869
+ };
4870
+ if (utils_isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
4871
+ else {
4872
+ headers['User-Agent'] = getUserAgent();
4873
+ headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
4874
+ }
4875
+ var _this__config_debug;
4876
+ const config = mergeConfig({
4877
+ debug: null !== (_this__config_debug = this._config.debug) && void 0 !== _this__config_debug && _this__config_debug
4878
+ }, this._config.websocketOptions, options, {
4879
+ headers
4880
+ }, {
4881
+ headers: this.headers || {}
4882
+ });
4883
+ return config;
4884
+ }
4132
4885
  async makeRequest(apiUrl, method, body, isStream, options) {
4133
4886
  const fullUrl = `${this.baseURL}${apiUrl}`;
4134
4887
  const fetchOptions = await this.buildOptions(method, body, options);
@@ -4176,6 +4929,14 @@ function isAxiosStatic(instance) {
4176
4929
  async delete(apiUrl, isStream, options) {
4177
4930
  return this.makeRequest(apiUrl, 'DELETE', void 0, isStream, options);
4178
4931
  }
4932
+ async makeWebsocket(apiUrl, options) {
4933
+ const fullUrl = `${this.baseWsURL}${apiUrl}`;
4934
+ const websocketOptions = await this.buildWebsocketOptions(options);
4935
+ this.debugLog(null == options ? void 0 : options.debug, `--- websocket url: ${fullUrl}`);
4936
+ this.debugLog(null == options ? void 0 : options.debug, '--- websocket options:', websocketOptions);
4937
+ const ws = new WebSocketAPI(fullUrl, websocketOptions);
4938
+ return ws;
4939
+ }
4179
4940
  getConfig() {
4180
4941
  return this._config;
4181
4942
  }
@@ -4188,6 +4949,7 @@ function isAxiosStatic(instance) {
4188
4949
  constructor(config){
4189
4950
  this._config = config;
4190
4951
  this.baseURL = config.baseURL || constant_COZE_COM_BASE_URL;
4952
+ this.baseWsURL = config.baseWsURL || COZE_COM_BASE_WS_URL;
4191
4953
  this.token = config.token;
4192
4954
  this.axiosOptions = config.axiosOptions || {};
4193
4955
  this.axiosInstance = config.axiosInstance;
@@ -4215,7 +4977,7 @@ class CozeAPI extends core_APIClient {
4215
4977
  constructor(...args){
4216
4978
  super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
4217
4979
  * @deprecated
4218
- */ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new audio_Audio(this), this.templates = new Templates(this);
4980
+ */ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new audio_Audio(this), this.templates = new Templates(this), this.websockets = new Websockets(this);
4219
4981
  }
4220
4982
  }
4221
4983
  /**
@@ -42365,12 +43127,24 @@ class RealtimeClient extends RealtimeEventHandler {
42365
43127
  let roomInfo;
42366
43128
  try {
42367
43129
  // Step1 get token
43130
+ let config;
43131
+ if (this._config.videoConfig) config = isScreenShareDevice(this._config.videoConfig.videoInputDeviceId) ? {
43132
+ video_config: {
43133
+ stream_video_type: 'screen'
43134
+ }
43135
+ } : {
43136
+ video_config: {
43137
+ stream_video_type: 'main'
43138
+ }
43139
+ };
42368
43140
  roomInfo = await this._api.audio.rooms.create({
42369
43141
  bot_id: botId,
42370
43142
  conversation_id: conversationId || void 0,
42371
43143
  voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
42372
43144
  connector_id: this._config.connectorId,
42373
- uid: this._config.userId || void 0
43145
+ uid: this._config.userId || void 0,
43146
+ workflow_id: this._config.workflowId || void 0,
43147
+ config
42374
43148
  });
42375
43149
  } catch (error) {
42376
43150
  this.dispatch(event_handler_EventNames.ERROR, error);