@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.mjs.LICENSE.txt */
1
+ /*! For license information please see index.js.LICENSE.txt */
2
2
  var __webpack_modules__ = {
3
3
  "?666e": function() {
4
4
  /* (ignored) */ },
@@ -83,7 +83,7 @@ __webpack_require__.d(common_utils_namespaceObject, {
83
83
  hasBrowserEnv: ()=>hasBrowserEnv,
84
84
  hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
85
85
  hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
86
- navigator: ()=>_navigator,
86
+ navigator: ()=>utils_navigator,
87
87
  origin: ()=>origin
88
88
  });
89
89
  // NAMESPACE OBJECT: ./src/utils.ts
@@ -93,6 +93,8 @@ __webpack_require__.d(src_utils_namespaceObject, {
93
93
  checkDevicePermission: ()=>checkDevicePermission,
94
94
  checkPermission: ()=>checkPermission,
95
95
  getAudioDevices: ()=>getAudioDevices,
96
+ isScreenShareDevice: ()=>isScreenShareDevice,
97
+ isScreenShareSupported: ()=>isScreenShareSupported,
96
98
  sleep: ()=>src_utils_sleep
97
99
  });
98
100
  class APIResource {
@@ -1616,7 +1618,7 @@ class InterceptorManager_InterceptorManager {
1616
1618
  ]
1617
1619
  };
1618
1620
  const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
1619
- const _navigator = 'object' == typeof navigator && navigator || void 0;
1621
+ const utils_navigator = 'object' == typeof navigator && navigator || void 0;
1620
1622
  /**
1621
1623
  * Determine if we're running in a standard browser environment
1622
1624
  *
@@ -1633,11 +1635,11 @@ const _navigator = 'object' == typeof navigator && navigator || void 0;
1633
1635
  * navigator.product -> 'NativeScript' or 'NS'
1634
1636
  *
1635
1637
  * @returns {boolean}
1636
- */ const hasStandardBrowserEnv = hasBrowserEnv && (!_navigator || [
1638
+ */ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
1637
1639
  'ReactNative',
1638
1640
  'NativeScript',
1639
1641
  'NS'
1640
- ].indexOf(_navigator.product) < 0);
1642
+ ].indexOf(utils_navigator.product) < 0);
1641
1643
  /**
1642
1644
  * Determine if we're running in a standard browser webWorker environment
1643
1645
  *
@@ -3659,9 +3661,9 @@ class documents_Documents extends APIResource {
3659
3661
  * @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
3660
3662
  * @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
3661
3663
  * @returns ListDocumentData | 知识库文件列表
3662
- */ list(params, options) {
3664
+ */ async list(params, options) {
3663
3665
  const apiUrl = '/open_api/knowledge/document/list';
3664
- const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
3666
+ const response = await this._client.get(apiUrl, params, false, mergeConfig(options, {
3665
3667
  headers: documents_documents_headers
3666
3668
  }));
3667
3669
  return response;
@@ -3710,9 +3712,104 @@ class documents_Documents extends APIResource {
3710
3712
  }));
3711
3713
  }
3712
3714
  }
