@coze/realtime-api 1.0.3 → 1.0.4

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,11 +7,11 @@
7
7
  })(self, ()=>(()=>{
8
8
  "use strict";
9
9
  var __webpack_modules__ = {
10
- "?c628": function() {
10
+ "?e272": function() {
11
11
  /* (ignored) */ },
12
- "?9452": function() {
12
+ "?5742": function() {
13
13
  /* (ignored) */ },
14
- "?e2b1": function() {
14
+ "?9caf": function() {
15
15
  /* (ignored) */ }
16
16
  };
17
17
  /************************************************************************/ // The module cache
@@ -86,7 +86,7 @@
86
86
  hasBrowserEnv: ()=>hasBrowserEnv,
87
87
  hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
88
88
  hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
89
- navigator: ()=>_navigator,
89
+ navigator: ()=>utils_navigator,
90
90
  origin: ()=>origin
91
91
  });
92
92
  // NAMESPACE OBJECT: ./src/utils.ts
@@ -96,6 +96,8 @@
96
96
  checkDevicePermission: ()=>checkDevicePermission,
97
97
  checkPermission: ()=>checkPermission,
98
98
  getAudioDevices: ()=>getAudioDevices,
99
+ isScreenShareDevice: ()=>isScreenShareDevice,
100
+ isScreenShareSupported: ()=>isScreenShareSupported,
99
101
  sleep: ()=>utils_sleep
100
102
  });
101
103
  function bind(fn, thisArg) {
@@ -1058,7 +1060,7 @@
1058
1060
  ]
1059
1061
  };
1060
1062
  const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
1061
- const _navigator = 'object' == typeof navigator && navigator || void 0;
1063
+ const utils_navigator = 'object' == typeof navigator && navigator || void 0;
1062
1064
  /**
1063
1065
  * Determine if we're running in a standard browser environment
1064
1066
  *
@@ -1075,11 +1077,11 @@
1075
1077
  * navigator.product -> 'NativeScript' or 'NS'
1076
1078
  *
1077
1079
  * @returns {boolean}
1078
- */ const hasStandardBrowserEnv = hasBrowserEnv && (!_navigator || [
1080
+ */ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
1079
1081
  'ReactNative',
1080
1082
  'NativeScript',
1081
1083
  'NS'
1082
- ].indexOf(_navigator.product) < 0);
1084
+ ].indexOf(utils_navigator.product) < 0);
1083
1085
  /**
1084
1086
  * Determine if we're running in a standard browser webWorker environment
1085
1087
  *
@@ -2864,11 +2866,11 @@
2864
2866
  // so that it can keep same with es module or cjs
2865
2867
  const { Axios: axios_Axios, AxiosError: axios_AxiosError, CanceledError: axios_CanceledError, isCancel: axios_isCancel, CancelToken: axios_CancelToken, VERSION: axios_VERSION, all: axios_all, Cancel, isAxiosError: axios_isAxiosError, spread: axios_spread, toFormData: axios_toFormData, AxiosHeaders: axios_AxiosHeaders, HttpStatusCode: axios_HttpStatusCode, formToJSON, getAdapter, mergeConfig: axios_mergeConfig } = lib_axios;
2866
2868
  // EXTERNAL MODULE: os (ignored)
2867
- var os_ignored_ = __webpack_require__("?e2b1");
2869
+ var os_ignored_ = __webpack_require__("?9caf");
2868
2870
  // EXTERNAL MODULE: crypto (ignored)
2869
- __webpack_require__("?c628");
2871
+ __webpack_require__("?e272");
2870
2872
  // EXTERNAL MODULE: jsonwebtoken (ignored)
2871
- __webpack_require__("?9452");
2873
+ __webpack_require__("?5742");
2872
2874
  class APIResource {
2873
2875
  constructor(client){
2874
2876
  this._client = client;
@@ -3668,9 +3670,9 @@
3668
3670
  * @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
3669
3671
  * @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
3670
3672
  * @returns ListDocumentData | 知识库文件列表
3671
- */ list(params, options) {
3673
+ */ async list(params, options) {
3672
3674
  const apiUrl = '/open_api/knowledge/document/list';
3673
- const response = this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
3675
+ const response = await this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
3674
3676
  headers: documents_documents_headers
3675
3677
  }));
