@coze/realtime-api 1.0.4-beta.1 → 1.0.4-beta.2

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,4 +1,4 @@
1
- /*! For license information please see index.js.LICENSE.txt */
1
+ /*! For license information please see index.cjs.LICENSE.txt */
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
4
  "?666e": function() {
@@ -95,7 +95,7 @@ __webpack_require__.d(common_utils_namespaceObject, {
95
95
  hasBrowserEnv: ()=>hasBrowserEnv,
96
96
  hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
97
97
  hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
98
- navigator: ()=>_navigator,
98
+ navigator: ()=>utils_navigator,
99
99
  origin: ()=>origin
100
100
  });
101
101
  // NAMESPACE OBJECT: ./src/utils.ts
@@ -105,6 +105,8 @@ __webpack_require__.d(src_utils_namespaceObject, {
105
105
  checkDevicePermission: ()=>checkDevicePermission,
106
106
  checkPermission: ()=>checkPermission,
107
107
  getAudioDevices: ()=>getAudioDevices,
108
+ isScreenShareDevice: ()=>isScreenShareDevice,
109
+ isScreenShareSupported: ()=>isScreenShareSupported,
108
110
  sleep: ()=>src_utils_sleep
109
111
  });
110
112
  class APIResource {
@@ -1628,7 +1630,7 @@ class InterceptorManager_InterceptorManager {
1628
1630
  ]
1629
1631
  };
1630
1632
  const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
1631
- const _navigator = 'object' == typeof navigator && navigator || void 0;
1633
+ const utils_navigator = 'object' == typeof navigator && navigator || void 0;
1632
1634
  /**
1633
1635
  * Determine if we're running in a standard browser environment
1634
1636
  *
@@ -1645,11 +1647,11 @@ const _navigator = 'object' == typeof navigator && navigator || void 0;
1645
1647
  * navigator.product -> 'NativeScript' or 'NS'
1646
1648
  *
1647
1649
  * @returns {boolean}
1648
- */ const hasStandardBrowserEnv = hasBrowserEnv && (!_navigator || [
1650
+ */ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
1649
1651
  'ReactNative',
1650
1652
  'NativeScript',
1651
1653
  'NS'
1652
- ].indexOf(_navigator.product) < 0);
1654
+ ].indexOf(utils_navigator.product) < 0);
1653
1655
  /**
1654
1656
  * Determine if we're running in a standard browser webWorker environment
1655
1657
  *
@@ -3671,9 +3673,9 @@ class documents_Documents extends APIResource {
3671
3673
  * @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
3672
3674
  * @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
3673
3675
  * @returns ListDocumentData | 知识库文件列表
3674
- */ list(params, options) {
3676
+ */ async list(params, options) {
3675
3677
  const apiUrl = '/open_api/knowledge/document/list';
3676
- const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
3678
+ const response = await this._client.get(apiUrl, params, false, mergeConfig(options, {
3677
3679
  headers: documents_documents_headers
3678
3680
  }));
3679
3681
  return response;
@@ -3722,9 +3724,104 @@ class documents_Documents extends APIResource {
3722
3724
  }));
3723
3725
  }
3724
3726
  }