3715
+ class Images extends APIResource {
3716
+ /**
3717
+ * Update the description of an image in the knowledge base | 更新知识库中的图片描述
3718
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/update_image_caption?_lang=en
3719
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/update_image_caption?_lang=zh
3720
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3721
+ * @param documentId - The ID of the document | 必选 知识库文件 ID
3722
+ * @param params - The parameters for updating the image
3723
+ * @param params.caption - Required. The description of the image | 必选 图片的描述信息
3724
+ * @returns undefined
3725
+ */ // eslint-disable-next-line max-params
3726
+ async update(datasetId, documentId, params, options) {
3727
+ const apiUrl = `/v1/datasets/${datasetId}/images/${documentId}`;
3728
+ await this._client.put(apiUrl, params, false, options);
3729
+ }
3730
+ /**
3731
+ * List images in the knowledge base | 列出知识库中的图片
3732
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/get_images?_lang=en
3733
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/get_images?_lang=zh
3734
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3735
+ * @param params - The parameters for listing images
3736
+ * @param params.page_num - Optional. Page number for pagination, minimum value is 1, defaults to 1 | 可选 分页查询时的页码。默认为 1。
3737
+ * @param params.page_size - Optional. Number of items per page, range 1-299, defaults to 10 | 可选 分页大小。默认为 10。
3738
+ * @param params.keyword - Optional. Search keyword for image descriptions | 可选 图片描述的搜索关键词。
3739
+ * @param params.has_caption - Optional. Filter for images with/without captions | 可选 是否过滤有/无描述的图片。
3740
+ */ async list(datasetId, params, options) {
3741
+ const apiUrl = `/v1/datasets/${datasetId}/images`;
3742
+ const response = await this._client.get(apiUrl, params, false, options);
3743
+ return response.data;
3744
+ }
3745
+ }
3713
3746
  class Datasets extends APIResource {
3747
+ /**
3748
+ * Creates a new dataset | 创建数据集
3749
+ * @docs en: https://www.coze.com/docs/developer_guides/create_dataset?_lang=en
3750
+ * @docs zh: https://www.coze.cn/docs/developer_guides/create_dataset?_lang=zh
3751
+ * @param params - The parameters for creating a dataset
3752
+ * @param {string} params.name - Required. Dataset name, maximum length of 100 characters | 必选 数据集名称,最大长度为 100 个字符
3753
+ * @param {string} params.space_id - Required. Space ID where the dataset belongs | 必选 数据集所属的空间 ID
3754
+ * @param {number} params.format_type - Required. Dataset type (0: Text type, 2: Image type) | 必选 数据集类型 (0: 文本类型, 2: 图片类型)
3755
+ * @param {string} [params.description] - Optional. Dataset description | 可选 数据集描述
3756
+ * @param {string} [params.file_id] - Optional. Dataset icon file ID from file upload
3757
+ */ async create(params, options) {
3758
+ const apiUrl = '/v1/datasets';
3759
+ const response = await this._client.post(apiUrl, params, false, options);
3760
+ return response.data;
3761
+ }
3762
+ /**
3763
+ * Lists all datasets in a space | 列出空间中的所有数据集
3764
+ * @docs en: https://www.coze.com/docs/developer_guides/list_dataset?_lang=en
3765
+ * @docs zh: https://www.coze.cn/docs/developer_guides/list_dataset?_lang=zh
3766
+ * @param params - The parameters for listing datasets | 列出数据集的参数
3767
+ * @param {string} params.space_id - Required. Space ID where the datasets belong | 必选 数据集所属的空间 ID
3768
+ * @param {string} [params.name] - Optional. Dataset name for fuzzy search | 可选 数据集名称用于模糊搜索
3769
+ * @param {number} [params.format_type] - Optional. Dataset type (0: Text type, 2: Image type) | 可选 数据集类型 (0: 文本类型, 2: 图片类型)
3770
+ * @param {number} [params.page_num] - Optional. Page number for pagination (default: 1) | 可选 分页查询时的页码。默认为 1。
3771
+ * @param {number} [params.page_size] - Optional. Number of items per page (default: 10) | 可选 分页大小。默认为 10。
3772
+ */ async list(params, options) {
3773
+ const apiUrl = '/v1/datasets';
3774
+ const response = await this._client.get(apiUrl, params, false, options);
3775
+ return response.data;
3776
+ }
3777
+ /**
3778
+ * Updates a dataset | 更新数据集
3779
+ * @docs en: https://www.coze.com/docs/developer_guides/update_dataset?_lang=en
3780
+ * @docs zh: https://www.coze.cn/docs/developer_guides/update_dataset?_lang=zh
3781
+ * @param dataset_id - Required. The ID of the dataset to update | 必选 数据集 ID
3782
+ * @param params - Required. The parameters for updating the dataset | 必选 更新数据集的参数
3783
+ * @param params.name - Required. Dataset name, maximum length of 100 characters. | 必选 数据集名称,最大长度为 100 个字符。
3784
+ * @param params.file_id - Optional. Dataset icon, should pass the file_id obtained from the file upload interface. | 可选 数据集图标,应传递从文件上传接口获取的 file_id。
3785
+ * @param params.description - Optional. Dataset description. | 可选 数据集描述。
3786
+ */ async update(dataset_id, params, options) {
3787
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3788
+ await this._client.put(apiUrl, params, false, options);
3789
+ }
3790
+ /**
3791
+ * Deletes a dataset | 删除数据集
3792
+ * @docs en: https://www.coze.com/docs/developer_guides/delete_dataset?_lang=en
3793
+ * @docs zh: https://www.coze.cn/docs/developer_guides/delete_dataset?_lang=zh
3794
+ * @param dataset_id - Required. The ID of the dataset to delete | 必选 数据集 ID
3795
+ */ async delete(dataset_id, options) {
3796
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3797
+ await this._client.delete(apiUrl, false, options);
3798
+ }
3799
+ /**
3800
+ * Views the progress of dataset upload | 查看数据集上传进度
3801
+ * @docs en: https://www.coze.com/docs/developer_guides/get_dataset_progress?_lang=en
3802
+ * @docs zh: https://www.coze.cn/docs/developer_guides/get_dataset_progress?_lang=zh
3803
+ * @param dataset_id - Required. The ID of the dataset to process | 必选 数据集 ID
3804
+ * @param params - Required. The parameters for processing the dataset | 必选 处理数据集的参数
3805
+ * @param params.dataset_ids - Required. List of dataset IDs | 必选 数据集 ID 列表
3806
+ */ async process(dataset_id, params, options) {
3807
+ const apiUrl = `/v1/datasets/${dataset_id}/process`;
3808
+ const response = await this._client.post(apiUrl, params, false, options);
3809
+ return response.data;
3810
+ }
3714
3811
  constructor(...args){
3715
- super(...args), this.documents = new documents_Documents(this._client);
3812
+ super(...args), this.documents = new documents_Documents(this._client), this.images = new Images(this._client);
3716
3813
  }
3717
3814
  }