3676
3678
  return response;
@@ -3719,9 +3721,104 @@
3719
3721
  }));
3720
3722
  }
3721
3723
  }
3724
+ class Images extends APIResource {
3725
+ /**
3726
+ * Update the description of an image in the knowledge base | 更新知识库中的图片描述
3727
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/update_image_caption?_lang=en
3728
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/update_image_caption?_lang=zh
3729
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3730
+ * @param documentId - The ID of the document | 必选 知识库文件 ID
3731
+ * @param params - The parameters for updating the image
3732
+ * @param params.caption - Required. The description of the image | 必选 图片的描述信息
3733
+ * @returns undefined
3734
+ */ // eslint-disable-next-line max-params
3735
+ async update(datasetId, documentId, params, options) {
3736
+ const apiUrl = `/v1/datasets/${datasetId}/images/${documentId}`;
3737
+ await this._client.put(apiUrl, params, false, options);
3738
+ }
3739
+ /**
3740
+ * List images in the knowledge base | 列出知识库中的图片
3741
+ * @docs en: https://www.coze.com/docs/developer_guides/developer_guides/get_images?_lang=en
3742
+ * @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/get_images?_lang=zh
3743
+ * @param datasetId - The ID of the dataset | 必选 知识库 ID
3744
+ * @param params - The parameters for listing images
3745
+ * @param params.page_num - Optional. Page number for pagination, minimum value is 1, defaults to 1 | 可选 分页查询时的页码。默认为 1。
3746
+ * @param params.page_size - Optional. Number of items per page, range 1-299, defaults to 10 | 可选 分页大小。默认为 10。
3747
+ * @param params.keyword - Optional. Search keyword for image descriptions | 可选 图片描述的搜索关键词。
3748
+ * @param params.has_caption - Optional. Filter for images with/without captions | 可选 是否过滤有/无描述的图片。
3749
+ */ async list(datasetId, params, options) {
3750
+ const apiUrl = `/v1/datasets/${datasetId}/images`;
3751
+ const response = await this._client.get(apiUrl, params, false, options);
3752
+ return response.data;
3753
+ }
3754
+ }
3722
3755
  class Datasets extends APIResource {
3756
+ /**
3757
+ * Creates a new dataset | 创建数据集
3758
+ * @docs en: https://www.coze.com/docs/developer_guides/create_dataset?_lang=en
3759
+ * @docs zh: https://www.coze.cn/docs/developer_guides/create_dataset?_lang=zh
3760
+ * @param params - The parameters for creating a dataset
3761
+ * @param {string} params.name - Required. Dataset name, maximum length of 100 characters | 必选 数据集名称,最大长度为 100 个字符
3762
+ * @param {string} params.space_id - Required. Space ID where the dataset belongs | 必选 数据集所属的空间 ID
3763
+ * @param {number} params.format_type - Required. Dataset type (0: Text type, 2: Image type) | 必选 数据集类型 (0: 文本类型, 2: 图片类型)
3764
+ * @param {string} [params.description] - Optional. Dataset description | 可选 数据集描述
3765
+ * @param {string} [params.file_id] - Optional. Dataset icon file ID from file upload
3766
+ */ async create(params, options) {
3767
+ const apiUrl = '/v1/datasets';
3768
+ const response = await this._client.post(apiUrl, params, false, options);
3769
+ return response.data;
3770
+ }
3771
+ /**
3772
+ * Lists all datasets in a space | 列出空间中的所有数据集
3773
+ * @docs en: https://www.coze.com/docs/developer_guides/list_dataset?_lang=en
3774
+ * @docs zh: https://www.coze.cn/docs/developer_guides/list_dataset?_lang=zh
3775
+ * @param params - The parameters for listing datasets | 列出数据集的参数
3776
+ * @param {string} params.space_id - Required. Space ID where the datasets belong | 必选 数据集所属的空间 ID
3777
+ * @param {string} [params.name] - Optional. Dataset name for fuzzy search | 可选 数据集名称用于模糊搜索
3778
+ * @param {number} [params.format_type] - Optional. Dataset type (0: Text type, 2: Image type) | 可选 数据集类型 (0: 文本类型, 2: 图片类型)
3779
+ * @param {number} [params.page_num] - Optional. Page number for pagination (default: 1) | 可选 分页查询时的页码。默认为 1。
3780
+ * @param {number} [params.page_size] - Optional. Number of items per page (default: 10) | 可选 分页大小。默认为 10。
3781
+ */ async list(params, options) {
3782
+ const apiUrl = '/v1/datasets';
3783
+ const response = await this._client.get(apiUrl, params, false, options);
3784
+ return response.data;
3785
+ }
3786
+ /**
3787
+ * Updates a dataset | 更新数据集
3788
+ * @docs en: https://www.coze.com/docs/developer_guides/update_dataset?_lang=en
3789
+ * @docs zh: https://www.coze.cn/docs/developer_guides/update_dataset?_lang=zh
3790
+ * @param dataset_id - Required. The ID of the dataset to update | 必选 数据集 ID
3791
+ * @param params - Required. The parameters for updating the dataset | 必选 更新数据集的参数
3792
+ * @param params.name - Required. Dataset name, maximum length of 100 characters. | 必选 数据集名称,最大长度为 100 个字符。
3793
+ * @param params.file_id - Optional. Dataset icon, should pass the file_id obtained from the file upload interface. | 可选 数据集图标,应传递从文件上传接口获取的 file_id。
3794
+ * @param params.description - Optional. Dataset description. | 可选 数据集描述。
3795
+ */ async update(dataset_id, params, options) {
3796
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3797
+ await this._client.put(apiUrl, params, false, options);
3798
+ }
3799
+ /**
3800
+ * Deletes a dataset | 删除数据集
3801
+ * @docs en: https://www.coze.com/docs/developer_guides/delete_dataset?_lang=en
3802
+ * @docs zh: https://www.coze.cn/docs/developer_guides/delete_dataset?_lang=zh
3803
+ * @param dataset_id - Required. The ID of the dataset to delete | 必选 数据集 ID
3804
+ */ async delete(dataset_id, options) {
3805
+ const apiUrl = `/v1/datasets/${dataset_id}`;
3806
+ await this._client.delete(apiUrl, false, options);
3807
+ }
3808
+ /**
3809
+ * Views the progress of dataset upload | 查看数据集上传进度
3810
+ * @docs en: https://www.coze.com/docs/developer_guides/get_dataset_progress?_lang=en
3811
+ * @docs zh: https://www.coze.cn/docs/developer_guides/get_dataset_progress?_lang=zh
3812
+ * @param dataset_id - Required. The ID of the dataset to process | 必选 数据集 ID
3813
+ * @param params - Required. The parameters for processing the dataset | 必选 处理数据集的参数
3814
+ * @param params.dataset_ids - Required. List of dataset IDs | 必选 数据集 ID 列表
3815
+ */ async process(dataset_id, params, options) {
3816
+ const apiUrl = `/v1/datasets/${dataset_id}/process`;
3817
+ const response = await this._client.post(apiUrl, params, false, options);
3818
+ return response.data;
3819
+ }
3723
3820
  constructor(...args){
3724
- super(...args), this.documents = new documents_Documents(this._client);
3821
+ super(...args), this.documents = new documents_Documents(this._client), this.images = new Images(this._client);
3725
3822
  }
3726
3823
  }