3727
+ class Images extends APIResource {
3728
+ /**
3729
+ * Update the description of an image in the knowledge base | 更新知识库中的图片描述
3730
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/update_image_caption?_lang=en
3731
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/update_image_caption?_lang=zh
3732
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3733
+ * @param documentId - The ID of the document | 必选 知识库文件 ID
3734
+ * @param params - The parameters for updating the image
3735
+ * @param params.caption - Required. The description of the image | 必选 图片的描述信息
3736
+ * @returns undefined
3737
+ */ // eslint-disable-next-line max-params
3738
+ async update(datasetId, documentId, params, options) {
3739
+ const apiUrl = `/v1/datasets/${datasetId}/images/${documentId}`;
3740
+ await this._client.put(apiUrl, params, false, options);
3741
+ }
3742
+ /**
3743
+ * List images in the knowledge base | 列出知识库中的图片
3744
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/get_images?_lang=en
3745
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/get_images?_lang=zh
3746
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3747
+ * @param params - The parameters for listing images
3748
+ * @param params.page_num - Optional. Page number for pagination, minimum value is 1, defaults to 1 | 可选 分页查询时的页码。默认为 1。
3749
+ * @param params.page_size - Optional. Number of items per page, range 1-299, defaults to 10 | 可选 分页大小。默认为 10。
3750
+ * @param params.keyword - Optional. Search keyword for image descriptions | 可选 图片描述的搜索关键词。
3751
+ * @param params.has_caption - Optional. Filter for images with/without captions | 可选 是否过滤有/无描述的图片。
3752
+ */ async list(datasetId, params, options) {
3753
+ const apiUrl = `/v1/datasets/${datasetId}/images`;
3754
+ const response = await this._client.get(apiUrl, params, false, options);
3755
+ return response.data;
3756
+ }
3757
+ }
3725
3758
  class Datasets extends APIResource {
3759
+ /**
3760
+ * Creates a new dataset | 创建数据集
3761
+ * @docs en: https://www.coze.com/docs/developer_guides/create_dataset?_lang=en
3762
+ * @docs zh: https://www.coze.cn/docs/developer_guides/create_dataset?_lang=zh
3763
+ * @param params - The parameters for creating a dataset
3764
+ * @param {string} params.name - Required. Dataset name, maximum length of 100 characters | 必选 数据集名称,最大长度为 100 个字符
3765
+ * @param {string} params.space_id - Required. Space ID where the dataset belongs | 必选 数据集所属的空间 ID
3766
+ * @param {number} params.format_type - Required. Dataset type (0: Text type, 2: Image type) | 必选 数据集类型 (0: 文本类型, 2: 图片类型)
3767
+ * @param {string} [params.description] - Optional. Dataset description | 可选 数据集描述
3768
+ * @param {string} [params.file_id] - Optional. Dataset icon file ID from file upload
3769
+ */ async create(params, options) {
3770
+ const apiUrl = '/v1/datasets';
3771
+ const response = await this._client.post(apiUrl, params, false, options);
3772
+ return response.data;
3773
+ }
3774
+ /**
3775
+ * Lists all datasets in a space | 列出空间中的所有数据集
3776
+ * @docs en: https://www.coze.com/docs/developer_guides/list_dataset?_lang=en
3777
+ * @docs zh: https://www.coze.cn/docs/developer_guides/list_dataset?_lang=zh
3778
+ * @param params - The parameters for listing datasets | 列出数据集的参数
3779
+ * @param {string} params.space_id - Required. Space ID where the datasets belong | 必选 数据集所属的空间 ID
3780
+ * @param {string} [params.name] - Optional. Dataset name for fuzzy search | 可选 数据集名称用于模糊搜索
3781
+ * @param {number} [params.format_type] - Optional. Dataset type (0: Text type, 2: Image type) | 可选 数据集类型 (0: 文本类型, 2: 图片类型)
3782
+ * @param {number} [params.page_num] - Optional. Page number for pagination (default: 1) | 可选 分页查询时的页码。默认为 1。
3783
+ * @param {number} [params.page_size] - Optional. Number of items per page (default: 10) | 可选 分页大小。默认为 10。
3784
+ */ async list(params, options) {
3785
+ const apiUrl = '/v1/datasets';
3786
+ const response = await this._client.get(apiUrl, params, false, options);
3787
+ return response.data;
3788
+ }
3789
+ /**
3790
+ * Updates a dataset | 更新数据集
3791
+ * @docs en: https://www.coze.com/docs/developer_guides/update_dataset?_lang=en
3792
+ * @docs zh: https://www.coze.cn/docs/developer_guides/update_dataset?_lang=zh
3793
+ * @param dataset_id - Required. The ID of the dataset to update | 必选 数据集 ID
3794
+ * @param params - Required. The parameters for updating the dataset | 必选 更新数据集的参数
3795
+ * @param params.name - Required. Dataset name, maximum length of 100 characters. | 必选 数据集名称,最大长度为 100 个字符。
3796
+ * @param params.file_id - Optional. Dataset icon, should pass the file_id obtained from the file upload interface. | 可选 数据集图标,应传递从文件上传接口获取的 file_id。
3797
+ * @param params.description - Optional. Dataset description. | 可选 数据集描述。
3798
+ */ async update(dataset_id, params, options) {
3799
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3800
+ await this._client.put(apiUrl, params, false, options);
3801
+ }
3802
+ /**
3803
+ * Deletes a dataset | 删除数据集
3804
+ * @docs en: https://www.coze.com/docs/developer_guides/delete_dataset?_lang=en
3805
+ * @docs zh: https://www.coze.cn/docs/developer_guides/delete_dataset?_lang=zh
3806
+ * @param dataset_id - Required. The ID of the dataset to delete | 必选 数据集 ID
3807
+ */ async delete(dataset_id, options) {
3808
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3809
+ await this._client.delete(apiUrl, false, options);
3810
+ }
3811
+ /**
3812
+ * Views the progress of dataset upload | 查看数据集上传进度
3813
+ * @docs en: https://www.coze.com/docs/developer_guides/get_dataset_progress?_lang=en
3814
+ * @docs zh: https://www.coze.cn/docs/developer_guides/get_dataset_progress?_lang=zh
3815
+ * @param dataset_id - Required. The ID of the dataset to process | 必选 数据集 ID
3816
+ * @param params - Required. The parameters for processing the dataset | 必选 处理数据集的参数
3817
+ * @param params.dataset_ids - Required. List of dataset IDs | 必选 数据集 ID 列表
3818
+ */ async process(dataset_id, params, options) {
3819
+ const apiUrl = `/v1/datasets/${dataset_id}/process`;
3820
+ const response = await this._client.post(apiUrl, params, false, options);
3821
+ return response.data;
3822
+ }
3726
3823
  constructor(...args){
3727
- super(...args), this.documents = new documents_Documents(this._client);
3824
+ super(...args), this.documents = new documents_Documents(this._client), this.images = new Images(this._client);
3728
3825
  }
3729
3826
  }