3718
3815
  class Voices extends APIResource {
@@ -3732,6 +3829,8 @@ class Voices extends APIResource {
3732
3829
  * | 如果传入会基于该文本生成预览音频,否则使用默认的文本
3733
3830
  * @param params.text - Optional. Users can read this text, service will compare audio with text. Returns error if difference is too large
3734
3831
  * | 可以让用户按照该文本念诵,服务会对比音频与该文本的差异。若差异过大会返回错误
3832
+ * @param params.space_id - Optional. The space id of the voice. | 空间ID
3833
+ * @param params.description- Optional. The description of the voice. | 音色描述
3735
3834
  * @param options - Request options
3736
3835
  * @returns Clone voice data
3737
3836
  */ async clone(params, options) {
@@ -3756,6 +3855,17 @@ class Voices extends APIResource {
3756
3855
  return response.data;
3757
3856
  }
3758
3857
  }
3858
+ class Transcriptions extends APIResource {
3859
+ /**
3860
+ * ASR voice to text | ASR 语音转文本
3861
+ * @param params - Required The parameters for file upload | 上传文件所需的参数
3862
+ * @param params.file - Required The audio file to be uploaded. | 需要上传的音频文件。
3863
+ */ async create(params, options) {
3864
+ const apiUrl = '/v1/audio/transcriptions';
3865
+ const response = await this._client.post(apiUrl, axios_toFormData(params), false, options);
3866
+ return response.data;
3867
+ }
3868
+ }
3759
3869
  class Speech extends APIResource {
3760
3870
  /**
3761
3871
  * @description Speech synthesis | 语音合成
@@ -3769,7 +3879,10 @@ class Speech extends APIResource {
3769
3879
  * @returns Speech synthesis data
3770
3880
  */ async create(params, options) {
3771
3881
  const apiUrl = '/v1/audio/speech';
3772
- const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
3882
+ const response = await this._client.post(apiUrl, {
3883
+ ...params,
3884
+ sample_rate: params.sample_rate || 24000
3885
+ }, false, mergeConfig(options, {
3773
3886
  responseType: 'arraybuffer'
3774
3887
  }));
3775
3888
  return response;
@@ -3784,13 +3897,27 @@ class Rooms extends APIResource {
3784
3897
  }
3785
3898
  class audio_Audio extends APIResource {
3786
3899
  constructor(...args){
3787
- super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
3900
+ 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);
3901
+ }
3902
+ }
3903
+ class Templates extends APIResource {
3904
+ /**
3905
+ * Duplicate a template. | 复制一个模板。
3906
+ * @param templateId - Required. The ID of the template to duplicate. | 要复制的模板的 ID。
3907
+ * @param params - Optional. The parameters for the duplicate operation. | 可选参数,用于复制操作。
3908
+ * @param params.workspace_id - Required. The ID of the workspace to duplicate the template into. | 要复制到的目标工作空间的 ID。
3909
+ * @param params.name - Optional. The name of the new template. | 新模板的名称。
3910
+ * @returns TemplateDuplicateRes | 复制模板结果
3911
+ */ async duplicate(templateId, params, options) {
3912
+ const apiUrl = `/v1/templates/${templateId}/duplicate`;
3913
+ const response = await this._client.post(apiUrl, params, false, options);
3914
+ return response.data;
3788
3915
  }
3789
3916
  }
3790
3917
  // EXTERNAL MODULE: os (ignored)
3791
3918
  var os_ignored_ = __webpack_require__("?9050");
3792
3919
  var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
3793
- 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
3920
+ var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","exports":{".":"./src/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
3794
3921
  const { version: version_version } = package_namespaceObject;
3795
3922
  const getEnv = ()=>{
3796
3923
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -3840,6 +3967,55 @@ const getNodeClientUserAgent = ()=>{
3840
3967
  };
3841
3968
  return JSON.stringify(ua);
3842
3969
  };
3970
+ const getBrowserClientUserAgent = ()=>{
3971
+ const browserInfo = {
3972
+ name: 'unknown',
3973
+ version: 'unknown'
3974
+ };
3975
+ const osInfo = {
3976
+ name: 'unknown',
3977
+ version: 'unknown'
3978
+ };
3979
+ const { userAgent } = navigator;
3980
+ // 检测操作系统及版本
3981
+ if (userAgent.indexOf('Windows') > -1) {
3982
+ var _userAgent_match;
3983
+ osInfo.name = 'windows';
3984
+ const windowsVersion = (null === (_userAgent_match = userAgent.match(/Windows NT ([0-9.]+)/)) || void 0 === _userAgent_match ? void 0 : _userAgent_match[1]) || 'unknown';
3985
+ osInfo.version = windowsVersion;
3986
+ } else if (userAgent.indexOf('Mac OS X') > -1) {
3987
+ var _userAgent_match1;
3988
+ osInfo.name = 'macos';
3989
+ // 将 10_15_7 格式转换为 10.15.7
3990
+ osInfo.version = ((null === (_userAgent_match1 = userAgent.match(/Mac OS X ([0-9_]+)/)) || void 0 === _userAgent_match1 ? void 0 : _userAgent_match1[1]) || 'unknown').replace(/_/g, '.');
3991
+ } else if (userAgent.indexOf('Linux') > -1) {
3992
+ var _userAgent_match2;
3993
+ osInfo.name = 'linux';
3994
+ osInfo.version = (null === (_userAgent_match2 = userAgent.match(/Linux ([0-9.]+)/)) || void 0 === _userAgent_match2 ? void 0 : _userAgent_match2[1]) || 'unknown';
3995
+ }
3996
+ // 检测浏览器及版本
3997
+ if (userAgent.indexOf('Chrome') > -1) {
3998
+ var _userAgent_match3;
3999
+ browserInfo.name = 'chrome';
4000
+ browserInfo.version = (null === (_userAgent_match3 = userAgent.match(/Chrome\/([0-9.]+)/)) || void 0 === _userAgent_match3 ? void 0 : _userAgent_match3[1]) || 'unknown';
4001
+ } else if (userAgent.indexOf('Firefox') > -1) {
4002
+ var _userAgent_match4;
4003
+ browserInfo.name = 'firefox';
4004
+ browserInfo.version = (null === (_userAgent_match4 = userAgent.match(/Firefox\/([0-9.]+)/)) || void 0 === _userAgent_match4 ? void 0 : _userAgent_match4[1]) || 'unknown';
4005
+ } else if (userAgent.indexOf('Safari') > -1) {
4006
+ var _userAgent_match5;
4007
+ browserInfo.name = 'safari';
4008
+ browserInfo.version = (null === (_userAgent_match5 = userAgent.match(/Version\/([0-9.]+)/)) || void 0 === _userAgent_match5 ? void 0 : _userAgent_match5[1]) || 'unknown';
4009
+ }
4010
+ const ua = {
4011
+ version: version_version,
4012
+ browser: browserInfo.name,
4013
+ browser_version: browserInfo.version,
4014
+ os_name: osInfo.name,
4015
+ os_version: osInfo.version
4016
+ };
4017
+ return JSON.stringify(ua);
4018
+ };
3843
4019
  /* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
3844
4020
  if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
3845
4021
  if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
@@ -3939,12 +4115,15 @@ function isAxiosStatic(instance) {
3939
4115
  const headers = {
3940
4116
  authorization: `Bearer ${token}`
3941
4117
  };
3942
- if (!utils_isBrowser()) {
4118
+ if (utils_isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
4119
+ else {
3943
4120
  headers['User-Agent'] = getUserAgent();
3944
4121
  headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
3945
4122
  }
3946
4123
  const config = mergeConfig(this.axiosOptions, options, {
3947
4124
  headers
4125
+ }, {
4126
+ headers: this.headers || {}
3948
4127
  });
3949
4128
  config.method = method;
3950
4129
  config.data = body;
@@ -3955,11 +4134,11 @@ function isAxiosStatic(instance) {
3955
4134
  const fetchOptions = await this.buildOptions(method, body, options);
3956
4135
  fetchOptions.isStreaming = isStream;
3957
4136
  fetchOptions.axiosInstance = this.axiosInstance;
3958
- this.debugLog(`--- request url: ${fullUrl}`);
3959
- this.debugLog('--- request options:', fetchOptions);
4137
+ this.debugLog(null == options ? void 0 : options.debug, `--- request url: ${fullUrl}`);
4138
+ this.debugLog(null == options ? void 0 : options.debug, '--- request options:', fetchOptions);
3960
4139
  const { response, stream, json } = await fetchAPI(fullUrl, fetchOptions);
3961
- this.debugLog(`--- response status: ${response.status}`);
3962
- this.debugLog('--- response headers: ', response.headers);
4140
+ this.debugLog(null == options ? void 0 : options.debug, `--- response status: ${response.status}`);
4141
+ this.debugLog(null == options ? void 0 : options.debug, '--- response headers: ', response.headers);
3963
4142
  var _response_headers;
3964
4143
  // Taro use `header`
3965
4144
  const contentType = (null !== (_response_headers = response.headers) && void 0 !== _response_headers ? _response_headers : response.header)['content-type'];
@@ -4002,8 +4181,9 @@ function isAxiosStatic(instance) {
4002
4181
  }
4003
4182
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4004
4183
  debugLog() {
4005
- for(var _len = arguments.length, msgs = new Array(_len), _key = 0; _key < _len; _key++)msgs[_key] = arguments[_key];
4006
- if (this.debug) console.debug(...msgs);
4184
+ let forceDebug = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
4185
+ for(var _len = arguments.length, msgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++)msgs[_key - 1] = arguments[_key];
4186
+ if (this.debug || forceDebug) console.debug(...msgs);
4007
4187
  }
4008
4188
  constructor(config){
4009
4189
  this._config = config;
@@ -4035,7 +4215,7 @@ class CozeAPI extends core_APIClient {
4035
4215
  constructor(...args){
4036
4216
  super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
4037
4217
  * @deprecated
4038
- */ 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);
4218
+ */ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new audio_Audio(this), this.templates = new Templates(this);
4039
4219
  }
4040
4220
  }