3727
3824
  class Voices extends APIResource {
@@ -3778,7 +3875,10 @@
3778
3875
  * @returns Speech synthesis data
3779
3876
  */ async create(params, options) {
3780
3877
  const apiUrl = '/v1/audio/speech';
3781
- const response = await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
3878
+ const response = await this._client.post(apiUrl, {
3879
+ ...params,
3880
+ sample_rate: params.sample_rate || 24000
3881
+ }, false, esm_mergeConfig(options, {
3782
3882
  responseType: 'arraybuffer'
3783
3883
  }));
3784
3884
  return response;
@@ -3796,7 +3896,21 @@
3796
3896
  super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
3797
3897
  }
3798
3898
  }
3799
- var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.15","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":{".":{"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","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"dist/types/index.d.ts","files":["dist","LICENSE","README.md","!**/*.tsbuildinfo"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","prepublishOnly":"npm run build","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"}}'); // CONCATENATED MODULE: ./src/version.ts
3899
+ class Templates extends APIResource {
3900
+ /**
3901
+ * Duplicate a template. | 复制一个模板。
3902
+ * @param templateId - Required. The ID of the template to duplicate. | 要复制的模板的 ID。
3903
+ * @param params - Optional. The parameters for the duplicate operation. | 可选参数,用于复制操作。
3904
+ * @param params.workspace_id - Required. The ID of the workspace to duplicate the template into. | 要复制到的目标工作空间的 ID。
3905
+ * @param params.name - Optional. The name of the new template. | 新模板的名称。
3906
+ * @returns TemplateDuplicateRes | 复制模板结果
3907
+ */ async duplicate(templateId, params, options) {
3908
+ const apiUrl = `/v1/templates/${templateId}/duplicate`;
3909
+ const response = await this._client.post(apiUrl, params, false, options);
3910
+ return response.data;
3911
+ }
3912
+ }
3913
+ 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":{".":{"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","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"dist/types/index.d.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"}}'); // CONCATENATED MODULE: ./src/version.ts
3800
3914
  const { version: esm_version } = package_namespaceObject;
