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