4041
4221
  /**
@@ -38440,7 +38620,11 @@ var VERTC = _createClass(function e() {
38440
38620
  return false;
38441
38621
  }
38442
38622
  };
38443
- const checkDevicePermission = async function() {
38623
+ /**
38624
+ * Checks device permissions for audio and video
38625
+ * @param checkVideo Whether to check video permissions (default: false)
38626
+ * @returns Promise that resolves with the device permission status
38627
+ */ const checkDevicePermission = async function() {
38444
38628
  let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
38445
38629
  return await index_esm_min_index.enableDevices({
38446
38630
  audio: true,
@@ -38453,7 +38637,16 @@ const checkDevicePermission = async function() {
38453
38637
  */ const getAudioDevices = async function() {
38454
38638
  let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
38455
38639
  let devices = [];
38456
- devices = video ? await index_esm_min_index.enumerateDevices() : await [
38640
+ if (video) {
38641
+ devices = await index_esm_min_index.enumerateDevices();
38642
+ if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
38643
+ devices.push({
38644
+ deviceId: 'screenShare',
38645
+ kind: 'videoinput',
38646
+ label: 'Screen Share',
38647
+ groupId: 'screenShare'
38648
+ });
38649
+ } else devices = await [
38457
38650
  ...await index_esm_min_index.enumerateAudioCaptureDevices(),
38458
38651
  ...await index_esm_min_index.enumerateAudioPlaybackDevices()
38459
38652
  ];
@@ -38468,6 +38661,14 @@ const checkDevicePermission = async function() {
38468
38661
  videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
38469
38662
  };
38470
38663
  };
38664
+ const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
38665
+ /**
38666
+ * Check if browser supports screen sharing
38667
+ * 检查浏览器是否支持屏幕共享
38668
+ */ function isScreenShareSupported() {
38669
+ var _navigator_mediaDevices, _navigator;
38670
+ return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
38671
+ }
38471
38672
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
38472
38673
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
38473
38674
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -38561,6 +38762,10 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
38561
38762
  * zh: 音频输出设备改变
38562
38763
  */ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
38563
38764
  /**
38765
+ * en: Video input device changed
38766
+ * zh: 视频输入设备改变
38767
+ */ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
38768
+ /**
38564
38769
  * en: Bot joined
38565
38770
  * zh: Bot 加入
38566
38771
  */ EventNames["BOT_JOIN"] = "server.bot.join";
@@ -41978,23 +42183,47 @@ class EngineClient extends RealtimeEventHandler {
41978
42183
  if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
41979
42184
  await this.engine.setAudioPlaybackDevice(deviceId);
41980
42185
  }
42186
+ async setVideoInputDevice(deviceId) {
42187
+ let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
42188
+ var _this__videoConfig;
42189
+ const devices = await getAudioDevices({
42190
+ video: true
42191
+ });
42192
+ if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
42193
+ await this.changeVideoState(false);
42194
+ if (isScreenShareDevice(deviceId)) {
42195
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN);
42196
+ if (isAutoCapture) {
42197
+ var _this__videoConfig1;
42198
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42199
+ await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
42200
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42201
+ }
42202
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
42203
+ } else {
42204
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_SCREEN);
42205
+ if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
42206
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_MAIN;
42207
+ }
42208
+ this.engine.setLocalVideoPlayer(this._streamIndex, {
42209
+ renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
42210
+ userId: this._roomUserId
42211
+ });
42212
+ }
41981
42213
  async createLocalStream(userId, videoConfig) {
42214
+ this._roomUserId = userId;
41982
42215
  const devices = await getAudioDevices({
41983
42216
  video: this._isSupportVideo
41984
42217
  });
41985
42218
  if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
41986
42219
  if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
41987
42220
  await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
41988
- if (this._isSupportVideo && (null == videoConfig ? void 0 : videoConfig.videoOnDefault)) await this.engine.startVideoCapture(devices.videoInputs[0].deviceId);
41989
- if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
41990
- renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
41991
- userId
41992
- });
42221
+ if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
41993
42222
  }
41994
42223
  async disconnect() {
41995
42224
  try {
41996
- if (this._isSupportVideo) await this.engine.stopVideoCapture();
41997
- await this.engine.stopAudioCapture();
42225
+ if (this._isSupportVideo) await this.changeVideoState(false);
42226
+ await this.changeAudioState(false);
41998
42227
  await this.engine.unpublishStream(MediaType$1.AUDIO);
41999
42228
  await this.engine.leaveRoom();
42000
42229
  this.removeEventListener();
@@ -42014,8 +42243,19 @@ class EngineClient extends RealtimeEventHandler {
42014
42243
  }
42015
42244
  async changeVideoState(isVideoOn) {
42016
42245
  try {
42017
- if (isVideoOn) await this.engine.startVideoCapture();
42018
- else await this.engine.stopVideoCapture();
42246
+ if (isVideoOn) {
42247
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
42248
+ else {
42249
+ var _this__videoConfig;
42250
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42251
+ await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
42252
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42253
+ }
42254
+ } else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
42255
+ else {
42256
+ await this.engine.stopScreenCapture();
42257
+ await this.engine.unpublishScreen(MediaType$1.VIDEO);
42258
+ }
42019
42259
  } catch (e) {
42020
42260
  this.dispatch(event_handler_EventNames.ERROR, e);
42021
42261
  throw e;
@@ -42092,8 +42332,11 @@ class EngineClient extends RealtimeEventHandler {
42092
42332
  throw e;
42093
42333
  }
42094
42334
  }
42335
+ getRtcEngine() {
42336
+ return this.engine;
42337
+ }
42095
42338
  // eslint-disable-next-line max-params
42096
- constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
42339
+ constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
42097
42340
  super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
42098
42341
  if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
42099
42342
  'rtc-test.bytedance.com'
@@ -42108,6 +42351,7 @@ class EngineClient extends RealtimeEventHandler {
42108
42351
  this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
42109
42352
  this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
42110
42353
  this._isSupportVideo = isSupportVideo;
42354
+ this._videoConfig = videoConfig;
42111
42355
  }
42112
42356
  }
42113
42357
  class RealtimeClient extends RealtimeEventHandler {
@@ -42123,16 +42367,17 @@ class RealtimeClient extends RealtimeEventHandler {
42123
42367
  // Step1 get token
42124
42368
  roomInfo = await this._api.audio.rooms.create({
42125
42369
  bot_id: botId,
42126
- conversation_id: conversationId,
42370
+ conversation_id: conversationId || void 0,
42127
42371
  voice_id: voiceId && voiceId.length > 0 ? voiceId : void 0,
42128
- connector_id: this._config.connectorId
42372
+ connector_id: this._config.connectorId,
42373
+ uid: this._config.userId || void 0
42129
42374
  });
42130
42375
  } catch (error) {
42131
42376
  this.dispatch(event_handler_EventNames.ERROR, error);
42132
42377
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
42133
42378
  }
42134
42379
  // Step2 create engine
42135
- this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
42380
+ this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
42136
42381
  // Step3 bind engine events
42137
42382
  this._client.bindEngineEvents();
42138
42383
  this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
@@ -42268,6 +42513,21 @@ class RealtimeClient extends RealtimeEventHandler {
42268
42513
  deviceId
42269
42514
  });
42270
42515
  }
42516
+ async setVideoInputDevice(deviceId) {
42517
+ var _this__client;
42518
+ await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
42519
+ this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
42520
+ deviceId
42521
+ });
42522
+ }
42523
+ /**
42524
+ * en: Get the RTC engine instance, for detail visit https://www.volcengine.com/docs/6348/104481
42525
+ *
42526
+ * zh: 获取 RTC 引擎实例,详情请访问 https://www.volcengine.com/docs/6348/104481
42527
+ */ getRtcEngine() {
42528
+ var _this__client;
42529
+ return null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.getRtcEngine();
42530
+ }
42271
42531
  /**
42272
42532
  * Constructor for initializing a RealtimeClient instance.
42273
42533
  *
@@ -42282,6 +42542,8 @@ class RealtimeClient extends RealtimeEventHandler {
42282
42542
  * 可选,音色Id。
42283
42543
  * @param config.conversationId - Optional, Conversation Id. |
42284
42544
  * 可选,会话Id。
42545
+ * @param config.userId - Optional, User Id. |
42546
+ * 可选,用户Id。
42285
42547
  * @param config.baseURL - Optional, defaults to "https://api.coze.cn". |
42286
42548
  * 可选,默认值为 "https://api.coze.cn"。
42287
42549
  * @param config.debug - Optional, defaults to false.
@@ -42298,6 +42560,16 @@ class RealtimeClient extends RealtimeEventHandler {
42298
42560
  * @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
42299
42561
  * 可选,默认是否抑制非静态噪声,默认值为 false。
42300
42562
  * @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
42563
+ * @param config.videoConfig - Optional, Video configuration. |
42564
+ * 可选,视频配置。
42565
+ * @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
42566
+ * 可选,默认是否开启视频,默认值为 true。
42567
+ * @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
42568
+ * 可选,渲染视频流的 DOM 元素。
42569
+ * @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
42570
+ * 可选,视频输入设备的设备 ID。
42571
+ * @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
42572
+ * 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
42301
42573
  */ constructor(config){
42302
42574
  super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
42303
42575
  this._config = config;
@@ -1,4 +1,4 @@
1
- import { type AudioPropertiesConfig, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
1
+ import { type AudioPropertiesConfig, type IRTCEngine, type onUserJoinedEvent, type onUserLeaveEvent, type UserMessageEvent } from '@volcengine/rtc';
2
2
  import { RealtimeEventHandler } from './event-handler';
3
3
  import { type VideoConfig } from '.';
4
4
  export declare class EngineClient extends RealtimeEventHandler {
@@ -6,7 +6,10 @@ export declare class EngineClient extends RealtimeEventHandler {
6
6
  private joinUserId;
7
7
  private _AIAnsExtension;
8
8
  private _isSupportVideo;
9
- constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean);
9
+ private _videoConfig?;
10
+ private _streamIndex?;
11
+ private _roomUserId?;
12
+ constructor(appId: string, debug?: boolean, isTestEnv?: boolean, isSupportVideo?: boolean, videoConfig?: VideoConfig);
10
13
  bindEngineEvents(): void;
11
14
  removeEventListener(): void;
12
15
  _parseMessage(event: UserMessageEvent): any;
@@ -25,6 +28,7 @@ export declare class EngineClient extends RealtimeEventHandler {
25
28
  }): Promise<void>;
26
29
  setAudioInputDevice(deviceId: string): Promise<void>;
27
30
  setAudioOutputDevice(deviceId: string): Promise<void>;
31
+ setVideoInputDevice(deviceId: string, isAutoCapture?: boolean): Promise<void>;
28
32
  createLocalStream(userId?: string, videoConfig?: VideoConfig): Promise<void>;
29
33
  disconnect(): Promise<void>;
30
34
  changeAudioState(isMicOn: boolean): Promise<void>;
@@ -39,4 +43,5 @@ export declare class EngineClient extends RealtimeEventHandler {
39
43
  changeAIAnsExtension(enable: boolean): void;
40
44
  startAudioPlaybackDeviceTest(): Promise<void>;
41
45
  stopAudioPlaybackDeviceTest(): void;
46
+ getRtcEngine(): IRTCEngine;
42
47
  }
@@ -79,6 +79,11 @@ export declare enum EventNames {
79
79
  * zh: 音频输出设备改变
80
80
  */
81
81
  AUDIO_OUTPUT_DEVICE_CHANGED = "client.output.device.changed",
82
+ /**
83
+ * en: Video input device changed
84
+ * zh: 视频输入设备改变
85
+ */
86
+ VIDEO_INPUT_DEVICE_CHANGED = "client.video.input.device.changed",
82
87
  /**
83
88
  * en: Bot joined
84
89
  * zh: Bot 加入