3801
3915
  const getEnv = ()=>{
3802
3916
  const nodeVersion = process.version.slice(1); // Remove 'v' prefix
@@ -3846,6 +3960,55 @@
3846
3960
  };
3847
3961
  return JSON.stringify(ua);
3848
3962
  };
3963
+ const getBrowserClientUserAgent = ()=>{
3964
+ const browserInfo = {
3965
+ name: 'unknown',
3966
+ version: 'unknown'
3967
+ };
3968
+ const osInfo = {
3969
+ name: 'unknown',
3970
+ version: 'unknown'
3971
+ };
3972
+ const { userAgent } = navigator;
3973
+ // 检测操作系统及版本
3974
+ if (userAgent.indexOf('Windows') > -1) {
3975
+ var _userAgent_match;
3976
+ osInfo.name = 'windows';
3977
+ const windowsVersion = (null === (_userAgent_match = userAgent.match(/Windows NT ([0-9.]+)/)) || void 0 === _userAgent_match ? void 0 : _userAgent_match[1]) || 'unknown';
3978
+ osInfo.version = windowsVersion;
3979
+ } else if (userAgent.indexOf('Mac OS X') > -1) {
3980
+ var _userAgent_match1;
3981
+ osInfo.name = 'macos';
3982
+ // 将 10_15_7 格式转换为 10.15.7
3983
+ osInfo.version = ((null === (_userAgent_match1 = userAgent.match(/Mac OS X ([0-9_]+)/)) || void 0 === _userAgent_match1 ? void 0 : _userAgent_match1[1]) || 'unknown').replace(/_/g, '.');
3984
+ } else if (userAgent.indexOf('Linux') > -1) {
3985
+ var _userAgent_match2;
3986
+ osInfo.name = 'linux';
3987
+ osInfo.version = (null === (_userAgent_match2 = userAgent.match(/Linux ([0-9.]+)/)) || void 0 === _userAgent_match2 ? void 0 : _userAgent_match2[1]) || 'unknown';
3988
+ }
3989
+ // 检测浏览器及版本
3990
+ if (userAgent.indexOf('Chrome') > -1) {
3991
+ var _userAgent_match3;
3992
+ browserInfo.name = 'chrome';
3993
+ browserInfo.version = (null === (_userAgent_match3 = userAgent.match(/Chrome\/([0-9.]+)/)) || void 0 === _userAgent_match3 ? void 0 : _userAgent_match3[1]) || 'unknown';
3994
+ } else if (userAgent.indexOf('Firefox') > -1) {
3995
+ var _userAgent_match4;
3996
+ browserInfo.name = 'firefox';
3997
+ browserInfo.version = (null === (_userAgent_match4 = userAgent.match(/Firefox\/([0-9.]+)/)) || void 0 === _userAgent_match4 ? void 0 : _userAgent_match4[1]) || 'unknown';
3998
+ } else if (userAgent.indexOf('Safari') > -1) {
3999
+ var _userAgent_match5;
4000
+ browserInfo.name = 'safari';
4001
+ browserInfo.version = (null === (_userAgent_match5 = userAgent.match(/Version\/([0-9.]+)/)) || void 0 === _userAgent_match5 ? void 0 : _userAgent_match5[1]) || 'unknown';
4002
+ }
4003
+ const ua = {
4004
+ version: esm_version,
4005
+ browser: browserInfo.name,
4006
+ browser_version: browserInfo.version,
4007
+ os_name: osInfo.name,
4008
+ os_version: osInfo.version
4009
+ };
4010
+ return JSON.stringify(ua);
4011
+ };
3849
4012
  /* eslint-disable @typescript-eslint/no-explicit-any */ const esm_handleError = (error)=>{
3850
4013
  if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
3851
4014
  if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
@@ -3943,7 +4106,8 @@
3943
4106
  const headers = {
3944
4107
  authorization: `Bearer ${token}`
3945
4108
  };
3946
- if (!isBrowser()) {
4109
+ if (isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
4110
+ else {
3947
4111
  headers['User-Agent'] = getUserAgent();
3948
4112
  headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
3949
4113
  }
@@ -4035,7 +4199,7 @@
4035
4199
  constructor(...args){
4036
4200
  super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
4037
4201
  * @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 esm_Audio(this);
4202
+ */ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new esm_Audio(this), this.templates = new Templates(this);
4039
4203
  }
4040
4204
  }
4041
4205
  /**
@@ -9267,7 +9431,7 @@
9267
9431
  }, stringPad = {
9268
9432
  start: createMethod(!1),
9269
9433
  end: createMethod(!0)
9270
- }, userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
9434
+ }, index_esm_min_userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(index_esm_min_userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
9271
9435
  $$F({
9272
9436
  target: "String",
9273
9437
  proto: !0,
@@ -38440,7 +38604,11 @@
38440
38604
  return false;
38441
38605
  }
38442
38606
  };
38443
- const checkDevicePermission = async function() {
38607
+ /**
38608
+ * Checks device permissions for audio and video
38609
+ * @param checkVideo Whether to check video permissions (default: false)
38610
+ * @returns Promise that resolves with the device permission status
38611
+ */ const checkDevicePermission = async function() {
38444
38612
  let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
38445
38613
  return await index_esm_min_index.enableDevices({
38446
38614
  audio: true,
@@ -38453,7 +38621,16 @@
38453
38621
  */ const getAudioDevices = async function() {
38454
38622
  let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
38455
38623
  let devices = [];
38456
- devices = video ? await index_esm_min_index.enumerateDevices() : await [
38624
+ if (video) {
38625
+ devices = await index_esm_min_index.enumerateDevices();
38626
+ if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
38627
+ devices.push({
38628
+ deviceId: 'screenShare',
38629
+ kind: 'videoinput',
38630
+ label: 'Screen Share',
38631
+ groupId: 'screenShare'
38632
+ });
38633
+ } else devices = await [
38457
38634
  ...await index_esm_min_index.enumerateAudioCaptureDevices(),
38458
38635
  ...await index_esm_min_index.enumerateAudioPlaybackDevices()
38459
38636
  ];
@@ -38468,6 +38645,14 @@
38468
38645
  videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
38469
38646
  };
38470
38647
  };
38648
+ const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
38649
+ /**
38650
+ * Check if browser supports screen sharing
38651
+ * 检查浏览器是否支持屏幕共享
38652
+ */ function isScreenShareSupported() {
38653
+ var _navigator_mediaDevices, _navigator;
38654
+ return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
38655
+ }
38471
38656
  var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
38472
38657
  RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
38473
38658
  RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
@@ -38561,6 +38746,10 @@
38561
38746
  * zh: 音频输出设备改变
38562
38747
  */ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
38563
38748
  /**
38749
+ * en: Video input device changed
38750
+ * zh: 视频输入设备改变
38751
+ */ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
38752
+ /**
38564
38753
  * en: Bot joined
38565
38754
  * zh: Bot 加入
38566
38755
  */ EventNames["BOT_JOIN"] = "server.bot.join";
@@ -41978,23 +42167,47 @@
41978
42167
  if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
41979
42168
  await this.engine.setAudioPlaybackDevice(deviceId);
41980
42169
  }
42170
+ async setVideoInputDevice(deviceId) {
42171
+ let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
42172
+ var _this__videoConfig;
42173
+ const devices = await getAudioDevices({
42174
+ video: true
42175
+ });
42176
+ if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
42177
+ await this.changeVideoState(false);
42178
+ if (isScreenShareDevice(deviceId)) {
42179
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN);
42180
+ if (isAutoCapture) {
42181
+ var _this__videoConfig1;
42182
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42183
+ await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
42184
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42185
+ }
42186
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
42187
+ } else {
42188
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_SCREEN);
42189
+ if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
42190
+ this._streamIndex = StreamIndex$1.STREAM_INDEX_MAIN;
42191
+ }
42192
+ this.engine.setLocalVideoPlayer(this._streamIndex, {
42193
+ renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
42194
+ userId: this._roomUserId
42195
+ });
42196
+ }
41981
42197
  async createLocalStream(userId, videoConfig) {
42198
+ this._roomUserId = userId;
41982
42199
  const devices = await getAudioDevices({
41983
42200
  video: this._isSupportVideo
41984
42201
  });
41985
42202
  if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
41986
42203
  if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
41987
42204
  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
- });
42205
+ if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
41993
42206
  }
