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