3730
3827
  class Voices extends APIResource {
@@ -3744,6 +3841,8 @@ class Voices extends APIResource {
3744
3841
  * | 如果传入会基于该文本生成预览音频,否则使用默认的文本
3745
3842
  * @param params.text - Optional. Users can read this text, service will compare audio with text. Returns error if difference is too large
3746
3843
  * | 可以让用户按照该文本念诵,服务会对比音频与该文本的差异。若差异过大会返回错误
3844
+ * @param params.space_id - Optional. The space id of the voice. | 空间ID
3845
+ * @param params.description- Optional. The description of the voice. | 音色描述
3747
3846
  * @param options - Request options
3748
3847
  * @returns Clone voice data
3749
3848
  */ async clone(params, options) {
@@ -3768,6 +3867,17 @@ class Voices extends APIResource {
3768
3867
  return response.data;
3769
3868
  }
3770
3869
  }
3870
+ class Transcriptions extends APIResource {
3871
+ /**
3872
+ * ASR voice to text | ASR 语音转文本
3873
+ * @param params - Required The parameters for file upload | 上传文件所需的参数
3874
+ * @param params.file - Required The audio file to be uploaded. | 需要上传的音频文件。
3875
+ */ async create(params, options) {
3876
+ const apiUrl = '/v1/audio/transcriptions';
3877
+ const response = await this._client.post(apiUrl, axios_toFormData(params), false, options);
3878
+ return response.data;
3879
+ }
3880
+ }
3771
3881
  class Speech extends APIResource {
3772
3882
  /**
3773
3883
  * @description Speech synthesis | 语音合成
@@ -3781,7 +3891,10 @@ class Speech extends APIResource {
3781
3891
  * @returns Speech synthesis data
3782
3892
  */ async create(params, options) {
3783
3893
  const apiUrl = '/v1/audio/speech';
3784
- const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
3894
+ const response = await this._client.post(apiUrl, {
3895
+ ...params,
3896
+ sample_rate: params.sample_rate || 24000
3897
+ }, false, mergeConfig(options, {
3785
3898
  responseType: 'arraybuffer'
3786
3899
  }));
3787
3900
  return response;
@@ -3796,13 +3909,27 @@ class Rooms extends APIResource {
3796
3909
  }
3797
3910
  class audio_Audio extends APIResource {
3798
3911
  constructor(...args){
3799
- super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
3912
+ super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client), this.transcriptions = new Transcriptions(this._client);
3913
+ }
3914
+ }
3915
+ class Templates extends APIResource {
3916
+ /**
3917
+ * Duplicate a template. | 复制一个模板。
3918
+ * @param templateId - Required. The ID of the template to duplicate. | 要复制的模板的 ID。
3919
+ * @param params - Optional. The parameters for the duplicate operation. | 可选参数,用于复制操作。
3920
+ * @param params.workspace_id - Required. The ID of the workspace to duplicate the template into. | 要复制到的目标工作空间的 ID。
3921
+ * @param params.name - Optional. The name of the new template. | 新模板的名称。
3922
+ * @returns TemplateDuplicateRes | 复制模板结果
3923
+ */ async duplicate(templateId, params, options) {
3924
+ const apiUrl = `/v1/templates/${templateId}/duplicate`;
3925
+ const response = await this._client.post(apiUrl, params, false, options);
3926
+ return response.data;
3800
3927
  }
3801
3928
  }
3802
3929
  // EXTERNAL MODULE: os (ignored)
3803
3930
  var os_ignored_ = __webpack_require__("?9050");
3804
3931
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
3805
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16-beta.1","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","main":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.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
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
3806
3933
  const { version: version_version } = package_namespaceObject;
3807
3934
  const getEnv = ()=>{
3808
3935
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -3852,6 +3979,55 @@ const getNodeClientUserAgent = ()=>{
3852
3979
  };
3853
3980
  return JSON.stringify(ua);
3854
3981
  };
3982
+ const getBrowserClientUserAgent = ()=>{
3983
+ const browserInfo = {
3984
+ name: 'unknown',
3985
+ version: 'unknown'
3986
+ };
3987
+ const osInfo = {
3988
+ name: 'unknown',
3989
+ version: 'unknown'
3990
+ };
3991
+ const { userAgent } = navigator;
3992
+ // 检测操作系统及版本
3993
+ if (userAgent.indexOf('Windows') > -1) {
3994
+ var _userAgent_match;
3995
+ osInfo.name = 'windows';
3996
+ const windowsVersion = (null === (_userAgent_match = userAgent.match(/Windows NT ([0-9.]+)/)) || void 0 === _userAgent_match ? void 0 : _userAgent_match[1]) || 'unknown';
3997
+ osInfo.version = windowsVersion;
3998
+ } else if (userAgent.indexOf('Mac OS X') > -1) {
3999
+ var _userAgent_match1;
4000
+ osInfo.name = 'macos';
4001
+ // 将 10_15_7 格式转换为 10.15.7
4002
+ osInfo.version = ((null === (_userAgent_match1 = userAgent.match(/Mac OS X ([0-9_]+)/)) || void 0 === _userAgent_match1 ? void 0 : _userAgent_match1[1]) || 'unknown').replace(/_/g, '.');
4003
+ } else if (userAgent.indexOf('Linux') > -1) {
4004
+ var _userAgent_match2;
4005
+ osInfo.name = 'linux';
4006
+ osInfo.version = (null === (_userAgent_match2 = userAgent.match(/Linux ([0-9.]+)/)) || void 0 === _userAgent_match2 ? void 0 : _userAgent_match2[1]) || 'unknown';
4007
+ }
4008
+ // 检测浏览器及版本
4009
+ if (userAgent.indexOf('Chrome') > -1) {
4010
+ var _userAgent_match3;
4011
+ browserInfo.name = 'chrome';
4012
+ browserInfo.version = (null === (_userAgent_match3 = userAgent.match(/Chrome\/([0-9.]+)/)) || void 0 === _userAgent_match3 ? void 0 : _userAgent_match3[1]) || 'unknown';
4013
+ } else if (userAgent.indexOf('Firefox') > -1) {
4014
+ var _userAgent_match4;
4015
+ browserInfo.name = 'firefox';
4016
+ browserInfo.version = (null === (_userAgent_match4 = userAgent.match(/Firefox\/([0-9.]+)/)) || void 0 === _userAgent_match4 ? void 0 : _userAgent_match4[1]) || 'unknown';
4017
+ } else if (userAgent.indexOf('Safari') > -1) {
4018
+ var _userAgent_match5;
4019
+ browserInfo.name = 'safari';
4020
+ browserInfo.version = (null === (_userAgent_match5 = userAgent.match(/Version\/([0-9.]+)/)) || void 0 === _userAgent_match5 ? void 0 : _userAgent_match5[1]) || 'unknown';
4021
+ }
4022
+ const ua = {
4023
+ version: version_version,
4024
+ browser: browserInfo.name,
4025
+ browser_version: browserInfo.version,
4026
+ os_name: osInfo.name,
4027
+ os_version: osInfo.version
4028
+ };
4029
+ return JSON.stringify(ua);
4030
+ };
3855
4031
  /* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
3856
4032
  if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
3857
4033
  if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
@@ -3951,12 +4127,15 @@ function isAxiosStatic(instance) {
3951
4127
  const headers = {
3952
4128
  authorization: `Bearer ${token}`
3953
4129
  };
3954
- if (!utils_isBrowser()) {
4130
+ if (utils_isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
4131
+ else {
3955
4132
  headers['User-Agent'] = getUserAgent();
3956
4133
  headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
3957
4134
  }
3958
4135
  const config = mergeConfig(this.axiosOptions, options, {
3959
4136
  headers
4137
+ }, {
4138
+ headers: this.headers || {}
3960
4139
  });
3961
4140
  config.method = method;
3962
4141
  config.data = body;
@@ -3967,11 +4146,11 @@ function isAxiosStatic(instance) {
3967
4146
  const fetchOptions = await this.buildOptions(method, body, options);
3968
4147
  fetchOptions.isStreaming = isStream;
3969
4148
  fetchOptions.axiosInstance = this.axiosInstance;
3970
- this.debugLog(`--- request url: ${fullUrl}`);
3971
- this.debugLog('--- request options:', fetchOptions);
4149
+ this.debugLog(null == options ? void 0 : options.debug, `--- request url: ${fullUrl}`);
4150
+ this.debugLog(null == options ? void 0 : options.debug, '--- request options:', fetchOptions);
3972
4151
  const { response, stream, json } = await fetchAPI(fullUrl, fetchOptions);
3973
- this.debugLog(`--- response status: ${response.status}`);
3974
- this.debugLog('--- response headers: ', response.headers);
4152
+ this.debugLog(null == options ? void 0 : options.debug, `--- response status: ${response.status}`);
4153
+ this.debugLog(null == options ? void 0 : options.debug, '--- response headers: ', response.headers);
3975
4154
  var _response_headers;
3976
4155
  // Taro use `header`
3977
4156
  const contentType = (null !== (_response_headers = response.headers) && void 0 !== _response_headers ? _response_headers : response.header)['content-type'];
@@ -4014,8 +4193,9 @@ function isAxiosStatic(instance) {
4014
4193
  }
4015
4194
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4016
4195
  debugLog() {
4017
- for(var _len = arguments.length, msgs = new Array(_len), _key = 0; _key < _len; _key++)msgs[_key] = arguments[_key];
4018
- if (this.debug) console.debug(...msgs);
4196
+ let forceDebug = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
4197
+ for(var _len = arguments.length, msgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++)msgs[_key - 1] = arguments[_key];
4198
+ if (this.debug || forceDebug) console.debug(...msgs);
4019
4199
  }
4020
4200
  constructor(config){
4021
4201
  this._config = config;
@@ -4047,7 +4227,7 @@ class CozeAPI extends core_APIClient {
4047
4227
  constructor(...args){
4048
4228
  super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
4049
4229
  * @deprecated
4050
- */ 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);
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);
4051
4231
  }