41994
42207
  async disconnect() {
41995
42208
  try {
41996
- if (this._isSupportVideo) await this.engine.stopVideoCapture();
41997
- await this.engine.stopAudioCapture();
42209
+ if (this._isSupportVideo) await this.changeVideoState(false);
42210
+ await this.changeAudioState(false);
41998
42211
  await this.engine.unpublishStream(MediaType$1.AUDIO);
41999
42212
  await this.engine.leaveRoom();
42000
42213
  this.removeEventListener();
@@ -42014,8 +42227,19 @@
42014
42227
  }
42015
42228
  async changeVideoState(isVideoOn) {
42016
42229
  try {
42017
- if (isVideoOn) await this.engine.startVideoCapture();
42018
- else await this.engine.stopVideoCapture();
42230
+ if (isVideoOn) {
42231
+ if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
42232
+ else {
42233
+ var _this__videoConfig;
42234
+ this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
42235
+ await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
42236
+ await this.engine.publishScreen(MediaType$1.VIDEO);
42237
+ }
42238
+ } else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
42239
+ else {
42240
+ await this.engine.stopScreenCapture();
42241
+ await this.engine.unpublishScreen(MediaType$1.VIDEO);
42242
+ }
42019
42243
  } catch (e) {
42020
42244
  this.dispatch(event_handler_EventNames.ERROR, e);
42021
42245
  throw e;
@@ -42093,7 +42317,7 @@
42093
42317
  }
42094
42318
  }
42095
42319
  // eslint-disable-next-line max-params
42096
- constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
42320
+ constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
42097
42321
  super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
42098
42322
  if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
42099
42323
  'rtc-test.bytedance.com'
@@ -42108,6 +42332,7 @@
42108
42332
  this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
42109
42333
  this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
42110
42334
  this._isSupportVideo = isSupportVideo;
42335
+ this._videoConfig = videoConfig;
42111
42336
  }
42112
42337
  }
42113
42338
  class RealtimeClient extends RealtimeEventHandler {
@@ -42132,7 +42357,7 @@
42132
42357
  throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
42133
42358
  }
42134
42359
  // Step2 create engine
42135
- this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
42360
+ this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
42136
42361
  // Step3 bind engine events
42137
42362
  this._client.bindEngineEvents();
42138
42363
  this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
@@ -42268,6 +42493,13 @@
42268
42493
  deviceId
42269
42494
  });
42270
42495
  }
42496
+ async setVideoInputDevice(deviceId) {
42497
+ var _this__client;
42498
+ await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
42499
+ this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
42500
+ deviceId
42501
+ });
42502
+ }
42271
42503
  /**
42272
42504
  * Constructor for initializing a RealtimeClient instance.
42273
42505
  *
@@ -42298,6 +42530,16 @@
42298
42530
  * @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
42299
42531
  * 可选,默认是否抑制非静态噪声,默认值为 false。
42300
42532
  * @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
42533
+ * @param config.videoConfig - Optional, Video configuration. |
42534
+ * 可选,视频配置。
42535
+ * @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
42536
+ * 可选,默认是否开启视频,默认值为 true。
42537
+ * @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
42538
+ * 可选,渲染视频流的 DOM 元素。
42539
+ * @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
42540
+ * 可选,视频输入设备的设备 ID。
42541
+ * @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
42542
+ * 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
42301
42543
  */ constructor(config){
42302
42544
  super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
42303
42545
  this._config = config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze/realtime-api",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互",
5
5
  "keywords": [
6
6
  "coze",
@@ -31,13 +31,13 @@
31
31
  },
32
32
  "main": "dist/cjs/index.cjs",
33
33
  "module": "dist/esm/index.js",
34
+ "types": "./src/index.ts",
34
35
  "typings": "dist/types/index.d.ts",
35
36
  "files": [
36
37
  "dist",
37
- "assets",
38
38
  "LICENSE",
39
- "!**/*.tsbuildinfo",
40
- "README.md"
39
+ "README.md",
40
+ "README.zh-CN.md"
41
41
  ],
42
42
  "scripts": {
43
43
  "build": "rm -rf ./dist && rslib build",
@@ -45,13 +45,12 @@
45
45
  "demo": "npm run start & cd ../../examples/realtime-console && npm run start",
46
46
  "format": "prettier --write .",
47
47
  "lint": "eslint ./ --cache --quiet",
48
- "prepublishOnly": "npm run build",
49
48
  "start": "rm -rf dist && rslib build -w",
50
49
  "test": "vitest",
51
50
  "test:cov": "vitest --coverage --run"
52
51
  },
53
52
  "dependencies": {
54
- "@coze/api": "1.0.15",
53
+ "@coze/api": "1.0.16",
55
54
  "@volcengine/rtc": "^4.62.1"
56
55
  },
57
56
  "devDependencies": {
@@ -67,8 +66,5 @@
67
66
  "axios": "^1.7.7",
68
67
  "typescript": "^5.5.3",
69
68
  "vitest": "~2.1.4"
70
- },
71
- "peerDependencies": {
72
- "axios": "^1.7.1"
73
69
  }
74
- }
70
+ }
Binary file