4052
4232
  }
4053
4233
  /**
@@ -38452,7 +38632,11 @@ var VERTC = _createClass(function e() {
38452
38632
  return false;
38453
38633
  }
38454
38634
  };
38455
- const checkDevicePermission = async function() {
38635
+ /**
38636
+ * Checks device permissions for audio and video
38637
+ * @param checkVideo Whether to check video permissions (default: false)
38638
+ * @returns Promise that resolves with the device permission status
38639
+ */ const checkDevicePermission = async function() {
38456
38640
  let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
38457
38641
  return await index_esm_min_index.enableDevices({
38458
38642
  audio: true,
@@ -38465,7 +38649,16 @@ const checkDevicePermission = async function() {
38465
38649
  */ const getAudioDevices = async function() {
38466
38650
  let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
38467
38651
  let devices = [];
38468
- devices = video ? await index_esm_min_index.enumerateDevices() : await [
38652
+ if (video) {
38653
+ devices = await index_esm_min_index.enumerateDevices();
38654
+ if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
38655
+ devices.push({
38656
+ deviceId: 'screenShare',
38657
+ kind: 'videoinput',
38658
+ label: 'Screen Share',
38659
+ groupId: 'screenShare'
38660
+ });
38661
+ } else devices = await [
38469
38662
  ...await index_esm_min_index.enumerateAudioCaptureDevices(),
38470
38663
  ...await index_esm_min_index.enumerateAudioPlaybackDevices()
38471
38664
  ];
@@ -38480,6 +38673,14 @@ const checkDevicePermission = async function() {
38480
38673
  videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
38481
38674
  };
38482
38675
  };
38676
+ const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
38677
+ /**
38678
+ * Check if browser supports screen sharing
38679
+ * 检查浏览器是否支持屏幕共享
38680
+ */ function isScreenShareSupported() {
38681
+ var _navigator_mediaDevices, _navigator;
38682
+ return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
38683
+ }
38483
38684
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
38484
38685
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
38485
38686
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -38573,6 +38774,10 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
38573
38774
  * zh: 音频输出设备改变
38574
38775
  */ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
38575
38776
  /**
38777
+ * en: Video input device changed
38778
+ * zh: 视频输入设备改变
38779
+ */ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
38780
+ /**
38576
38781
  * en: Bot joined
38577
38782
  * zh: Bot 加入
38578
38783
  */ EventNames["BOT_JOIN"] = "server.bot.join";
@@ -41990,23 +42195,47 @@ class EngineClient extends RealtimeEventHandler {
41990
42195
  if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
41991
42196
  await this.engine.setAudioPlaybackDevice(deviceId);
41992
42197
  }
42198
+ async setVideoInputDevice(deviceId) {
42199
+ let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
42200
+ var _this__videoConfig;
42201
+ const devices = await getAudioDevices({
42202
+ video: true
42203
+ });
42204
+ if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
42205
+ await this.changeVideoState(false);
42206
+ if (isScreenShareDevice(deviceId)) {
42207
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN);
42208
+ if (isAutoCapture) {
42209
+ var _this__videoConfig1;
42210
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42211
+ await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
42212
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42213
+ }
42214
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
42215
+ } else {
42216
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_SCREEN);
42217
+ if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
42218
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_MAIN;
42219
+ }
42220
+ this.engine.setLocalVideoPlayer(this._streamIndex, {
42221
+ renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
42222
+ userId: this._roomUserId
42223
+ });
42224
+ }
41993
42225
  async createLocalStream(userId, videoConfig) {
42226
+ this._roomUserId = userId;
41994
42227
  const devices = await getAudioDevices({
41995
42228
  video: this._isSupportVideo
41996
42229
  });
41997
42230
  if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
41998
42231
  if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
41999
42232
  await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
42000
- if (this._isSupportVideo && (null == videoConfig ? void 0 : videoConfig.videoOnDefault)) await this.engine.startVideoCapture(devices.videoInputs[0].deviceId);
42001
- if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
42002
- renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
42003
- userId
42004
- });
42233
+ if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
42005
42234
  }
42006
42235
  async disconnect() {
42007
42236
  try {
42008
- if (this._isSupportVideo) await this.engine.stopVideoCapture();
42009
- await this.engine.stopAudioCapture();
42237
+ if (this._isSupportVideo) await this.changeVideoState(false);
42238
+ await this.changeAudioState(false);
42010
42239
  await this.engine.unpublishStream(MediaType$1.AUDIO);
42011
42240
  await this.engine.leaveRoom();
42012
42241
  this.removeEventListener();
@@ -42026,8 +42255,19 @@ class EngineClient extends RealtimeEventHandler {
42026
42255
  }
42027
42256
  async changeVideoState(isVideoOn) {
42028
42257
  try {
42029
- if (isVideoOn) await this.engine.startVideoCapture();
42030
- else await this.engine.stopVideoCapture();
42258
+ if (isVideoOn) {
42259
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
42260
+ else {
42261
+ var _this__videoConfig;
42262
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42263
+ await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
42264
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42265
+ }
42266
+ } else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
42267
+ else {
42268
+ await this.engine.stopScreenCapture();
42269
+ await this.engine.unpublishScreen(MediaType$1.VIDEO);
42270
+ }
42031
42271
  } catch (e) {
42032
42272
  this.dispatch(event_handler_EventNames.ERROR, e);
42033
42273
  throw e;
@@ -42104,8 +42344,11 @@ class EngineClient extends RealtimeEventHandler {
42104
42344
  throw e;
42105
42345
  }
42106
42346
  }
42347
+ getRtcEngine() {
42348
+ return this.engine;
42349
+ }
42107
42350
  // eslint-disable-next-line max-params
42108
- constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
42351
+ constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
42109
42352
  super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
42110
42353
  if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
42111
42354
  'rtc-test.bytedance.com'
@@ -42120,6 +42363,7 @@ class EngineClient extends RealtimeEventHandler {
42120
42363
  this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
42121
42364
  this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
42122
42365
  this._isSupportVideo = isSupportVideo;
42366
+ this._videoConfig = videoConfig;
42123
42367
  }
42124
42368
  }
42125
42369
  class RealtimeClient extends RealtimeEventHandler {
@@ -42135,16 +42379,17 @@ class RealtimeClient extends RealtimeEventHandler {
42135
42379
  // Step1 get token
42136
42380
  roomInfo = await this._api.audio.rooms.create({
42137
42381
  bot_id: botId,
42138
- conversation_id: conversationId,
42382
+ conversation_id: conversationId || void 0,
42139
42383
  voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
42140
- connector_id: this._config.connectorId
42384
+ connector_id: this._config.connectorId,
42385
+ uid: this._config.userId || void 0
42141
42386
  });
42142
42387
  } catch (error) {
42143
42388
  this.dispatch(event_handler_EventNames.ERROR, error);
42144
42389
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
42145
42390
  }
42146
42391
  // Step2 create engine
42147
- this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
42392
+ this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
42148
42393
  // Step3 bind engine events
42149
42394
  this._client.bindEngineEvents();
42150
42395
  this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
@@ -42280,6 +42525,21 @@ class RealtimeClient extends RealtimeEventHandler {
42280
42525
  deviceId
42281
42526
  });
42282
42527
  }
42528
+ async setVideoInputDevice(deviceId) {
42529
+ var _this__client;
42530
+ await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
42531
+ this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
42532
+ deviceId
42533
+ });
42534
+ }
42535
+ /**
42536
+ * en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
42537
+ *
42538
+ * zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
42539
+ */ getRtcEngine() {
42540
+ var _this__client;
42541
+ return null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.getRtcEngine();
42542
+ }
42283
42543
  /**
42284
42544
  * Constructor for initializing a RealtimeClient instance.
42285
42545
  *
@@ -42294,6 +42554,8 @@ class RealtimeClient extends RealtimeEventHandler {
42294
42554
  * 可选,音色Id。
42295
42555
  * @param config.conversationId - Optional, Conversation Id. |
42296
42556
  * 可选,会话Id。
42557
+ * @param config.userId - Optional, User Id. |
42558
+ * 可选,用户Id。
42297
42559
  * @param config.baseURL - Optional, defaults to "https://api.coze.cn". |
42298
42560
  * 可选,默认值为 "https://api.coze.cn"。
42299
42561
  * @param config.debug - Optional, defaults to false.
@@ -42310,6 +42572,16 @@ class RealtimeClient extends RealtimeEventHandler {
42310
42572
  * @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
42311
42573
  * 可选,默认是否抑制非静态噪声,默认值为 false。
42312
42574
  * @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
42575
+ * @param config.videoConfig - Optional, Video configuration. |
42576
+ * 可选,视频配置。
42577
+ * @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
42578
+ * 可选,默认是否开启视频,默认值为 true。
42579
+ * @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
42580
+ * 可选,渲染视频流的 DOM 元素。
42581
+ * @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
42582
+ * 可选,视频输入设备的设备 ID。
42583
+ * @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
42584
+ * 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
42313
42585
  */ constructor(config){
42314
42586
  super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
42315
42587
  this._config = config;