@coze/realtime-api 1.0.4-beta.1 → 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/README.md +6 -0
- package/README.zh-CN.md +104 -0
- package/dist/cjs/{index.js → index.cjs} +1544 -1320
- package/dist/esm/{index.mjs → index.js} +1544 -1320
- package/dist/types/client.d.ts +5 -1
- package/dist/types/event-handler.d.ts +5 -0
- package/dist/types/index.d.ts +14 -1
- package/dist/types/utils.d.ts +11 -0
- package/dist/umd/index.js +1543 -1319
- package/package.json +15 -27
- /package/dist/cjs/{index.js.LICENSE.txt → index.cjs.LICENSE.txt} +0 -0
- /package/dist/esm/{index.mjs.LICENSE.txt → index.js.LICENSE.txt} +0 -0
package/dist/umd/index.js
CHANGED
@@ -7,11 +7,11 @@
|
|
7
7
|
})(self, ()=>(()=>{
|
8
8
|
"use strict";
|
9
9
|
var __webpack_modules__ = {
|
10
|
-
"?
|
10
|
+
"?e272": function() {
|
11
11
|
/* (ignored) */ },
|
12
|
-
"?
|
12
|
+
"?5742": function() {
|
13
13
|
/* (ignored) */ },
|
14
|
-
"?
|
14
|
+
"?9caf": function() {
|
15
15
|
/* (ignored) */ }
|
16
16
|
};
|
17
17
|
/************************************************************************/ // The module cache
|
@@ -30,22 +30,7 @@
|
|
30
30
|
// Return the exports of the module
|
31
31
|
return module1.exports;
|
32
32
|
}
|
33
|
-
/************************************************************************/ // webpack/runtime/
|
34
|
-
(()=>{
|
35
|
-
// getDefaultExport function for compatibility with non-ESM modules
|
36
|
-
__webpack_require__.n = function(module1) {
|
37
|
-
var getter = module1 && module1.__esModule ? function() {
|
38
|
-
return module1['default'];
|
39
|
-
} : function() {
|
40
|
-
return module1;
|
41
|
-
};
|
42
|
-
__webpack_require__.d(getter, {
|
43
|
-
a: getter
|
44
|
-
});
|
45
|
-
return getter;
|
46
|
-
};
|
47
|
-
})();
|
48
|
-
// webpack/runtime/define_property_getters
|
33
|
+
/************************************************************************/ // webpack/runtime/define_property_getters
|
49
34
|
(()=>{
|
50
35
|
__webpack_require__.d = function(exports1, definition) {
|
51
36
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
@@ -101,7 +86,7 @@
|
|
101
86
|
hasBrowserEnv: ()=>hasBrowserEnv,
|
102
87
|
hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
|
103
88
|
hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
|
104
|
-
navigator: ()=>
|
89
|
+
navigator: ()=>utils_navigator,
|
105
90
|
origin: ()=>origin
|
106
91
|
});
|
107
92
|
// NAMESPACE OBJECT: ./src/utils.ts
|
@@ -111,968 +96,409 @@
|
|
111
96
|
checkDevicePermission: ()=>checkDevicePermission,
|
112
97
|
checkPermission: ()=>checkPermission,
|
113
98
|
getAudioDevices: ()=>getAudioDevices,
|
114
|
-
|
99
|
+
isScreenShareDevice: ()=>isScreenShareDevice,
|
100
|
+
isScreenShareSupported: ()=>isScreenShareSupported,
|
101
|
+
sleep: ()=>utils_sleep
|
115
102
|
});
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
}
|
121
|
-
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
122
|
-
/**
|
123
|
-
* Create a new agent. | 调用接口创建一个新的智能体。
|
124
|
-
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
125
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
126
|
-
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
127
|
-
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
128
|
-
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
129
|
-
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
130
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
131
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
132
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
133
|
-
* @returns Information about the created bot. | 创建的 Bot 信息。
|
134
|
-
*/ async create(params, options) {
|
135
|
-
const apiUrl = '/v1/bot/create';
|
136
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
137
|
-
return result.data;
|
138
|
-
}
|
139
|
-
/**
|
140
|
-
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
141
|
-
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
142
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
143
|
-
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
144
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
145
|
-
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
146
|
-
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
147
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
148
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
149
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
150
|
-
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
151
|
-
* @returns Undefined | 无返回值
|
152
|
-
*/ async update(params, options) {
|
153
|
-
const apiUrl = '/v1/bot/update';
|
154
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
155
|
-
return result.data;
|
156
|
-
}
|
157
|
-
/**
|
158
|
-
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
159
|
-
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
160
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
161
|
-
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
162
|
-
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
163
|
-
* @param params.page_size - Optional Pagination size. | 分页大小。
|
164
|
-
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
165
|
-
* @returns List of published bots. | 已发布的 Bot 列表。
|
166
|
-
*/ async list(params, options) {
|
167
|
-
const apiUrl = '/v1/space/published_bots_list';
|
168
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
169
|
-
return result.data;
|
170
|
-
}
|
171
|
-
/**
|
172
|
-
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
173
|
-
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
174
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
175
|
-
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
176
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
177
|
-
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
178
|
-
* @returns Undefined | 无返回值
|
179
|
-
*/ async publish(params, options) {
|
180
|
-
const apiUrl = '/v1/bot/publish';
|
181
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
182
|
-
return result.data;
|
183
|
-
}
|
184
|
-
/**
|
185
|
-
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
186
|
-
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
187
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
188
|
-
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
189
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
190
|
-
* @returns Information about the bot. | Bot 的配置信息。
|
191
|
-
*/ async retrieve(params, options) {
|
192
|
-
const apiUrl = '/v1/bot/get_online_info';
|
193
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
194
|
-
return result.data;
|
195
|
-
}
|
196
|
-
}
|
197
|
-
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
198
|
-
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
199
|
-
try {
|
200
|
-
return JSON.parse(jsonString);
|
201
|
-
} catch (error) {
|
202
|
-
return defaultValue;
|
203
|
-
}
|
204
|
-
}
|
205
|
-
function utils_sleep(ms) {
|
206
|
-
return new Promise((resolve)=>{
|
207
|
-
setTimeout(resolve, ms);
|
208
|
-
});
|
209
|
-
}
|
210
|
-
function utils_isBrowser() {
|
211
|
-
return 'undefined' != typeof window;
|
212
|
-
}
|
213
|
-
function isPlainObject(obj) {
|
214
|
-
if ('object' != typeof obj || null === obj) return false;
|
215
|
-
const proto = Object.getPrototypeOf(obj);
|
216
|
-
if (null === proto) return true;
|
217
|
-
let baseProto = proto;
|
218
|
-
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
219
|
-
return proto === baseProto;
|
220
|
-
}
|
221
|
-
function mergeConfig() {
|
222
|
-
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
223
|
-
return objects.reduce((result, obj)=>{
|
224
|
-
if (void 0 === obj) return result || {};
|
225
|
-
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
226
|
-
if (isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = mergeConfig(result[key] || {}, obj[key]);
|
227
|
-
else result[key] = obj[key];
|
228
|
-
}
|
229
|
-
return result;
|
230
|
-
}, {});
|
103
|
+
function bind(fn, thisArg) {
|
104
|
+
return function() {
|
105
|
+
return fn.apply(thisArg, arguments);
|
106
|
+
};
|
231
107
|
}
|
232
|
-
|
233
|
-
|
108
|
+
// utils is a library of generic helper functions non-specific to axios
|
109
|
+
const { toString: utils_toString } = Object.prototype;
|
110
|
+
const { getPrototypeOf } = Object;
|
111
|
+
const kindOf = ((cache)=>(thing)=>{
|
112
|
+
const str = utils_toString.call(thing);
|
113
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
114
|
+
})(Object.create(null));
|
115
|
+
const kindOfTest = (type)=>{
|
116
|
+
type = type.toLowerCase();
|
117
|
+
return (thing)=>kindOf(thing) === type;
|
118
|
+
};
|
119
|
+
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
120
|
+
/**
|
121
|
+
* Determine if a value is an Array
|
122
|
+
*
|
123
|
+
* @param {Object} val The value to test
|
124
|
+
*
|
125
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
126
|
+
*/ const { isArray } = Array;
|
127
|
+
/**
|
128
|
+
* Determine if a value is undefined
|
129
|
+
*
|
130
|
+
* @param {*} val The value to test
|
131
|
+
*
|
132
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
133
|
+
*/ const isUndefined = typeOfTest('undefined');
|
134
|
+
/**
|
135
|
+
* Determine if a value is a Buffer
|
136
|
+
*
|
137
|
+
* @param {*} val The value to test
|
138
|
+
*
|
139
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
140
|
+
*/ function isBuffer(val) {
|
141
|
+
return null !== val && !isUndefined(val) && null !== val.constructor && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
234
142
|
}
|
235
|
-
|
143
|
+
/**
|
144
|
+
* Determine if a value is an ArrayBuffer
|
145
|
+
*
|
146
|
+
* @param {*} val The value to test
|
147
|
+
*
|
148
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
149
|
+
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
150
|
+
/**
|
151
|
+
* Determine if a value is a view on an ArrayBuffer
|
152
|
+
*
|
153
|
+
* @param {*} val The value to test
|
154
|
+
*
|
155
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
156
|
+
*/ function isArrayBufferView(val) {
|
157
|
+
let result;
|
158
|
+
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
159
|
+
return result;
|
236
160
|
}
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
161
|
+
/**
|
162
|
+
* Determine if a value is a String
|
163
|
+
*
|
164
|
+
* @param {*} val The value to test
|
165
|
+
*
|
166
|
+
* @returns {boolean} True if value is a String, otherwise false
|
167
|
+
*/ const isString = typeOfTest('string');
|
168
|
+
/**
|
169
|
+
* Determine if a value is a Function
|
170
|
+
*
|
171
|
+
* @param {*} val The value to test
|
172
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
173
|
+
*/ const isFunction = typeOfTest('function');
|
174
|
+
/**
|
175
|
+
* Determine if a value is a Number
|
176
|
+
*
|
177
|
+
* @param {*} val The value to test
|
178
|
+
*
|
179
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
180
|
+
*/ const isNumber = typeOfTest('number');
|
181
|
+
/**
|
182
|
+
* Determine if a value is an Object
|
183
|
+
*
|
184
|
+
* @param {*} thing The value to test
|
185
|
+
*
|
186
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
187
|
+
*/ const isObject = (thing)=>null !== thing && 'object' == typeof thing;
|
188
|
+
/**
|
189
|
+
* Determine if a value is a Boolean
|
190
|
+
*
|
191
|
+
* @param {*} thing The value to test
|
192
|
+
* @returns {boolean} True if value is a Boolean, otherwise false
|
193
|
+
*/ const isBoolean = (thing)=>true === thing || false === thing;
|
194
|
+
/**
|
195
|
+
* Determine if a value is a plain Object
|
196
|
+
*
|
197
|
+
* @param {*} val The value to test
|
198
|
+
*
|
199
|
+
* @returns {boolean} True if value is a plain Object, otherwise false
|
200
|
+
*/ const isPlainObject = (val)=>{
|
201
|
+
if ('object' !== kindOf(val)) return false;
|
202
|
+
const prototype = getPrototypeOf(val);
|
203
|
+
return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
204
|
+
};
|
205
|
+
/**
|
206
|
+
* Determine if a value is a Date
|
207
|
+
*
|
208
|
+
* @param {*} val The value to test
|
209
|
+
*
|
210
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
211
|
+
*/ const isDate = kindOfTest('Date');
|
212
|
+
/**
|
213
|
+
* Determine if a value is a File
|
214
|
+
*
|
215
|
+
* @param {*} val The value to test
|
216
|
+
*
|
217
|
+
* @returns {boolean} True if value is a File, otherwise false
|
218
|
+
*/ const isFile = kindOfTest('File');
|
219
|
+
/**
|
220
|
+
* Determine if a value is a Blob
|
221
|
+
*
|
222
|
+
* @param {*} val The value to test
|
223
|
+
*
|
224
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
225
|
+
*/ const isBlob = kindOfTest('Blob');
|
226
|
+
/**
|
227
|
+
* Determine if a value is a FileList
|
228
|
+
*
|
229
|
+
* @param {*} val The value to test
|
230
|
+
*
|
231
|
+
* @returns {boolean} True if value is a File, otherwise false
|
232
|
+
*/ const utils_isFileList = kindOfTest('FileList');
|
233
|
+
/**
|
234
|
+
* Determine if a value is a Stream
|
235
|
+
*
|
236
|
+
* @param {*} val The value to test
|
237
|
+
*
|
238
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
239
|
+
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
240
|
+
/**
|
241
|
+
* Determine if a value is a FormData
|
242
|
+
*
|
243
|
+
* @param {*} thing The value to test
|
244
|
+
*
|
245
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
246
|
+
*/ const utils_isFormData = (thing)=>{
|
247
|
+
let kind;
|
248
|
+
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
249
|
+
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
250
|
+
};
|
251
|
+
/**
|
252
|
+
* Determine if a value is a URLSearchParams object
|
253
|
+
*
|
254
|
+
* @param {*} val The value to test
|
255
|
+
*
|
256
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
257
|
+
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
258
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
259
|
+
'ReadableStream',
|
260
|
+
'Request',
|
261
|
+
'Response',
|
262
|
+
'Headers'
|
263
|
+
].map(kindOfTest);
|
264
|
+
/**
|
265
|
+
* Trim excess whitespace off the beginning and end of a string
|
266
|
+
*
|
267
|
+
* @param {String} str The String to trim
|
268
|
+
*
|
269
|
+
* @returns {String} The String freed of excess whitespace
|
270
|
+
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
271
|
+
/**
|
272
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
273
|
+
*
|
274
|
+
* If `obj` is an Array callback will be called passing
|
275
|
+
* the value, index, and complete array for each item.
|
276
|
+
*
|
277
|
+
* If 'obj' is an Object callback will be called passing
|
278
|
+
* the value, key, and complete object for each property.
|
279
|
+
*
|
280
|
+
* @param {Object|Array} obj The object to iterate
|
281
|
+
* @param {Function} fn The callback to invoke for each item
|
282
|
+
*
|
283
|
+
* @param {Boolean} [allOwnKeys = false]
|
284
|
+
* @returns {any}
|
285
|
+
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
286
|
+
// Don't bother if no value provided
|
287
|
+
if (null == obj) return;
|
288
|
+
let i;
|
289
|
+
let l;
|
290
|
+
// Force an array if not already something iterable
|
291
|
+
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
292
|
+
obj
|
293
|
+
];
|
294
|
+
if (isArray(obj)) // Iterate over array values
|
295
|
+
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
296
|
+
else {
|
297
|
+
// Iterate over object keys
|
298
|
+
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
299
|
+
const len = keys.length;
|
300
|
+
let key;
|
301
|
+
for(i = 0; i < len; i++){
|
302
|
+
key = keys[i];
|
303
|
+
fn.call(null, obj[key], key, obj);
|
251
304
|
}
|
252
|
-
if (status) return `http status code: ${status} (no body)`;
|
253
|
-
return '(no status code or body)';
|
254
|
-
}
|
255
|
-
static generate(status, errorResponse, message, headers) {
|
256
|
-
if (!status) return new APIConnectionError({
|
257
|
-
cause: castToError(errorResponse)
|
258
|
-
});
|
259
|
-
const error = errorResponse;
|
260
|
-
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
261
|
-
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
262
|
-
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
263
|
-
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
264
|
-
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
265
|
-
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
266
|
-
if (408 === status) return new TimeoutError(status, error, message, headers);
|
267
|
-
if (502 === status) return new GatewayError(status, error, message, headers);
|
268
|
-
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
269
|
-
return new error_APIError(status, error, message, headers);
|
270
|
-
}
|
271
|
-
constructor(status, error, message, headers){
|
272
|
-
var _error_error, _error_error1;
|
273
|
-
super(`${error_APIError.makeMessage(status, error, message, headers)}`);
|
274
|
-
this.status = status;
|
275
|
-
this.headers = headers;
|
276
|
-
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
277
|
-
// this.error = error;
|
278
|
-
this.code = null == error ? void 0 : error.code;
|
279
|
-
this.msg = null == error ? void 0 : error.msg;
|
280
|
-
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
281
|
-
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
282
|
-
this.rawError = error;
|
283
|
-
}
|
284
|
-
}
|
285
|
-
class APIConnectionError extends error_APIError {
|
286
|
-
constructor({ message, cause }){
|
287
|
-
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
288
|
-
// if (cause) {
|
289
|
-
// this.cause = cause;
|
290
|
-
// }
|
291
|
-
}
|
292
|
-
}
|
293
|
-
class APIUserAbortError extends error_APIError {
|
294
|
-
constructor(message){
|
295
|
-
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
296
|
-
}
|
297
|
-
}
|
298
|
-
class BadRequestError extends error_APIError {
|
299
|
-
constructor(...args){
|
300
|
-
super(...args), this.name = 'BadRequestError', this.status = 400;
|
301
|
-
}
|
302
|
-
}
|
303
|
-
class AuthenticationError extends error_APIError {
|
304
|
-
constructor(...args){
|
305
|
-
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
306
|
-
}
|
307
|
-
}
|
308
|
-
class PermissionDeniedError extends error_APIError {
|
309
|
-
constructor(...args){
|
310
|
-
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
311
|
-
}
|
312
|
-
}
|
313
|
-
class NotFoundError extends error_APIError {
|
314
|
-
constructor(...args){
|
315
|
-
super(...args), this.name = 'NotFoundError', this.status = 404;
|
316
305
|
}
|
317
306
|
}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
}
|
327
|
-
}
|
328
|
-
class InternalServerError extends error_APIError {
|
329
|
-
constructor(...args){
|
330
|
-
super(...args), this.name = 'InternalServerError', this.status = 500;
|
307
|
+
function findKey(obj, key) {
|
308
|
+
key = key.toLowerCase();
|
309
|
+
const keys = Object.keys(obj);
|
310
|
+
let i = keys.length;
|
311
|
+
let _key;
|
312
|
+
while(i-- > 0){
|
313
|
+
_key = keys[i];
|
314
|
+
if (key === _key.toLowerCase()) return _key;
|
331
315
|
}
|
316
|
+
return null;
|
332
317
|
}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
318
|
+
const _global = (()=>{
|
319
|
+
/*eslint no-undef:0*/ if ("undefined" != typeof globalThis) return globalThis;
|
320
|
+
return "undefined" != typeof self ? self : 'undefined' != typeof window ? window : global;
|
321
|
+
})();
|
322
|
+
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
323
|
+
/**
|
324
|
+
* Accepts varargs expecting each argument to be an object, then
|
325
|
+
* immutably merges the properties of each object and returns result.
|
326
|
+
*
|
327
|
+
* When multiple objects contain the same key the later object in
|
328
|
+
* the arguments list will take precedence.
|
329
|
+
*
|
330
|
+
* Example:
|
331
|
+
*
|
332
|
+
* ```js
|
333
|
+
* var result = merge({foo: 123}, {foo: 456});
|
334
|
+
* console.log(result.foo); // outputs 456
|
335
|
+
* ```
|
336
|
+
*
|
337
|
+
* @param {Object} obj1 Object to merge
|
338
|
+
*
|
339
|
+
* @returns {Object} Result of all merge properties
|
340
|
+
*/ function utils_merge() {
|
341
|
+
const { caseless } = isContextDefined(this) && this || {};
|
342
|
+
const result = {};
|
343
|
+
const assignValue = (val, key)=>{
|
344
|
+
const targetKey = caseless && findKey(result, key) || key;
|
345
|
+
if (isPlainObject(result[targetKey]) && isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
346
|
+
else if (isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
347
|
+
else if (isArray(val)) result[targetKey] = val.slice();
|
348
|
+
else result[targetKey] = val;
|
349
|
+
};
|
350
|
+
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
351
|
+
return result;
|
337
352
|
}
|
338
|
-
|
339
|
-
|
340
|
-
|
353
|
+
/**
|
354
|
+
* Extends object a by mutably adding to it the properties of object b.
|
355
|
+
*
|
356
|
+
* @param {Object} a The object to be extended
|
357
|
+
* @param {Object} b The object to copy properties from
|
358
|
+
* @param {Object} thisArg The object to bind function to
|
359
|
+
*
|
360
|
+
* @param {Boolean} [allOwnKeys]
|
361
|
+
* @returns {Object} The resulting value of object a
|
362
|
+
*/ const extend = (a, b, thisArg, { allOwnKeys } = {})=>{
|
363
|
+
forEach(b, (val, key)=>{
|
364
|
+
if (thisArg && isFunction(val)) a[key] = bind(val, thisArg);
|
365
|
+
else a[key] = val;
|
366
|
+
}, {
|
367
|
+
allOwnKeys
|
368
|
+
});
|
369
|
+
return a;
|
341
370
|
};
|
342
|
-
class Messages extends APIResource {
|
343
|
-
/**
|
344
|
-
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
345
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
346
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
347
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
348
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
349
|
-
* @returns An array of chat messages. | 对话消息数组。
|
350
|
-
*/ async list(conversation_id, chat_id, options) {
|
351
|
-
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
352
|
-
const result = await this._client.get(apiUrl, void 0, false, options);
|
353
|
-
return result.data;
|
354
|
-
}
|
355
|
-
}
|
356
|
-
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
357
|
-
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
358
|
-
...i,
|
359
|
-
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
360
|
-
}));
|
361
|
-
class Chat extends APIResource {
|
362
|
-
/**
|
363
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
364
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
365
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
366
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
367
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
368
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
369
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
370
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
371
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
372
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
373
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
374
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
375
|
-
* @returns The data of the created chat. | 创建的对话数据。
|
376
|
-
*/ async create(params, options) {
|
377
|
-
if (!params.user_id) params.user_id = uuid();
|
378
|
-
const { conversation_id, ...rest } = params;
|
379
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
380
|
-
const payload = {
|
381
|
-
...rest,
|
382
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
383
|
-
stream: false
|
384
|
-
};
|
385
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
386
|
-
return result.data;
|
387
|
-
}
|
388
|
-
/**
|
389
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
390
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
391
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
392
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
393
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
394
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
395
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
396
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
397
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
398
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
399
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
400
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
401
|
-
* @returns
|
402
|
-
*/ async createAndPoll(params, options) {
|
403
|
-
if (!params.user_id) params.user_id = uuid();
|
404
|
-
const { conversation_id, ...rest } = params;
|
405
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
406
|
-
const payload = {
|
407
|
-
...rest,
|
408
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
409
|
-
stream: false
|
410
|
-
};
|
411
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
412
|
-
const chatId = result.data.id;
|
413
|
-
const conversationId = result.data.conversation_id;
|
414
|
-
let chat;
|
415
|
-
while(true){
|
416
|
-
await utils_sleep(100);
|
417
|
-
chat = await this.retrieve(conversationId, chatId);
|
418
|
-
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
419
|
-
}
|
420
|
-
const messageList = await this.messages.list(conversationId, chatId);
|
421
|
-
return {
|
422
|
-
chat,
|
423
|
-
messages: messageList
|
424
|
-
};
|
425
|
-
}
|
426
|
-
/**
|
427
|
-
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
428
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
429
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
430
|
-
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
431
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
432
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
433
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
434
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
435
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
436
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
437
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
438
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
439
|
-
* @returns A stream of chat data. | 对话数据流。
|
440
|
-
*/ async *stream(params, options) {
|
441
|
-
if (!params.user_id) params.user_id = uuid();
|
442
|
-
const { conversation_id, ...rest } = params;
|
443
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
444
|
-
const payload = {
|
445
|
-
...rest,
|
446
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
447
|
-
stream: true
|
448
|
-
};
|
449
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
450
|
-
for await (const message of result)if ("done" === message.event) {
|
451
|
-
const ret = {
|
452
|
-
event: message.event,
|
453
|
-
data: '[DONE]'
|
454
|
-
};
|
455
|
-
yield ret;
|
456
|
-
} else try {
|
457
|
-
const ret = {
|
458
|
-
event: message.event,
|
459
|
-
data: JSON.parse(message.data)
|
460
|
-
};
|
461
|
-
yield ret;
|
462
|
-
} catch (error) {
|
463
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
464
|
-
}
|
465
|
-
}
|
466
|
-
/**
|
467
|
-
* Get the detailed information of the chat. | 查看对话的详细信息。
|
468
|
-
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
469
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
470
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
471
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
472
|
-
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
473
|
-
*/ async retrieve(conversation_id, chat_id, options) {
|
474
|
-
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
475
|
-
const result = await this._client.post(apiUrl, void 0, false, options);
|
476
|
-
return result.data;
|
477
|
-
}
|
478
|
-
/**
|
479
|
-
* Cancel a chat session. | 取消对话会话。
|
480
|
-
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
481
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
482
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
483
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
484
|
-
* @returns The data of the canceled chat. | 取消的对话数据。
|
485
|
-
*/ async cancel(conversation_id, chat_id, options) {
|
486
|
-
const apiUrl = '/v3/chat/cancel';
|
487
|
-
const payload = {
|
488
|
-
conversation_id,
|
489
|
-
chat_id
|
490
|
-
};
|
491
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
492
|
-
return result.data;
|
493
|
-
}
|
494
|
-
/**
|
495
|
-
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
496
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
497
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
498
|
-
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
499
|
-
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
500
|
-
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
501
|
-
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
502
|
-
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
503
|
-
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
504
|
-
*/ async *submitToolOutputs(params, options) {
|
505
|
-
const { conversation_id, chat_id, ...rest } = params;
|
506
|
-
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
507
|
-
const payload = {
|
508
|
-
...rest
|
509
|
-
};
|
510
|
-
if (false === params.stream) {
|
511
|
-
const response = await this._client.post(apiUrl, payload, false, options);
|
512
|
-
return response.data;
|
513
|
-
}
|
514
|
-
{
|
515
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
516
|
-
for await (const message of result)if ("done" === message.event) {
|
517
|
-
const ret = {
|
518
|
-
event: message.event,
|
519
|
-
data: '[DONE]'
|
520
|
-
};
|
521
|
-
yield ret;
|
522
|
-
} else try {
|
523
|
-
const ret = {
|
524
|
-
event: message.event,
|
525
|
-
data: JSON.parse(message.data)
|
526
|
-
};
|
527
|
-
yield ret;
|
528
|
-
} catch (error) {
|
529
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
530
|
-
}
|
531
|
-
}
|
532
|
-
}
|
533
|
-
constructor(...args){
|
534
|
-
super(...args), this.messages = new Messages(this._client);
|
535
|
-
}
|
536
|
-
}
|
537
|
-
var chat_ChatEventType = /*#__PURE__*/ function(ChatEventType) {
|
538
|
-
ChatEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
|
539
|
-
ChatEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
|
540
|
-
ChatEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
|
541
|
-
ChatEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
|
542
|
-
ChatEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
|
543
|
-
ChatEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
|
544
|
-
ChatEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
|
545
|
-
ChatEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
|
546
|
-
ChatEventType["DONE"] = "done";
|
547
|
-
ChatEventType["ERROR"] = "error";
|
548
|
-
return ChatEventType;
|
549
|
-
}({});
|
550
|
-
class messages_Messages extends APIResource {
|
551
|
-
/**
|
552
|
-
* Create a message and add it to the specified conversation. | 创建一条消息,并将其添加到指定的会话中。
|
553
|
-
* @docs en: https://www.coze.com/docs/developer_guides/create_message?_lang=en
|
554
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/create_message?_lang=zh
|
555
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
556
|
-
* @param params - Required The parameters for creating a message | 创建消息所需的参数
|
557
|
-
* @param params.role - Required The entity that sent this message. Possible values: user, assistant. | 发送这条消息的实体。取值:user, assistant。
|
558
|
-
* @param params.content - Required The content of the message. | 消息的内容。
|
559
|
-
* @param params.content_type - Required The type of the message content. | 消息内容的类型。
|
560
|
-
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
561
|
-
* @returns Information about the new message. | 消息详情。
|
562
|
-
*/ async create(conversation_id, params, options) {
|
563
|
-
const apiUrl = `/v1/conversation/message/create?conversation_id=${conversation_id}`;
|
564
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
565
|
-
return response.data;
|
566
|
-
}
|
567
|
-
/**
|
568
|
-
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
569
|
-
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
570
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
571
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
572
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
573
|
-
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
574
|
-
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
575
|
-
* @param params.content - Optional The content of the message. | 消息的内容。
|
576
|
-
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
577
|
-
* @returns Information about the modified message. | 消息详情。
|
578
|
-
*/ // eslint-disable-next-line max-params
|
579
|
-
async update(conversation_id, message_id, params, options) {
|
580
|
-
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
581
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
582
|
-
return response.message;
|
583
|
-
}
|
584
|
-
/**
|
585
|
-
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
586
|
-
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
587
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
588
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
589
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
590
|
-
* @returns Information about the message. | 消息详情。
|
591
|
-
*/ async retrieve(conversation_id, message_id, options) {
|
592
|
-
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
593
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
594
|
-
return response.data;
|
595
|
-
}
|
596
|
-
/**
|
597
|
-
* List messages in a conversation. | 列出会话中的消息。
|
598
|
-
* @docs en: https://www.coze.com/docs/developer_guides/message_list?_lang=en
|
599
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/message_list?_lang=zh
|
600
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
601
|
-
* @param params - Optional The parameters for listing messages | 列出消息所需的参数
|
602
|
-
* @param params.order - Optional The order of the messages. | 消息的顺序。
|
603
|
-
* @param params.chat_id - Optional The ID of the chat. | 聊天 ID。
|
604
|
-
* @param params.before_id - Optional The ID of the message before which to list. | 列出此消息之前的消息 ID。
|
605
|
-
* @param params.after_id - Optional The ID of the message after which to list. | 列出此消息之后的消息 ID。
|
606
|
-
* @param params.limit - Optional The maximum number of messages to return. | 返回的最大消息数。
|
607
|
-
* @returns A list of messages. | 消息列表。
|
608
|
-
*/ async list(conversation_id, params, options) {
|
609
|
-
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
610
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
611
|
-
return response;
|
612
|
-
}
|
613
|
-
/**
|
614
|
-
* Call the API to delete a message within a specified conversation. | 调用接口在指定会话中删除消息。
|
615
|
-
* @docs en: https://www.coze.com/docs/developer_guides/delete_message?_lang=en
|
616
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_message?_lang=zh
|
617
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
618
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
619
|
-
* @returns Details of the deleted message. | 已删除的消息详情。
|
620
|
-
*/ async delete(conversation_id, message_id, options) {
|
621
|
-
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
622
|
-
const response = await this._client.post(apiUrl, void 0, false, options);
|
623
|
-
return response.data;
|
624
|
-
}
|
625
|
-
}
|
626
|
-
class Conversations extends APIResource {
|
627
|
-
/**
|
628
|
-
* Create a conversation. Conversation is an interaction between an agent and a user, including one or more messages. | 调用接口创建一个会话。
|
629
|
-
* @docs en: https://www.coze.com/docs/developer_guides/create_conversation?_lang=en
|
630
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/create_conversation?_lang=zh
|
631
|
-
* @param params - Required The parameters for creating a conversation | 创建会话所需的参数
|
632
|
-
* @param params.messages - Optional Messages in the conversation. | 会话中的消息内容。
|
633
|
-
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
634
|
-
* @param params.bot_id - Optional Bind and isolate conversation on different bots. | 绑定和隔离不同Bot的会话。
|
635
|
-
* @returns Information about the created conversation. | 会话的基础信息。
|
636
|
-
*/ async create(params, options) {
|
637
|
-
const apiUrl = '/v1/conversation/create';
|
638
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
639
|
-
return response.data;
|
640
|
-
}
|
641
|
-
/**
|
642
|
-
* Get the information of specific conversation. | 通过会话 ID 查看会话信息。
|
643
|
-
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_conversation?_lang=en
|
644
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_conversation?_lang=zh
|
645
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
646
|
-
* @returns Information about the conversation. | 会话的基础信息。
|
647
|
-
*/ async retrieve(conversation_id, options) {
|
648
|
-
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
649
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
650
|
-
return response.data;
|
651
|
-
}
|
652
|
-
/**
|
653
|
-
* List all conversations. | 列出 Bot 下所有会话。
|
654
|
-
* @param params
|
655
|
-
* @param params.bot_id - Required Bot ID. | Bot ID。
|
656
|
-
* @param params.page_num - Optional The page number. | 页码,默认值为 1。
|
657
|
-
* @param params.page_size - Optional The number of conversations per page. | 每页的会话数量,默认值为 50。
|
658
|
-
* @returns Information about the conversations. | 会话的信息。
|
659
|
-
*/ async list(params, options) {
|
660
|
-
const apiUrl = '/v1/conversations';
|
661
|
-
const response = await this._client.get(apiUrl, params, false, options);
|
662
|
-
return response.data;
|
663
|
-
}
|
664
|
-
/**
|
665
|
-
* Clear a conversation. | 清空会话。
|
666
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
667
|
-
* @returns Information about the conversation session. | 会话的会话 ID。
|
668
|
-
*/ async clear(conversation_id, options) {
|
669
|
-
const apiUrl = `/v1/conversations/${conversation_id}/clear`;
|
670
|
-
const response = await this._client.post(apiUrl, null, false, options);
|
671
|
-
return response.data;
|
672
|
-
}
|
673
|
-
constructor(...args){
|
674
|
-
super(...args), this.messages = new messages_Messages(this._client);
|
675
|
-
}
|
676
|
-
}
|
677
|
-
function bind(fn, thisArg) {
|
678
|
-
return function() {
|
679
|
-
return fn.apply(thisArg, arguments);
|
680
|
-
};
|
681
|
-
}
|
682
|
-
// utils is a library of generic helper functions non-specific to axios
|
683
|
-
const { toString: utils_toString } = Object.prototype;
|
684
|
-
const { getPrototypeOf } = Object;
|
685
|
-
const kindOf = ((cache)=>(thing)=>{
|
686
|
-
const str = utils_toString.call(thing);
|
687
|
-
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
688
|
-
})(Object.create(null));
|
689
|
-
const kindOfTest = (type)=>{
|
690
|
-
type = type.toLowerCase();
|
691
|
-
return (thing)=>kindOf(thing) === type;
|
692
|
-
};
|
693
|
-
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
694
|
-
/**
|
695
|
-
* Determine if a value is an Array
|
696
|
-
*
|
697
|
-
* @param {Object} val The value to test
|
698
|
-
*
|
699
|
-
* @returns {boolean} True if value is an Array, otherwise false
|
700
|
-
*/ const { isArray } = Array;
|
701
|
-
/**
|
702
|
-
* Determine if a value is undefined
|
703
|
-
*
|
704
|
-
* @param {*} val The value to test
|
705
|
-
*
|
706
|
-
* @returns {boolean} True if the value is undefined, otherwise false
|
707
|
-
*/ const isUndefined = typeOfTest('undefined');
|
708
|
-
/**
|
709
|
-
* Determine if a value is a Buffer
|
710
|
-
*
|
711
|
-
* @param {*} val The value to test
|
712
|
-
*
|
713
|
-
* @returns {boolean} True if value is a Buffer, otherwise false
|
714
|
-
*/ function isBuffer(val) {
|
715
|
-
return null !== val && !isUndefined(val) && null !== val.constructor && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
716
|
-
}
|
717
371
|
/**
|
718
|
-
*
|
719
|
-
*
|
720
|
-
* @param {*} val The value to test
|
721
|
-
*
|
722
|
-
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
723
|
-
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
724
|
-
/**
|
725
|
-
* Determine if a value is a view on an ArrayBuffer
|
726
|
-
*
|
727
|
-
* @param {*} val The value to test
|
728
|
-
*
|
729
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
730
|
-
*/ function isArrayBufferView(val) {
|
731
|
-
let result;
|
732
|
-
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
733
|
-
return result;
|
734
|
-
}
|
735
|
-
/**
|
736
|
-
* Determine if a value is a String
|
737
|
-
*
|
738
|
-
* @param {*} val The value to test
|
739
|
-
*
|
740
|
-
* @returns {boolean} True if value is a String, otherwise false
|
741
|
-
*/ const isString = typeOfTest('string');
|
742
|
-
/**
|
743
|
-
* Determine if a value is a Function
|
744
|
-
*
|
745
|
-
* @param {*} val The value to test
|
746
|
-
* @returns {boolean} True if value is a Function, otherwise false
|
747
|
-
*/ const isFunction = typeOfTest('function');
|
748
|
-
/**
|
749
|
-
* Determine if a value is a Number
|
750
|
-
*
|
751
|
-
* @param {*} val The value to test
|
752
|
-
*
|
753
|
-
* @returns {boolean} True if value is a Number, otherwise false
|
754
|
-
*/ const isNumber = typeOfTest('number');
|
755
|
-
/**
|
756
|
-
* Determine if a value is an Object
|
757
|
-
*
|
758
|
-
* @param {*} thing The value to test
|
372
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
759
373
|
*
|
760
|
-
* @
|
761
|
-
*/ const isObject = (thing)=>null !== thing && 'object' == typeof thing;
|
762
|
-
/**
|
763
|
-
* Determine if a value is a Boolean
|
374
|
+
* @param {string} content with BOM
|
764
375
|
*
|
765
|
-
* @
|
766
|
-
|
767
|
-
|
376
|
+
* @returns {string} content value without BOM
|
377
|
+
*/ const stripBOM = (content)=>{
|
378
|
+
if (0xFEFF === content.charCodeAt(0)) content = content.slice(1);
|
379
|
+
return content;
|
380
|
+
};
|
768
381
|
/**
|
769
|
-
*
|
770
|
-
*
|
771
|
-
* @param {
|
382
|
+
* Inherit the prototype methods from one constructor into another
|
383
|
+
* @param {function} constructor
|
384
|
+
* @param {function} superConstructor
|
385
|
+
* @param {object} [props]
|
386
|
+
* @param {object} [descriptors]
|
772
387
|
*
|
773
|
-
* @returns {
|
774
|
-
*/ const
|
775
|
-
|
776
|
-
|
777
|
-
|
388
|
+
* @returns {void}
|
389
|
+
*/ const inherits = (constructor, superConstructor, props, descriptors)=>{
|
390
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
391
|
+
constructor.prototype.constructor = constructor;
|
392
|
+
Object.defineProperty(constructor, 'super', {
|
393
|
+
value: superConstructor.prototype
|
394
|
+
});
|
395
|
+
props && Object.assign(constructor.prototype, props);
|
778
396
|
};
|
779
397
|
/**
|
780
|
-
*
|
781
|
-
*
|
782
|
-
* @param {
|
398
|
+
* Resolve object with deep prototype chain to a flat object
|
399
|
+
* @param {Object} sourceObj source object
|
400
|
+
* @param {Object} [destObj]
|
401
|
+
* @param {Function|Boolean} [filter]
|
402
|
+
* @param {Function} [propFilter]
|
783
403
|
*
|
784
|
-
* @returns {
|
785
|
-
*/ const
|
404
|
+
* @returns {Object}
|
405
|
+
*/ const toFlatObject = (sourceObj, destObj, filter, propFilter)=>{
|
406
|
+
let props;
|
407
|
+
let i;
|
408
|
+
let prop;
|
409
|
+
const merged = {};
|
410
|
+
destObj = destObj || {};
|
411
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
412
|
+
if (null == sourceObj) return destObj;
|
413
|
+
do {
|
414
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
415
|
+
i = props.length;
|
416
|
+
while(i-- > 0){
|
417
|
+
prop = props[i];
|
418
|
+
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
419
|
+
destObj[prop] = sourceObj[prop];
|
420
|
+
merged[prop] = true;
|
421
|
+
}
|
422
|
+
}
|
423
|
+
sourceObj = false !== filter && getPrototypeOf(sourceObj);
|
424
|
+
}while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
425
|
+
return destObj;
|
426
|
+
};
|
786
427
|
/**
|
787
|
-
*
|
428
|
+
* Determines whether a string ends with the characters of a specified string
|
788
429
|
*
|
789
|
-
* @param {
|
430
|
+
* @param {String} str
|
431
|
+
* @param {String} searchString
|
432
|
+
* @param {Number} [position= 0]
|
790
433
|
*
|
791
|
-
* @returns {boolean}
|
792
|
-
*/ const
|
434
|
+
* @returns {boolean}
|
435
|
+
*/ const endsWith = (str, searchString, position)=>{
|
436
|
+
str = String(str);
|
437
|
+
if (void 0 === position || position > str.length) position = str.length;
|
438
|
+
position -= searchString.length;
|
439
|
+
const lastIndex = str.indexOf(searchString, position);
|
440
|
+
return -1 !== lastIndex && lastIndex === position;
|
441
|
+
};
|
793
442
|
/**
|
794
|
-
*
|
443
|
+
* Returns new array from array like object or null if failed
|
795
444
|
*
|
796
|
-
* @param {*}
|
445
|
+
* @param {*} [thing]
|
797
446
|
*
|
798
|
-
* @returns {
|
799
|
-
*/ const
|
447
|
+
* @returns {?Array}
|
448
|
+
*/ const toArray = (thing)=>{
|
449
|
+
if (!thing) return null;
|
450
|
+
if (isArray(thing)) return thing;
|
451
|
+
let i = thing.length;
|
452
|
+
if (!isNumber(i)) return null;
|
453
|
+
const arr = new Array(i);
|
454
|
+
while(i-- > 0)arr[i] = thing[i];
|
455
|
+
return arr;
|
456
|
+
};
|
800
457
|
/**
|
801
|
-
*
|
458
|
+
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
459
|
+
* thing passed in is an instance of Uint8Array
|
802
460
|
*
|
803
|
-
* @param {
|
461
|
+
* @param {TypedArray}
|
804
462
|
*
|
805
|
-
* @returns {
|
806
|
-
*/
|
463
|
+
* @returns {Array}
|
464
|
+
*/ // eslint-disable-next-line func-names
|
465
|
+
const isTypedArray = ((TypedArray)=>(thing)=>TypedArray && thing instanceof TypedArray)('undefined' != typeof Uint8Array && getPrototypeOf(Uint8Array));
|
807
466
|
/**
|
808
|
-
*
|
467
|
+
* For each entry in the object, call the function with the key and value.
|
809
468
|
*
|
810
|
-
* @param {
|
469
|
+
* @param {Object<any, any>} obj - The object to iterate over.
|
470
|
+
* @param {Function} fn - The function to call for each entry.
|
811
471
|
*
|
812
|
-
* @returns {
|
813
|
-
*/ const
|
472
|
+
* @returns {void}
|
473
|
+
*/ const forEachEntry = (obj, fn)=>{
|
474
|
+
const generator = obj && obj[Symbol.iterator];
|
475
|
+
const iterator = generator.call(obj);
|
476
|
+
let result;
|
477
|
+
while((result = iterator.next()) && !result.done){
|
478
|
+
const pair = result.value;
|
479
|
+
fn.call(obj, pair[0], pair[1]);
|
480
|
+
}
|
481
|
+
};
|
814
482
|
/**
|
815
|
-
*
|
483
|
+
* It takes a regular expression and a string, and returns an array of all the matches
|
816
484
|
*
|
817
|
-
* @param {
|
485
|
+
* @param {string} regExp - The regular expression to match against.
|
486
|
+
* @param {string} str - The string to search.
|
818
487
|
*
|
819
|
-
* @returns {boolean}
|
820
|
-
*/ const
|
821
|
-
let
|
822
|
-
|
823
|
-
|
488
|
+
* @returns {Array<boolean>}
|
489
|
+
*/ const matchAll = (regExp, str)=>{
|
490
|
+
let matches;
|
491
|
+
const arr = [];
|
492
|
+
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
493
|
+
return arr;
|
824
494
|
};
|
495
|
+
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
496
|
+
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
497
|
+
return p1.toUpperCase() + p2;
|
498
|
+
});
|
499
|
+
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
825
500
|
/**
|
826
|
-
* Determine if a value is a
|
827
|
-
*
|
828
|
-
* @param {*} val The value to test
|
829
|
-
*
|
830
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
831
|
-
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
832
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
833
|
-
'ReadableStream',
|
834
|
-
'Request',
|
835
|
-
'Response',
|
836
|
-
'Headers'
|
837
|
-
].map(kindOfTest);
|
838
|
-
/**
|
839
|
-
* Trim excess whitespace off the beginning and end of a string
|
840
|
-
*
|
841
|
-
* @param {String} str The String to trim
|
842
|
-
*
|
843
|
-
* @returns {String} The String freed of excess whitespace
|
844
|
-
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
845
|
-
/**
|
846
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
847
|
-
*
|
848
|
-
* If `obj` is an Array callback will be called passing
|
849
|
-
* the value, index, and complete array for each item.
|
850
|
-
*
|
851
|
-
* If 'obj' is an Object callback will be called passing
|
852
|
-
* the value, key, and complete object for each property.
|
853
|
-
*
|
854
|
-
* @param {Object|Array} obj The object to iterate
|
855
|
-
* @param {Function} fn The callback to invoke for each item
|
856
|
-
*
|
857
|
-
* @param {Boolean} [allOwnKeys = false]
|
858
|
-
* @returns {any}
|
859
|
-
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
860
|
-
// Don't bother if no value provided
|
861
|
-
if (null == obj) return;
|
862
|
-
let i;
|
863
|
-
let l;
|
864
|
-
// Force an array if not already something iterable
|
865
|
-
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
866
|
-
obj
|
867
|
-
];
|
868
|
-
if (isArray(obj)) // Iterate over array values
|
869
|
-
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
870
|
-
else {
|
871
|
-
// Iterate over object keys
|
872
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
873
|
-
const len = keys.length;
|
874
|
-
let key;
|
875
|
-
for(i = 0; i < len; i++){
|
876
|
-
key = keys[i];
|
877
|
-
fn.call(null, obj[key], key, obj);
|
878
|
-
}
|
879
|
-
}
|
880
|
-
}
|
881
|
-
function findKey(obj, key) {
|
882
|
-
key = key.toLowerCase();
|
883
|
-
const keys = Object.keys(obj);
|
884
|
-
let i = keys.length;
|
885
|
-
let _key;
|
886
|
-
while(i-- > 0){
|
887
|
-
_key = keys[i];
|
888
|
-
if (key === _key.toLowerCase()) return _key;
|
889
|
-
}
|
890
|
-
return null;
|
891
|
-
}
|
892
|
-
const _global = (()=>{
|
893
|
-
/*eslint no-undef:0*/ if ("undefined" != typeof globalThis) return globalThis;
|
894
|
-
return "undefined" != typeof self ? self : 'undefined' != typeof window ? window : global;
|
895
|
-
})();
|
896
|
-
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
897
|
-
/**
|
898
|
-
* Accepts varargs expecting each argument to be an object, then
|
899
|
-
* immutably merges the properties of each object and returns result.
|
900
|
-
*
|
901
|
-
* When multiple objects contain the same key the later object in
|
902
|
-
* the arguments list will take precedence.
|
903
|
-
*
|
904
|
-
* Example:
|
905
|
-
*
|
906
|
-
* ```js
|
907
|
-
* var result = merge({foo: 123}, {foo: 456});
|
908
|
-
* console.log(result.foo); // outputs 456
|
909
|
-
* ```
|
910
|
-
*
|
911
|
-
* @param {Object} obj1 Object to merge
|
912
|
-
*
|
913
|
-
* @returns {Object} Result of all merge properties
|
914
|
-
*/ function utils_merge() {
|
915
|
-
const { caseless } = isContextDefined(this) && this || {};
|
916
|
-
const result = {};
|
917
|
-
const assignValue = (val, key)=>{
|
918
|
-
const targetKey = caseless && findKey(result, key) || key;
|
919
|
-
if (utils_isPlainObject(result[targetKey]) && utils_isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
920
|
-
else if (utils_isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
921
|
-
else if (isArray(val)) result[targetKey] = val.slice();
|
922
|
-
else result[targetKey] = val;
|
923
|
-
};
|
924
|
-
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
925
|
-
return result;
|
926
|
-
}
|
927
|
-
/**
|
928
|
-
* Extends object a by mutably adding to it the properties of object b.
|
929
|
-
*
|
930
|
-
* @param {Object} a The object to be extended
|
931
|
-
* @param {Object} b The object to copy properties from
|
932
|
-
* @param {Object} thisArg The object to bind function to
|
933
|
-
*
|
934
|
-
* @param {Boolean} [allOwnKeys]
|
935
|
-
* @returns {Object} The resulting value of object a
|
936
|
-
*/ const extend = (a, b, thisArg, { allOwnKeys } = {})=>{
|
937
|
-
forEach(b, (val, key)=>{
|
938
|
-
if (thisArg && isFunction(val)) a[key] = bind(val, thisArg);
|
939
|
-
else a[key] = val;
|
940
|
-
}, {
|
941
|
-
allOwnKeys
|
942
|
-
});
|
943
|
-
return a;
|
944
|
-
};
|
945
|
-
/**
|
946
|
-
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
947
|
-
*
|
948
|
-
* @param {string} content with BOM
|
949
|
-
*
|
950
|
-
* @returns {string} content value without BOM
|
951
|
-
*/ const stripBOM = (content)=>{
|
952
|
-
if (0xFEFF === content.charCodeAt(0)) content = content.slice(1);
|
953
|
-
return content;
|
954
|
-
};
|
955
|
-
/**
|
956
|
-
* Inherit the prototype methods from one constructor into another
|
957
|
-
* @param {function} constructor
|
958
|
-
* @param {function} superConstructor
|
959
|
-
* @param {object} [props]
|
960
|
-
* @param {object} [descriptors]
|
961
|
-
*
|
962
|
-
* @returns {void}
|
963
|
-
*/ const inherits = (constructor, superConstructor, props, descriptors)=>{
|
964
|
-
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
965
|
-
constructor.prototype.constructor = constructor;
|
966
|
-
Object.defineProperty(constructor, 'super', {
|
967
|
-
value: superConstructor.prototype
|
968
|
-
});
|
969
|
-
props && Object.assign(constructor.prototype, props);
|
970
|
-
};
|
971
|
-
/**
|
972
|
-
* Resolve object with deep prototype chain to a flat object
|
973
|
-
* @param {Object} sourceObj source object
|
974
|
-
* @param {Object} [destObj]
|
975
|
-
* @param {Function|Boolean} [filter]
|
976
|
-
* @param {Function} [propFilter]
|
977
|
-
*
|
978
|
-
* @returns {Object}
|
979
|
-
*/ const toFlatObject = (sourceObj, destObj, filter, propFilter)=>{
|
980
|
-
let props;
|
981
|
-
let i;
|
982
|
-
let prop;
|
983
|
-
const merged = {};
|
984
|
-
destObj = destObj || {};
|
985
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
986
|
-
if (null == sourceObj) return destObj;
|
987
|
-
do {
|
988
|
-
props = Object.getOwnPropertyNames(sourceObj);
|
989
|
-
i = props.length;
|
990
|
-
while(i-- > 0){
|
991
|
-
prop = props[i];
|
992
|
-
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
993
|
-
destObj[prop] = sourceObj[prop];
|
994
|
-
merged[prop] = true;
|
995
|
-
}
|
996
|
-
}
|
997
|
-
sourceObj = false !== filter && getPrototypeOf(sourceObj);
|
998
|
-
}while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
999
|
-
return destObj;
|
1000
|
-
};
|
1001
|
-
/**
|
1002
|
-
* Determines whether a string ends with the characters of a specified string
|
1003
|
-
*
|
1004
|
-
* @param {String} str
|
1005
|
-
* @param {String} searchString
|
1006
|
-
* @param {Number} [position= 0]
|
1007
|
-
*
|
1008
|
-
* @returns {boolean}
|
1009
|
-
*/ const endsWith = (str, searchString, position)=>{
|
1010
|
-
str = String(str);
|
1011
|
-
if (void 0 === position || position > str.length) position = str.length;
|
1012
|
-
position -= searchString.length;
|
1013
|
-
const lastIndex = str.indexOf(searchString, position);
|
1014
|
-
return -1 !== lastIndex && lastIndex === position;
|
1015
|
-
};
|
1016
|
-
/**
|
1017
|
-
* Returns new array from array like object or null if failed
|
1018
|
-
*
|
1019
|
-
* @param {*} [thing]
|
1020
|
-
*
|
1021
|
-
* @returns {?Array}
|
1022
|
-
*/ const toArray = (thing)=>{
|
1023
|
-
if (!thing) return null;
|
1024
|
-
if (isArray(thing)) return thing;
|
1025
|
-
let i = thing.length;
|
1026
|
-
if (!isNumber(i)) return null;
|
1027
|
-
const arr = new Array(i);
|
1028
|
-
while(i-- > 0)arr[i] = thing[i];
|
1029
|
-
return arr;
|
1030
|
-
};
|
1031
|
-
/**
|
1032
|
-
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
1033
|
-
* thing passed in is an instance of Uint8Array
|
1034
|
-
*
|
1035
|
-
* @param {TypedArray}
|
1036
|
-
*
|
1037
|
-
* @returns {Array}
|
1038
|
-
*/ // eslint-disable-next-line func-names
|
1039
|
-
const isTypedArray = ((TypedArray)=>(thing)=>TypedArray && thing instanceof TypedArray)('undefined' != typeof Uint8Array && getPrototypeOf(Uint8Array));
|
1040
|
-
/**
|
1041
|
-
* For each entry in the object, call the function with the key and value.
|
1042
|
-
*
|
1043
|
-
* @param {Object<any, any>} obj - The object to iterate over.
|
1044
|
-
* @param {Function} fn - The function to call for each entry.
|
1045
|
-
*
|
1046
|
-
* @returns {void}
|
1047
|
-
*/ const forEachEntry = (obj, fn)=>{
|
1048
|
-
const generator = obj && obj[Symbol.iterator];
|
1049
|
-
const iterator = generator.call(obj);
|
1050
|
-
let result;
|
1051
|
-
while((result = iterator.next()) && !result.done){
|
1052
|
-
const pair = result.value;
|
1053
|
-
fn.call(obj, pair[0], pair[1]);
|
1054
|
-
}
|
1055
|
-
};
|
1056
|
-
/**
|
1057
|
-
* It takes a regular expression and a string, and returns an array of all the matches
|
1058
|
-
*
|
1059
|
-
* @param {string} regExp - The regular expression to match against.
|
1060
|
-
* @param {string} str - The string to search.
|
1061
|
-
*
|
1062
|
-
* @returns {Array<boolean>}
|
1063
|
-
*/ const matchAll = (regExp, str)=>{
|
1064
|
-
let matches;
|
1065
|
-
const arr = [];
|
1066
|
-
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
1067
|
-
return arr;
|
1068
|
-
};
|
1069
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
1070
|
-
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
1071
|
-
return p1.toUpperCase() + p2;
|
1072
|
-
});
|
1073
|
-
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
1074
|
-
/**
|
1075
|
-
* Determine if a value is a RegExp object
|
501
|
+
* Determine if a value is a RegExp object
|
1076
502
|
*
|
1077
503
|
* @param {*} val The value to test
|
1078
504
|
*
|
@@ -1192,7 +618,7 @@
|
|
1192
618
|
isNumber,
|
1193
619
|
isBoolean,
|
1194
620
|
isObject,
|
1195
|
-
isPlainObject
|
621
|
+
isPlainObject,
|
1196
622
|
isReadableStream,
|
1197
623
|
isRequest,
|
1198
624
|
isResponse,
|
@@ -1634,7 +1060,7 @@
|
|
1634
1060
|
]
|
1635
1061
|
};
|
1636
1062
|
const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
|
1637
|
-
const
|
1063
|
+
const utils_navigator = 'object' == typeof navigator && navigator || void 0;
|
1638
1064
|
/**
|
1639
1065
|
* Determine if we're running in a standard browser environment
|
1640
1066
|
*
|
@@ -1651,11 +1077,11 @@
|
|
1651
1077
|
* navigator.product -> 'NativeScript' or 'NS'
|
1652
1078
|
*
|
1653
1079
|
* @returns {boolean}
|
1654
|
-
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!
|
1080
|
+
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
|
1655
1081
|
'ReactNative',
|
1656
1082
|
'NativeScript',
|
1657
1083
|
'NS'
|
1658
|
-
].indexOf(
|
1084
|
+
].indexOf(utils_navigator.product) < 0);
|
1659
1085
|
/**
|
1660
1086
|
* Determine if we're running in a standard browser webWorker environment
|
1661
1087
|
*
|
@@ -2390,7 +1816,7 @@
|
|
2390
1816
|
* @param {Object} config2
|
2391
1817
|
*
|
2392
1818
|
* @returns {Object} New object resulting from merging config2 to config1
|
2393
|
-
*/ function
|
1819
|
+
*/ function mergeConfig(config1, config2) {
|
2394
1820
|
// eslint-disable-next-line no-param-reassign
|
2395
1821
|
config2 = config2 || {};
|
2396
1822
|
const config = {};
|
@@ -2460,7 +1886,7 @@
|
|
2460
1886
|
return config;
|
2461
1887
|
}
|
2462
1888
|
/* ESM default export */ const resolveConfig = (config)=>{
|
2463
|
-
const newConfig =
|
1889
|
+
const newConfig = mergeConfig({}, config);
|
2464
1890
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
2465
1891
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
2466
1892
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
@@ -3066,7 +2492,7 @@
|
|
3066
2492
|
config = config || {};
|
3067
2493
|
config.url = configOrUrl;
|
3068
2494
|
} else config = configOrUrl || {};
|
3069
|
-
config =
|
2495
|
+
config = mergeConfig(this.defaults, config);
|
3070
2496
|
const { transitional, paramsSerializer, headers } = config;
|
3071
2497
|
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
3072
2498
|
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
@@ -3125,320 +2551,887 @@
|
|
3125
2551
|
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
3126
2552
|
return promise;
|
3127
2553
|
}
|
3128
|
-
len = requestInterceptorChain.length;
|
3129
|
-
let newConfig = config;
|
3130
|
-
i = 0;
|
3131
|
-
while(i < len){
|
3132
|
-
const onFulfilled = requestInterceptorChain[i++];
|
3133
|
-
const onRejected = requestInterceptorChain[i++];
|
3134
|
-
try {
|
3135
|
-
newConfig = onFulfilled(newConfig);
|
2554
|
+
len = requestInterceptorChain.length;
|
2555
|
+
let newConfig = config;
|
2556
|
+
i = 0;
|
2557
|
+
while(i < len){
|
2558
|
+
const onFulfilled = requestInterceptorChain[i++];
|
2559
|
+
const onRejected = requestInterceptorChain[i++];
|
2560
|
+
try {
|
2561
|
+
newConfig = onFulfilled(newConfig);
|
2562
|
+
} catch (error) {
|
2563
|
+
onRejected.call(this, error);
|
2564
|
+
break;
|
2565
|
+
}
|
2566
|
+
}
|
2567
|
+
try {
|
2568
|
+
promise = dispatchRequest.call(this, newConfig);
|
2569
|
+
} catch (error) {
|
2570
|
+
return Promise.reject(error);
|
2571
|
+
}
|
2572
|
+
i = 0;
|
2573
|
+
len = responseInterceptorChain.length;
|
2574
|
+
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
2575
|
+
return promise;
|
2576
|
+
}
|
2577
|
+
getUri(config) {
|
2578
|
+
config = mergeConfig(this.defaults, config);
|
2579
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
2580
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2581
|
+
}
|
2582
|
+
}
|
2583
|
+
// Provide aliases for supported request methods
|
2584
|
+
utils.forEach([
|
2585
|
+
'delete',
|
2586
|
+
'get',
|
2587
|
+
'head',
|
2588
|
+
'options'
|
2589
|
+
], function(method) {
|
2590
|
+
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
2591
|
+
return this.request(mergeConfig(config || {}, {
|
2592
|
+
method,
|
2593
|
+
url,
|
2594
|
+
data: (config || {}).data
|
2595
|
+
}));
|
2596
|
+
};
|
2597
|
+
});
|
2598
|
+
utils.forEach([
|
2599
|
+
'post',
|
2600
|
+
'put',
|
2601
|
+
'patch'
|
2602
|
+
], function(method) {
|
2603
|
+
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
2604
|
+
return function(url, data, config) {
|
2605
|
+
return this.request(mergeConfig(config || {}, {
|
2606
|
+
method,
|
2607
|
+
headers: isForm ? {
|
2608
|
+
'Content-Type': 'multipart/form-data'
|
2609
|
+
} : {},
|
2610
|
+
url,
|
2611
|
+
data
|
2612
|
+
}));
|
2613
|
+
};
|
2614
|
+
}
|
2615
|
+
Axios_Axios.prototype[method] = generateHTTPMethod();
|
2616
|
+
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2617
|
+
});
|
2618
|
+
/* ESM default export */ const Axios = Axios_Axios;
|
2619
|
+
/**
|
2620
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2621
|
+
*
|
2622
|
+
* @param {Function} executor The executor function.
|
2623
|
+
*
|
2624
|
+
* @returns {CancelToken}
|
2625
|
+
*/ class CancelToken_CancelToken {
|
2626
|
+
constructor(executor){
|
2627
|
+
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
2628
|
+
let resolvePromise;
|
2629
|
+
this.promise = new Promise(function(resolve) {
|
2630
|
+
resolvePromise = resolve;
|
2631
|
+
});
|
2632
|
+
const token = this;
|
2633
|
+
// eslint-disable-next-line func-names
|
2634
|
+
this.promise.then((cancel)=>{
|
2635
|
+
if (!token._listeners) return;
|
2636
|
+
let i = token._listeners.length;
|
2637
|
+
while(i-- > 0)token._listeners[i](cancel);
|
2638
|
+
token._listeners = null;
|
2639
|
+
});
|
2640
|
+
// eslint-disable-next-line func-names
|
2641
|
+
this.promise.then = (onfulfilled)=>{
|
2642
|
+
let _resolve;
|
2643
|
+
// eslint-disable-next-line func-names
|
2644
|
+
const promise = new Promise((resolve)=>{
|
2645
|
+
token.subscribe(resolve);
|
2646
|
+
_resolve = resolve;
|
2647
|
+
}).then(onfulfilled);
|
2648
|
+
promise.cancel = function() {
|
2649
|
+
token.unsubscribe(_resolve);
|
2650
|
+
};
|
2651
|
+
return promise;
|
2652
|
+
};
|
2653
|
+
executor(function(message, config, request) {
|
2654
|
+
if (token.reason) // Cancellation has already been requested
|
2655
|
+
return;
|
2656
|
+
token.reason = new CanceledError(message, config, request);
|
2657
|
+
resolvePromise(token.reason);
|
2658
|
+
});
|
2659
|
+
}
|
2660
|
+
/**
|
2661
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
2662
|
+
*/ throwIfRequested() {
|
2663
|
+
if (this.reason) throw this.reason;
|
2664
|
+
}
|
2665
|
+
/**
|
2666
|
+
* Subscribe to the cancel signal
|
2667
|
+
*/ subscribe(listener) {
|
2668
|
+
if (this.reason) {
|
2669
|
+
listener(this.reason);
|
2670
|
+
return;
|
2671
|
+
}
|
2672
|
+
if (this._listeners) this._listeners.push(listener);
|
2673
|
+
else this._listeners = [
|
2674
|
+
listener
|
2675
|
+
];
|
2676
|
+
}
|
2677
|
+
/**
|
2678
|
+
* Unsubscribe from the cancel signal
|
2679
|
+
*/ unsubscribe(listener) {
|
2680
|
+
if (!this._listeners) return;
|
2681
|
+
const index = this._listeners.indexOf(listener);
|
2682
|
+
if (-1 !== index) this._listeners.splice(index, 1);
|
2683
|
+
}
|
2684
|
+
toAbortSignal() {
|
2685
|
+
const controller = new AbortController();
|
2686
|
+
const abort = (err)=>{
|
2687
|
+
controller.abort(err);
|
2688
|
+
};
|
2689
|
+
this.subscribe(abort);
|
2690
|
+
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
2691
|
+
return controller.signal;
|
2692
|
+
}
|
2693
|
+
/**
|
2694
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2695
|
+
* cancels the `CancelToken`.
|
2696
|
+
*/ static source() {
|
2697
|
+
let cancel;
|
2698
|
+
const token = new CancelToken_CancelToken(function(c) {
|
2699
|
+
cancel = c;
|
2700
|
+
});
|
2701
|
+
return {
|
2702
|
+
token,
|
2703
|
+
cancel
|
2704
|
+
};
|
2705
|
+
}
|
2706
|
+
}
|
2707
|
+
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
2708
|
+
/**
|
2709
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2710
|
+
*
|
2711
|
+
* Common use case would be to use `Function.prototype.apply`.
|
2712
|
+
*
|
2713
|
+
* ```js
|
2714
|
+
* function f(x, y, z) {}
|
2715
|
+
* var args = [1, 2, 3];
|
2716
|
+
* f.apply(null, args);
|
2717
|
+
* ```
|
2718
|
+
*
|
2719
|
+
* With `spread` this example can be re-written.
|
2720
|
+
*
|
2721
|
+
* ```js
|
2722
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
2723
|
+
* ```
|
2724
|
+
*
|
2725
|
+
* @param {Function} callback
|
2726
|
+
*
|
2727
|
+
* @returns {Function}
|
2728
|
+
*/ function spread(callback) {
|
2729
|
+
return function(arr) {
|
2730
|
+
return callback.apply(null, arr);
|
2731
|
+
};
|
2732
|
+
}
|
2733
|
+
/**
|
2734
|
+
* Determines whether the payload is an error thrown by Axios
|
2735
|
+
*
|
2736
|
+
* @param {*} payload The value to test
|
2737
|
+
*
|
2738
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2739
|
+
*/ function isAxiosError(payload) {
|
2740
|
+
return utils.isObject(payload) && true === payload.isAxiosError;
|
2741
|
+
}
|
2742
|
+
const HttpStatusCode = {
|
2743
|
+
Continue: 100,
|
2744
|
+
SwitchingProtocols: 101,
|
2745
|
+
Processing: 102,
|
2746
|
+
EarlyHints: 103,
|
2747
|
+
Ok: 200,
|
2748
|
+
Created: 201,
|
2749
|
+
Accepted: 202,
|
2750
|
+
NonAuthoritativeInformation: 203,
|
2751
|
+
NoContent: 204,
|
2752
|
+
ResetContent: 205,
|
2753
|
+
PartialContent: 206,
|
2754
|
+
MultiStatus: 207,
|
2755
|
+
AlreadyReported: 208,
|
2756
|
+
ImUsed: 226,
|
2757
|
+
MultipleChoices: 300,
|
2758
|
+
MovedPermanently: 301,
|
2759
|
+
Found: 302,
|
2760
|
+
SeeOther: 303,
|
2761
|
+
NotModified: 304,
|
2762
|
+
UseProxy: 305,
|
2763
|
+
Unused: 306,
|
2764
|
+
TemporaryRedirect: 307,
|
2765
|
+
PermanentRedirect: 308,
|
2766
|
+
BadRequest: 400,
|
2767
|
+
Unauthorized: 401,
|
2768
|
+
PaymentRequired: 402,
|
2769
|
+
Forbidden: 403,
|
2770
|
+
NotFound: 404,
|
2771
|
+
MethodNotAllowed: 405,
|
2772
|
+
NotAcceptable: 406,
|
2773
|
+
ProxyAuthenticationRequired: 407,
|
2774
|
+
RequestTimeout: 408,
|
2775
|
+
Conflict: 409,
|
2776
|
+
Gone: 410,
|
2777
|
+
LengthRequired: 411,
|
2778
|
+
PreconditionFailed: 412,
|
2779
|
+
PayloadTooLarge: 413,
|
2780
|
+
UriTooLong: 414,
|
2781
|
+
UnsupportedMediaType: 415,
|
2782
|
+
RangeNotSatisfiable: 416,
|
2783
|
+
ExpectationFailed: 417,
|
2784
|
+
ImATeapot: 418,
|
2785
|
+
MisdirectedRequest: 421,
|
2786
|
+
UnprocessableEntity: 422,
|
2787
|
+
Locked: 423,
|
2788
|
+
FailedDependency: 424,
|
2789
|
+
TooEarly: 425,
|
2790
|
+
UpgradeRequired: 426,
|
2791
|
+
PreconditionRequired: 428,
|
2792
|
+
TooManyRequests: 429,
|
2793
|
+
RequestHeaderFieldsTooLarge: 431,
|
2794
|
+
UnavailableForLegalReasons: 451,
|
2795
|
+
InternalServerError: 500,
|
2796
|
+
NotImplemented: 501,
|
2797
|
+
BadGateway: 502,
|
2798
|
+
ServiceUnavailable: 503,
|
2799
|
+
GatewayTimeout: 504,
|
2800
|
+
HttpVersionNotSupported: 505,
|
2801
|
+
VariantAlsoNegotiates: 506,
|
2802
|
+
InsufficientStorage: 507,
|
2803
|
+
LoopDetected: 508,
|
2804
|
+
NotExtended: 510,
|
2805
|
+
NetworkAuthenticationRequired: 511
|
2806
|
+
};
|
2807
|
+
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
2808
|
+
HttpStatusCode[value] = key;
|
2809
|
+
});
|
2810
|
+
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
2811
|
+
/**
|
2812
|
+
* Create an instance of Axios
|
2813
|
+
*
|
2814
|
+
* @param {Object} defaultConfig The default config for the instance
|
2815
|
+
*
|
2816
|
+
* @returns {Axios} A new instance of Axios
|
2817
|
+
*/ function createInstance(defaultConfig) {
|
2818
|
+
const context = new Axios(defaultConfig);
|
2819
|
+
const instance = bind(Axios.prototype.request, context);
|
2820
|
+
// Copy axios.prototype to instance
|
2821
|
+
utils.extend(instance, Axios.prototype, context, {
|
2822
|
+
allOwnKeys: true
|
2823
|
+
});
|
2824
|
+
// Copy context to instance
|
2825
|
+
utils.extend(instance, context, null, {
|
2826
|
+
allOwnKeys: true
|
2827
|
+
});
|
2828
|
+
// Factory for creating new instances
|
2829
|
+
instance.create = function(instanceConfig) {
|
2830
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2831
|
+
};
|
2832
|
+
return instance;
|
2833
|
+
}
|
2834
|
+
// Create the default instance to be exported
|
2835
|
+
const axios = createInstance(defaults);
|
2836
|
+
// Expose Axios class to allow class inheritance
|
2837
|
+
axios.Axios = Axios;
|
2838
|
+
// Expose Cancel & CancelToken
|
2839
|
+
axios.CanceledError = CanceledError;
|
2840
|
+
axios.CancelToken = CancelToken;
|
2841
|
+
axios.isCancel = isCancel;
|
2842
|
+
axios.VERSION = VERSION;
|
2843
|
+
axios.toFormData = toFormData;
|
2844
|
+
// Expose AxiosError class
|
2845
|
+
axios.AxiosError = core_AxiosError;
|
2846
|
+
// alias for CanceledError for backward compatibility
|
2847
|
+
axios.Cancel = axios.CanceledError;
|
2848
|
+
// Expose all/spread
|
2849
|
+
axios.all = function(promises) {
|
2850
|
+
return Promise.all(promises);
|
2851
|
+
};
|
2852
|
+
axios.spread = spread;
|
2853
|
+
// Expose isAxiosError
|
2854
|
+
axios.isAxiosError = isAxiosError;
|
2855
|
+
// Expose mergeConfig
|
2856
|
+
axios.mergeConfig = mergeConfig;
|
2857
|
+
axios.AxiosHeaders = AxiosHeaders;
|
2858
|
+
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2859
|
+
axios.getAdapter = adapters_adapters.getAdapter;
|
2860
|
+
axios.HttpStatusCode = helpers_HttpStatusCode;
|
2861
|
+
axios.default = axios;
|
2862
|
+
// this module should only have a default export
|
2863
|
+
/* ESM default export */ const lib_axios = axios;
|
2864
|
+
// This module is intended to unwrap Axios default export as named.
|
2865
|
+
// Keep top-level export same with static properties
|
2866
|
+
// so that it can keep same with es module or cjs
|
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;
|
2868
|
+
// EXTERNAL MODULE: os (ignored)
|
2869
|
+
var os_ignored_ = __webpack_require__("?9caf");
|
2870
|
+
// EXTERNAL MODULE: crypto (ignored)
|
2871
|
+
__webpack_require__("?e272");
|
2872
|
+
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
2873
|
+
__webpack_require__("?5742");
|
2874
|
+
class APIResource {
|
2875
|
+
constructor(client){
|
2876
|
+
this._client = client;
|
2877
|
+
}
|
2878
|
+
}
|
2879
|
+
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
2880
|
+
/**
|
2881
|
+
* Create a new agent. | 调用接口创建一个新的智能体。
|
2882
|
+
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
2883
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
2884
|
+
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
2885
|
+
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
2886
|
+
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
2887
|
+
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
2888
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2889
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2890
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2891
|
+
* @returns Information about the created bot. | 创建的 Bot 信息。
|
2892
|
+
*/ async create(params, options) {
|
2893
|
+
const apiUrl = '/v1/bot/create';
|
2894
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
2895
|
+
return result.data;
|
2896
|
+
}
|
2897
|
+
/**
|
2898
|
+
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
2899
|
+
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
2900
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
2901
|
+
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
2902
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
2903
|
+
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
2904
|
+
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
2905
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2906
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2907
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2908
|
+
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
2909
|
+
* @returns Undefined | 无返回值
|
2910
|
+
*/ async update(params, options) {
|
2911
|
+
const apiUrl = '/v1/bot/update';
|
2912
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
2913
|
+
return result.data;
|
2914
|
+
}
|
2915
|
+
/**
|
2916
|
+
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
2917
|
+
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
2918
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
2919
|
+
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
2920
|
+
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
2921
|
+
* @param params.page_size - Optional Pagination size. | 分页大小。
|
2922
|
+
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
2923
|
+
* @returns List of published bots. | 已发布的 Bot 列表。
|
2924
|
+
*/ async list(params, options) {
|
2925
|
+
const apiUrl = '/v1/space/published_bots_list';
|
2926
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
2927
|
+
return result.data;
|
2928
|
+
}
|
2929
|
+
/**
|
2930
|
+
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
2931
|
+
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
2932
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
2933
|
+
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
2934
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
2935
|
+
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
2936
|
+
* @returns Undefined | 无返回值
|
2937
|
+
*/ async publish(params, options) {
|
2938
|
+
const apiUrl = '/v1/bot/publish';
|
2939
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
2940
|
+
return result.data;
|
2941
|
+
}
|
2942
|
+
/**
|
2943
|
+
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
2944
|
+
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
2945
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
2946
|
+
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
2947
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
2948
|
+
* @returns Information about the bot. | Bot 的配置信息。
|
2949
|
+
*/ async retrieve(params, options) {
|
2950
|
+
const apiUrl = '/v1/bot/get_online_info';
|
2951
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
2952
|
+
return result.data;
|
2953
|
+
}
|
2954
|
+
}
|
2955
|
+
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
2956
|
+
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
2957
|
+
try {
|
2958
|
+
return JSON.parse(jsonString);
|
2959
|
+
} catch (error) {
|
2960
|
+
return defaultValue;
|
2961
|
+
}
|
2962
|
+
}
|
2963
|
+
function sleep(ms) {
|
2964
|
+
return new Promise((resolve)=>{
|
2965
|
+
setTimeout(resolve, ms);
|
2966
|
+
});
|
2967
|
+
}
|
2968
|
+
function isBrowser() {
|
2969
|
+
return 'undefined' != typeof window;
|
2970
|
+
}
|
2971
|
+
function esm_isPlainObject(obj) {
|
2972
|
+
if ('object' != typeof obj || null === obj) return false;
|
2973
|
+
const proto = Object.getPrototypeOf(obj);
|
2974
|
+
if (null === proto) return true;
|
2975
|
+
let baseProto = proto;
|
2976
|
+
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
2977
|
+
return proto === baseProto;
|
2978
|
+
}
|
2979
|
+
function esm_mergeConfig() {
|
2980
|
+
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
2981
|
+
return objects.reduce((result, obj)=>{
|
2982
|
+
if (void 0 === obj) return result || {};
|
2983
|
+
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
2984
|
+
if (esm_isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = esm_mergeConfig(result[key] || {}, obj[key]);
|
2985
|
+
else result[key] = obj[key];
|
2986
|
+
}
|
2987
|
+
return result;
|
2988
|
+
}, {});
|
2989
|
+
}
|
2990
|
+
function isPersonalAccessToken(token) {
|
2991
|
+
return null == token ? void 0 : token.startsWith('pat_');
|
2992
|
+
}
|
2993
|
+
/* eslint-disable max-params */ class CozeError extends Error {
|
2994
|
+
}
|
2995
|
+
class APIError extends CozeError {
|
2996
|
+
static makeMessage(status, errorBody, message, headers) {
|
2997
|
+
if (!errorBody && message) return message;
|
2998
|
+
if (errorBody) {
|
2999
|
+
const list = [];
|
3000
|
+
const { code, msg, error } = errorBody;
|
3001
|
+
if (code) list.push(`code: ${code}`);
|
3002
|
+
if (msg) list.push(`msg: ${msg}`);
|
3003
|
+
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
3004
|
+
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
3005
|
+
if (logId) list.push(`logid: ${logId}`);
|
3006
|
+
const help_doc = null == error ? void 0 : error.help_doc;
|
3007
|
+
if (help_doc) list.push(`help doc: ${help_doc}`);
|
3008
|
+
return list.join(', ');
|
3009
|
+
}
|
3010
|
+
if (status) return `http status code: ${status} (no body)`;
|
3011
|
+
return '(no status code or body)';
|
3012
|
+
}
|
3013
|
+
static generate(status, errorResponse, message, headers) {
|
3014
|
+
if (!status) return new APIConnectionError({
|
3015
|
+
cause: castToError(errorResponse)
|
3016
|
+
});
|
3017
|
+
const error = errorResponse;
|
3018
|
+
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
3019
|
+
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
3020
|
+
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
3021
|
+
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
3022
|
+
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
3023
|
+
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
3024
|
+
if (408 === status) return new TimeoutError(status, error, message, headers);
|
3025
|
+
if (502 === status) return new GatewayError(status, error, message, headers);
|
3026
|
+
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
3027
|
+
return new APIError(status, error, message, headers);
|
3028
|
+
}
|
3029
|
+
constructor(status, error, message, headers){
|
3030
|
+
var _error_error, _error_error1;
|
3031
|
+
super(`${APIError.makeMessage(status, error, message, headers)}`);
|
3032
|
+
this.status = status;
|
3033
|
+
this.headers = headers;
|
3034
|
+
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
3035
|
+
// this.error = error;
|
3036
|
+
this.code = null == error ? void 0 : error.code;
|
3037
|
+
this.msg = null == error ? void 0 : error.msg;
|
3038
|
+
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
3039
|
+
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
3040
|
+
this.rawError = error;
|
3041
|
+
}
|
3042
|
+
}
|
3043
|
+
class APIConnectionError extends APIError {
|
3044
|
+
constructor({ message, cause }){
|
3045
|
+
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
3046
|
+
// if (cause) {
|
3047
|
+
// this.cause = cause;
|
3048
|
+
// }
|
3049
|
+
}
|
3050
|
+
}
|
3051
|
+
class APIUserAbortError extends APIError {
|
3052
|
+
constructor(message){
|
3053
|
+
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
3054
|
+
}
|
3055
|
+
}
|
3056
|
+
class BadRequestError extends APIError {
|
3057
|
+
constructor(...args){
|
3058
|
+
super(...args), this.name = 'BadRequestError', this.status = 400;
|
3059
|
+
}
|
3060
|
+
}
|
3061
|
+
class AuthenticationError extends APIError {
|
3062
|
+
constructor(...args){
|
3063
|
+
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
3064
|
+
}
|
3065
|
+
}
|
3066
|
+
class PermissionDeniedError extends APIError {
|
3067
|
+
constructor(...args){
|
3068
|
+
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
3069
|
+
}
|
3070
|
+
}
|
3071
|
+
class NotFoundError extends APIError {
|
3072
|
+
constructor(...args){
|
3073
|
+
super(...args), this.name = 'NotFoundError', this.status = 404;
|
3074
|
+
}
|
3075
|
+
}
|
3076
|
+
class TimeoutError extends APIError {
|
3077
|
+
constructor(...args){
|
3078
|
+
super(...args), this.name = 'TimeoutError', this.status = 408;
|
3079
|
+
}
|
3080
|
+
}
|
3081
|
+
class RateLimitError extends APIError {
|
3082
|
+
constructor(...args){
|
3083
|
+
super(...args), this.name = 'RateLimitError', this.status = 429;
|
3084
|
+
}
|
3085
|
+
}
|
3086
|
+
class InternalServerError extends APIError {
|
3087
|
+
constructor(...args){
|
3088
|
+
super(...args), this.name = 'InternalServerError', this.status = 500;
|
3089
|
+
}
|
3090
|
+
}
|
3091
|
+
class GatewayError extends APIError {
|
3092
|
+
constructor(...args){
|
3093
|
+
super(...args), this.name = 'GatewayError', this.status = 502;
|
3094
|
+
}
|
3095
|
+
}
|
3096
|
+
const castToError = (err)=>{
|
3097
|
+
if (err instanceof Error) return err;
|
3098
|
+
return new Error(err);
|
3099
|
+
};
|
3100
|
+
class Messages extends APIResource {
|
3101
|
+
/**
|
3102
|
+
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
3103
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
3104
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
3105
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3106
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3107
|
+
* @returns An array of chat messages. | 对话消息数组。
|
3108
|
+
*/ async list(conversation_id, chat_id, options) {
|
3109
|
+
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3110
|
+
const result = await this._client.get(apiUrl, void 0, false, options);
|
3111
|
+
return result.data;
|
3112
|
+
}
|
3113
|
+
}
|
3114
|
+
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
3115
|
+
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
3116
|
+
...i,
|
3117
|
+
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
3118
|
+
}));
|
3119
|
+
class Chat extends APIResource {
|
3120
|
+
/**
|
3121
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3122
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3123
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3124
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3125
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3126
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3127
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3128
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
3129
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3130
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3131
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3132
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3133
|
+
* @returns The data of the created chat. | 创建的对话数据。
|
3134
|
+
*/ async create(params, options) {
|
3135
|
+
if (!params.user_id) params.user_id = uuid();
|
3136
|
+
const { conversation_id, ...rest } = params;
|
3137
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3138
|
+
const payload = {
|
3139
|
+
...rest,
|
3140
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3141
|
+
stream: false
|
3142
|
+
};
|
3143
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
3144
|
+
return result.data;
|
3145
|
+
}
|
3146
|
+
/**
|
3147
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3148
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3149
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3150
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3151
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3152
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3153
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3154
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3155
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3156
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3157
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3158
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3159
|
+
* @returns
|
3160
|
+
*/ async createAndPoll(params, options) {
|
3161
|
+
if (!params.user_id) params.user_id = uuid();
|
3162
|
+
const { conversation_id, ...rest } = params;
|
3163
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3164
|
+
const payload = {
|
3165
|
+
...rest,
|
3166
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3167
|
+
stream: false
|
3168
|
+
};
|
3169
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
3170
|
+
const chatId = result.data.id;
|
3171
|
+
const conversationId = result.data.conversation_id;
|
3172
|
+
let chat;
|
3173
|
+
while(true){
|
3174
|
+
await sleep(100);
|
3175
|
+
chat = await this.retrieve(conversationId, chatId);
|
3176
|
+
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
3177
|
+
}
|
3178
|
+
const messageList = await this.messages.list(conversationId, chatId);
|
3179
|
+
return {
|
3180
|
+
chat,
|
3181
|
+
messages: messageList
|
3182
|
+
};
|
3183
|
+
}
|
3184
|
+
/**
|
3185
|
+
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
3186
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3187
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3188
|
+
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
3189
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3190
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3191
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3192
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3193
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3194
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3195
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3196
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3197
|
+
* @returns A stream of chat data. | 对话数据流。
|
3198
|
+
*/ async *stream(params, options) {
|
3199
|
+
if (!params.user_id) params.user_id = uuid();
|
3200
|
+
const { conversation_id, ...rest } = params;
|
3201
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3202
|
+
const payload = {
|
3203
|
+
...rest,
|
3204
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3205
|
+
stream: true
|
3206
|
+
};
|
3207
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
3208
|
+
for await (const message of result)if ("done" === message.event) {
|
3209
|
+
const ret = {
|
3210
|
+
event: message.event,
|
3211
|
+
data: '[DONE]'
|
3212
|
+
};
|
3213
|
+
yield ret;
|
3214
|
+
} else try {
|
3215
|
+
const ret = {
|
3216
|
+
event: message.event,
|
3217
|
+
data: JSON.parse(message.data)
|
3218
|
+
};
|
3219
|
+
yield ret;
|
3220
|
+
} catch (error) {
|
3221
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3222
|
+
}
|
3223
|
+
}
|
3224
|
+
/**
|
3225
|
+
* Get the detailed information of the chat. | 查看对话的详细信息。
|
3226
|
+
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
3227
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
3228
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3229
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3230
|
+
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
3231
|
+
*/ async retrieve(conversation_id, chat_id, options) {
|
3232
|
+
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3233
|
+
const result = await this._client.post(apiUrl, void 0, false, options);
|
3234
|
+
return result.data;
|
3235
|
+
}
|
3236
|
+
/**
|
3237
|
+
* Cancel a chat session. | 取消对话会话。
|
3238
|
+
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
3239
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
3240
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3241
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3242
|
+
* @returns The data of the canceled chat. | 取消的对话数据。
|
3243
|
+
*/ async cancel(conversation_id, chat_id, options) {
|
3244
|
+
const apiUrl = '/v3/chat/cancel';
|
3245
|
+
const payload = {
|
3246
|
+
conversation_id,
|
3247
|
+
chat_id
|
3248
|
+
};
|
3249
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
3250
|
+
return result.data;
|
3251
|
+
}
|
3252
|
+
/**
|
3253
|
+
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
3254
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
3255
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
3256
|
+
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
3257
|
+
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
3258
|
+
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
3259
|
+
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
3260
|
+
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
3261
|
+
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
3262
|
+
*/ async *submitToolOutputs(params, options) {
|
3263
|
+
const { conversation_id, chat_id, ...rest } = params;
|
3264
|
+
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
3265
|
+
const payload = {
|
3266
|
+
...rest
|
3267
|
+
};
|
3268
|
+
if (false === params.stream) {
|
3269
|
+
const response = await this._client.post(apiUrl, payload, false, options);
|
3270
|
+
return response.data;
|
3271
|
+
}
|
3272
|
+
{
|
3273
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
3274
|
+
for await (const message of result)if ("done" === message.event) {
|
3275
|
+
const ret = {
|
3276
|
+
event: message.event,
|
3277
|
+
data: '[DONE]'
|
3278
|
+
};
|
3279
|
+
yield ret;
|
3280
|
+
} else try {
|
3281
|
+
const ret = {
|
3282
|
+
event: message.event,
|
3283
|
+
data: JSON.parse(message.data)
|
3284
|
+
};
|
3285
|
+
yield ret;
|
3136
3286
|
} catch (error) {
|
3137
|
-
|
3138
|
-
break;
|
3287
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3139
3288
|
}
|
3140
3289
|
}
|
3141
|
-
try {
|
3142
|
-
promise = dispatchRequest.call(this, newConfig);
|
3143
|
-
} catch (error) {
|
3144
|
-
return Promise.reject(error);
|
3145
|
-
}
|
3146
|
-
i = 0;
|
3147
|
-
len = responseInterceptorChain.length;
|
3148
|
-
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
3149
|
-
return promise;
|
3150
3290
|
}
|
3151
|
-
|
3152
|
-
|
3153
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
3154
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
3291
|
+
constructor(...args){
|
3292
|
+
super(...args), this.messages = new Messages(this._client);
|
3155
3293
|
}
|
3156
3294
|
}
|
3157
|
-
|
3158
|
-
|
3159
|
-
|
3160
|
-
|
3161
|
-
|
3162
|
-
|
3163
|
-
|
3164
|
-
|
3165
|
-
|
3166
|
-
|
3167
|
-
|
3168
|
-
|
3169
|
-
|
3170
|
-
|
3171
|
-
|
3172
|
-
|
3173
|
-
|
3174
|
-
|
3175
|
-
|
3176
|
-
|
3177
|
-
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3185
|
-
|
3186
|
-
}));
|
3187
|
-
};
|
3295
|
+
var chat_ChatEventType = /*#__PURE__*/ function(ChatEventType) {
|
3296
|
+
ChatEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
|
3297
|
+
ChatEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
|
3298
|
+
ChatEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
|
3299
|
+
ChatEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
|
3300
|
+
ChatEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
|
3301
|
+
ChatEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
|
3302
|
+
ChatEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
|
3303
|
+
ChatEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
|
3304
|
+
ChatEventType["DONE"] = "done";
|
3305
|
+
ChatEventType["ERROR"] = "error";
|
3306
|
+
return ChatEventType;
|
3307
|
+
}({});
|
3308
|
+
class messages_Messages extends APIResource {
|
3309
|
+
/**
|
3310
|
+
* Create a message and add it to the specified conversation. | 创建一条消息,并将其添加到指定的会话中。
|
3311
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_message?_lang=en
|
3312
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_message?_lang=zh
|
3313
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3314
|
+
* @param params - Required The parameters for creating a message | 创建消息所需的参数
|
3315
|
+
* @param params.role - Required The entity that sent this message. Possible values: user, assistant. | 发送这条消息的实体。取值:user, assistant。
|
3316
|
+
* @param params.content - Required The content of the message. | 消息的内容。
|
3317
|
+
* @param params.content_type - Required The type of the message content. | 消息内容的类型。
|
3318
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
3319
|
+
* @returns Information about the new message. | 消息详情。
|
3320
|
+
*/ async create(conversation_id, params, options) {
|
3321
|
+
const apiUrl = `/v1/conversation/message/create?conversation_id=${conversation_id}`;
|
3322
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3323
|
+
return response.data;
|
3188
3324
|
}
|
3189
|
-
|
3190
|
-
|
3191
|
-
|
3192
|
-
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
this.
|
3204
|
-
|
3205
|
-
});
|
3206
|
-
const token = this;
|
3207
|
-
// eslint-disable-next-line func-names
|
3208
|
-
this.promise.then((cancel)=>{
|
3209
|
-
if (!token._listeners) return;
|
3210
|
-
let i = token._listeners.length;
|
3211
|
-
while(i-- > 0)token._listeners[i](cancel);
|
3212
|
-
token._listeners = null;
|
3213
|
-
});
|
3214
|
-
// eslint-disable-next-line func-names
|
3215
|
-
this.promise.then = (onfulfilled)=>{
|
3216
|
-
let _resolve;
|
3217
|
-
// eslint-disable-next-line func-names
|
3218
|
-
const promise = new Promise((resolve)=>{
|
3219
|
-
token.subscribe(resolve);
|
3220
|
-
_resolve = resolve;
|
3221
|
-
}).then(onfulfilled);
|
3222
|
-
promise.cancel = function() {
|
3223
|
-
token.unsubscribe(_resolve);
|
3224
|
-
};
|
3225
|
-
return promise;
|
3226
|
-
};
|
3227
|
-
executor(function(message, config, request) {
|
3228
|
-
if (token.reason) // Cancellation has already been requested
|
3229
|
-
return;
|
3230
|
-
token.reason = new CanceledError(message, config, request);
|
3231
|
-
resolvePromise(token.reason);
|
3232
|
-
});
|
3325
|
+
/**
|
3326
|
+
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
3327
|
+
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
3328
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
3329
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3330
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3331
|
+
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
3332
|
+
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
3333
|
+
* @param params.content - Optional The content of the message. | 消息的内容。
|
3334
|
+
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
3335
|
+
* @returns Information about the modified message. | 消息详情。
|
3336
|
+
*/ // eslint-disable-next-line max-params
|
3337
|
+
async update(conversation_id, message_id, params, options) {
|
3338
|
+
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3339
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3340
|
+
return response.message;
|
3233
3341
|
}
|
3234
3342
|
/**
|
3235
|
-
*
|
3236
|
-
|
3237
|
-
|
3343
|
+
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
3344
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
3345
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
3346
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3347
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3348
|
+
* @returns Information about the message. | 消息详情。
|
3349
|
+
*/ async retrieve(conversation_id, message_id, options) {
|
3350
|
+
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3351
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
3352
|
+
return response.data;
|
3238
3353
|
}
|
3239
3354
|
/**
|
3240
|
-
*
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
|
3246
|
-
|
3247
|
-
|
3248
|
-
|
3249
|
-
|
3355
|
+
* List messages in a conversation. | 列出会话中的消息。
|
3356
|
+
* @docs en: https://www.coze.com/docs/developer_guides/message_list?_lang=en
|
3357
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/message_list?_lang=zh
|
3358
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3359
|
+
* @param params - Optional The parameters for listing messages | 列出消息所需的参数
|
3360
|
+
* @param params.order - Optional The order of the messages. | 消息的顺序。
|
3361
|
+
* @param params.chat_id - Optional The ID of the chat. | 聊天 ID。
|
3362
|
+
* @param params.before_id - Optional The ID of the message before which to list. | 列出此消息之前的消息 ID。
|
3363
|
+
* @param params.after_id - Optional The ID of the message after which to list. | 列出此消息之后的消息 ID。
|
3364
|
+
* @param params.limit - Optional The maximum number of messages to return. | 返回的最大消息数。
|
3365
|
+
* @returns A list of messages. | 消息列表。
|
3366
|
+
*/ async list(conversation_id, params, options) {
|
3367
|
+
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
3368
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3369
|
+
return response;
|
3250
3370
|
}
|
3251
3371
|
/**
|
3252
|
-
*
|
3253
|
-
|
3254
|
-
|
3255
|
-
|
3256
|
-
|
3372
|
+
* Call the API to delete a message within a specified conversation. | 调用接口在指定会话中删除消息。
|
3373
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_message?_lang=en
|
3374
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_message?_lang=zh
|
3375
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3376
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3377
|
+
* @returns Details of the deleted message. | 已删除的消息详情。
|
3378
|
+
*/ async delete(conversation_id, message_id, options) {
|
3379
|
+
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3380
|
+
const response = await this._client.post(apiUrl, void 0, false, options);
|
3381
|
+
return response.data;
|
3257
3382
|
}
|
3258
|
-
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3383
|
+
}
|
3384
|
+
class Conversations extends APIResource {
|
3385
|
+
/**
|
3386
|
+
* Create a conversation. Conversation is an interaction between an agent and a user, including one or more messages. | 调用接口创建一个会话。
|
3387
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_conversation?_lang=en
|
3388
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_conversation?_lang=zh
|
3389
|
+
* @param params - Required The parameters for creating a conversation | 创建会话所需的参数
|
3390
|
+
* @param params.messages - Optional Messages in the conversation. | 会话中的消息内容。
|
3391
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
3392
|
+
* @param params.bot_id - Optional Bind and isolate conversation on different bots. | 绑定和隔离不同Bot的会话。
|
3393
|
+
* @returns Information about the created conversation. | 会话的基础信息。
|
3394
|
+
*/ async create(params, options) {
|
3395
|
+
const apiUrl = '/v1/conversation/create';
|
3396
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3397
|
+
return response.data;
|
3266
3398
|
}
|
3267
3399
|
/**
|
3268
|
-
*
|
3269
|
-
*
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
}
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3400
|
+
* Get the information of specific conversation. | 通过会话 ID 查看会话信息。
|
3401
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_conversation?_lang=en
|
3402
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_conversation?_lang=zh
|
3403
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3404
|
+
* @returns Information about the conversation. | 会话的基础信息。
|
3405
|
+
*/ async retrieve(conversation_id, options) {
|
3406
|
+
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
3407
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
3408
|
+
return response.data;
|
3409
|
+
}
|
3410
|
+
/**
|
3411
|
+
* List all conversations. | 列出 Bot 下所有会话。
|
3412
|
+
* @param params
|
3413
|
+
* @param params.bot_id - Required Bot ID. | Bot ID。
|
3414
|
+
* @param params.page_num - Optional The page number. | 页码,默认值为 1。
|
3415
|
+
* @param params.page_size - Optional The number of conversations per page. | 每页的会话数量,默认值为 50。
|
3416
|
+
* @returns Information about the conversations. | 会话的信息。
|
3417
|
+
*/ async list(params, options) {
|
3418
|
+
const apiUrl = '/v1/conversations';
|
3419
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
3420
|
+
return response.data;
|
3421
|
+
}
|
3422
|
+
/**
|
3423
|
+
* Clear a conversation. | 清空会话。
|
3424
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3425
|
+
* @returns Information about the conversation session. | 会话的会话 ID。
|
3426
|
+
*/ async clear(conversation_id, options) {
|
3427
|
+
const apiUrl = `/v1/conversations/${conversation_id}/clear`;
|
3428
|
+
const response = await this._client.post(apiUrl, null, false, options);
|
3429
|
+
return response.data;
|
3430
|
+
}
|
3431
|
+
constructor(...args){
|
3432
|
+
super(...args), this.messages = new messages_Messages(this._client);
|
3279
3433
|
}
|
3280
3434
|
}
|
3281
|
-
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
3282
|
-
/**
|
3283
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
3284
|
-
*
|
3285
|
-
* Common use case would be to use `Function.prototype.apply`.
|
3286
|
-
*
|
3287
|
-
* ```js
|
3288
|
-
* function f(x, y, z) {}
|
3289
|
-
* var args = [1, 2, 3];
|
3290
|
-
* f.apply(null, args);
|
3291
|
-
* ```
|
3292
|
-
*
|
3293
|
-
* With `spread` this example can be re-written.
|
3294
|
-
*
|
3295
|
-
* ```js
|
3296
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
3297
|
-
* ```
|
3298
|
-
*
|
3299
|
-
* @param {Function} callback
|
3300
|
-
*
|
3301
|
-
* @returns {Function}
|
3302
|
-
*/ function spread(callback) {
|
3303
|
-
return function(arr) {
|
3304
|
-
return callback.apply(null, arr);
|
3305
|
-
};
|
3306
|
-
}
|
3307
|
-
/**
|
3308
|
-
* Determines whether the payload is an error thrown by Axios
|
3309
|
-
*
|
3310
|
-
* @param {*} payload The value to test
|
3311
|
-
*
|
3312
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
3313
|
-
*/ function isAxiosError(payload) {
|
3314
|
-
return utils.isObject(payload) && true === payload.isAxiosError;
|
3315
|
-
}
|
3316
|
-
const HttpStatusCode = {
|
3317
|
-
Continue: 100,
|
3318
|
-
SwitchingProtocols: 101,
|
3319
|
-
Processing: 102,
|
3320
|
-
EarlyHints: 103,
|
3321
|
-
Ok: 200,
|
3322
|
-
Created: 201,
|
3323
|
-
Accepted: 202,
|
3324
|
-
NonAuthoritativeInformation: 203,
|
3325
|
-
NoContent: 204,
|
3326
|
-
ResetContent: 205,
|
3327
|
-
PartialContent: 206,
|
3328
|
-
MultiStatus: 207,
|
3329
|
-
AlreadyReported: 208,
|
3330
|
-
ImUsed: 226,
|
3331
|
-
MultipleChoices: 300,
|
3332
|
-
MovedPermanently: 301,
|
3333
|
-
Found: 302,
|
3334
|
-
SeeOther: 303,
|
3335
|
-
NotModified: 304,
|
3336
|
-
UseProxy: 305,
|
3337
|
-
Unused: 306,
|
3338
|
-
TemporaryRedirect: 307,
|
3339
|
-
PermanentRedirect: 308,
|
3340
|
-
BadRequest: 400,
|
3341
|
-
Unauthorized: 401,
|
3342
|
-
PaymentRequired: 402,
|
3343
|
-
Forbidden: 403,
|
3344
|
-
NotFound: 404,
|
3345
|
-
MethodNotAllowed: 405,
|
3346
|
-
NotAcceptable: 406,
|
3347
|
-
ProxyAuthenticationRequired: 407,
|
3348
|
-
RequestTimeout: 408,
|
3349
|
-
Conflict: 409,
|
3350
|
-
Gone: 410,
|
3351
|
-
LengthRequired: 411,
|
3352
|
-
PreconditionFailed: 412,
|
3353
|
-
PayloadTooLarge: 413,
|
3354
|
-
UriTooLong: 414,
|
3355
|
-
UnsupportedMediaType: 415,
|
3356
|
-
RangeNotSatisfiable: 416,
|
3357
|
-
ExpectationFailed: 417,
|
3358
|
-
ImATeapot: 418,
|
3359
|
-
MisdirectedRequest: 421,
|
3360
|
-
UnprocessableEntity: 422,
|
3361
|
-
Locked: 423,
|
3362
|
-
FailedDependency: 424,
|
3363
|
-
TooEarly: 425,
|
3364
|
-
UpgradeRequired: 426,
|
3365
|
-
PreconditionRequired: 428,
|
3366
|
-
TooManyRequests: 429,
|
3367
|
-
RequestHeaderFieldsTooLarge: 431,
|
3368
|
-
UnavailableForLegalReasons: 451,
|
3369
|
-
InternalServerError: 500,
|
3370
|
-
NotImplemented: 501,
|
3371
|
-
BadGateway: 502,
|
3372
|
-
ServiceUnavailable: 503,
|
3373
|
-
GatewayTimeout: 504,
|
3374
|
-
HttpVersionNotSupported: 505,
|
3375
|
-
VariantAlsoNegotiates: 506,
|
3376
|
-
InsufficientStorage: 507,
|
3377
|
-
LoopDetected: 508,
|
3378
|
-
NotExtended: 510,
|
3379
|
-
NetworkAuthenticationRequired: 511
|
3380
|
-
};
|
3381
|
-
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
3382
|
-
HttpStatusCode[value] = key;
|
3383
|
-
});
|
3384
|
-
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
3385
|
-
/**
|
3386
|
-
* Create an instance of Axios
|
3387
|
-
*
|
3388
|
-
* @param {Object} defaultConfig The default config for the instance
|
3389
|
-
*
|
3390
|
-
* @returns {Axios} A new instance of Axios
|
3391
|
-
*/ function createInstance(defaultConfig) {
|
3392
|
-
const context = new Axios(defaultConfig);
|
3393
|
-
const instance = bind(Axios.prototype.request, context);
|
3394
|
-
// Copy axios.prototype to instance
|
3395
|
-
utils.extend(instance, Axios.prototype, context, {
|
3396
|
-
allOwnKeys: true
|
3397
|
-
});
|
3398
|
-
// Copy context to instance
|
3399
|
-
utils.extend(instance, context, null, {
|
3400
|
-
allOwnKeys: true
|
3401
|
-
});
|
3402
|
-
// Factory for creating new instances
|
3403
|
-
instance.create = function(instanceConfig) {
|
3404
|
-
return createInstance(mergeConfig_mergeConfig(defaultConfig, instanceConfig));
|
3405
|
-
};
|
3406
|
-
return instance;
|
3407
|
-
}
|
3408
|
-
// Create the default instance to be exported
|
3409
|
-
const axios = createInstance(defaults);
|
3410
|
-
// Expose Axios class to allow class inheritance
|
3411
|
-
axios.Axios = Axios;
|
3412
|
-
// Expose Cancel & CancelToken
|
3413
|
-
axios.CanceledError = CanceledError;
|
3414
|
-
axios.CancelToken = CancelToken;
|
3415
|
-
axios.isCancel = isCancel;
|
3416
|
-
axios.VERSION = VERSION;
|
3417
|
-
axios.toFormData = toFormData;
|
3418
|
-
// Expose AxiosError class
|
3419
|
-
axios.AxiosError = core_AxiosError;
|
3420
|
-
// alias for CanceledError for backward compatibility
|
3421
|
-
axios.Cancel = axios.CanceledError;
|
3422
|
-
// Expose all/spread
|
3423
|
-
axios.all = function(promises) {
|
3424
|
-
return Promise.all(promises);
|
3425
|
-
};
|
3426
|
-
axios.spread = spread;
|
3427
|
-
// Expose isAxiosError
|
3428
|
-
axios.isAxiosError = isAxiosError;
|
3429
|
-
// Expose mergeConfig
|
3430
|
-
axios.mergeConfig = mergeConfig_mergeConfig;
|
3431
|
-
axios.AxiosHeaders = AxiosHeaders;
|
3432
|
-
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
3433
|
-
axios.getAdapter = adapters_adapters.getAdapter;
|
3434
|
-
axios.HttpStatusCode = helpers_HttpStatusCode;
|
3435
|
-
axios.default = axios;
|
3436
|
-
// this module should only have a default export
|
3437
|
-
/* ESM default export */ const lib_axios = axios;
|
3438
|
-
// This module is intended to unwrap Axios default export as named.
|
3439
|
-
// Keep top-level export same with static properties
|
3440
|
-
// so that it can keep same with es module or cjs
|
3441
|
-
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;
|
3442
3435
|
class Files extends APIResource {
|
3443
3436
|
/**
|
3444
3437
|
* Upload files to Coze platform. | 调用接口上传文件到扣子。
|
@@ -3601,7 +3594,7 @@
|
|
3601
3594
|
* @returns ListDocumentData | 知识库文件列表
|
3602
3595
|
*/ list(params, options) {
|
3603
3596
|
const apiUrl = '/open_api/knowledge/document/list';
|
3604
|
-
const response = this._client.get(apiUrl, params, false,
|
3597
|
+
const response = this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
|
3605
3598
|
headers: documents_headers
|
3606
3599
|
}));
|
3607
3600
|
return response;
|
@@ -3619,7 +3612,7 @@
|
|
3619
3612
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3620
3613
|
*/ async create(params, options) {
|
3621
3614
|
const apiUrl = '/open_api/knowledge/document/create';
|
3622
|
-
const response = await this._client.post(apiUrl, params, false,
|
3615
|
+
const response = await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3623
3616
|
headers: documents_headers
|
3624
3617
|
}));
|
3625
3618
|
return response.document_infos;
|
@@ -3635,7 +3628,7 @@
|
|
3635
3628
|
* @returns void | 无返回
|
3636
3629
|
*/ async delete(params, options) {
|
3637
3630
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3638
|
-
await this._client.post(apiUrl, params, false,
|
3631
|
+
await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3639
3632
|
headers: documents_headers
|
3640
3633
|
}));
|
3641
3634
|
}
|
@@ -3651,7 +3644,7 @@
|
|
3651
3644
|
* @returns void | 无返回
|
3652
3645
|
*/ async update(params, options) {
|
3653
3646
|
const apiUrl = '/open_api/knowledge/document/update';
|
3654
|
-
await this._client.post(apiUrl, params, false,
|
3647
|
+
await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3655
3648
|
headers: documents_headers
|
3656
3649
|
}));
|
3657
3650
|
}
|
@@ -3677,9 +3670,9 @@
|
|
3677
3670
|
* @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
|
3678
3671
|
* @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
|
3679
3672
|
* @returns ListDocumentData | 知识库文件列表
|
3680
|
-
*/ list(params, options) {
|
3673
|
+
*/ async list(params, options) {
|
3681
3674
|
const apiUrl = '/open_api/knowledge/document/list';
|
3682
|
-
const response = this._client.get(apiUrl, params, false,
|
3675
|
+
const response = await this._client.get(apiUrl, params, false, esm_mergeConfig(options, {
|
3683
3676
|
headers: documents_documents_headers
|
3684
3677
|
}));
|
3685
3678
|
return response;
|
@@ -3695,7 +3688,7 @@
|
|
3695
3688
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3696
3689
|
*/ async create(params, options) {
|
3697
3690
|
const apiUrl = '/open_api/knowledge/document/create';
|
3698
|
-
const response = await this._client.post(apiUrl, params, false,
|
3691
|
+
const response = await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3699
3692
|
headers: documents_documents_headers
|
3700
3693
|
}));
|
3701
3694
|
return response.document_infos;
|
@@ -3709,7 +3702,7 @@
|
|
3709
3702
|
* @returns void | 无返回
|
3710
3703
|
*/ async delete(params, options) {
|
3711
3704
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3712
|
-
await this._client.post(apiUrl, params, false,
|
3705
|
+
await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3713
3706
|
headers: documents_documents_headers
|
3714
3707
|
}));
|
3715
3708
|
}
|
@@ -3723,14 +3716,109 @@
|
|
3723
3716
|
* @returns void | 无返回
|
3724
3717
|
*/ async update(params, options) {
|
3725
3718
|
const apiUrl = '/open_api/knowledge/document/update';
|
3726
|
-
await this._client.post(apiUrl, params, false,
|
3719
|
+
await this._client.post(apiUrl, params, false, esm_mergeConfig(options, {
|
3727
3720
|
headers: documents_documents_headers
|
3728
3721
|
}));
|
3729
3722
|
}
|
3730
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
|
+
}
|
3731
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
|
+
}
|
3732
3820
|
constructor(...args){
|
3733
|
-
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);
|
3734
3822
|
}
|
3735
3823
|
}
|
3736
3824
|
class Voices extends APIResource {
|
@@ -3787,7 +3875,10 @@
|
|
3787
3875
|
* @returns Speech synthesis data
|
3788
3876
|
*/ async create(params, options) {
|
3789
3877
|
const apiUrl = '/v1/audio/speech';
|
3790
|
-
const response = await this._client.post(apiUrl,
|
3878
|
+
const response = await this._client.post(apiUrl, {
|
3879
|
+
...params,
|
3880
|
+
sample_rate: params.sample_rate || 24000
|
3881
|
+
}, false, esm_mergeConfig(options, {
|
3791
3882
|
responseType: 'arraybuffer'
|
3792
3883
|
}));
|
3793
3884
|
return response;
|
@@ -3800,26 +3891,37 @@
|
|
3800
3891
|
return response.data;
|
3801
3892
|
}
|
3802
3893
|
}
|
3803
|
-
class
|
3894
|
+
class esm_Audio extends APIResource {
|
3804
3895
|
constructor(...args){
|
3805
3896
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3806
3897
|
}
|
3807
3898
|
}
|
3808
|
-
|
3809
|
-
|
3810
|
-
|
3811
|
-
|
3812
|
-
|
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
|
3914
|
+
const { version: esm_version } = package_namespaceObject;
|
3813
3915
|
const getEnv = ()=>{
|
3814
3916
|
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
3815
3917
|
const { platform } = process;
|
3816
3918
|
let osName = platform.toLowerCase();
|
3817
|
-
let osVersion =
|
3919
|
+
let osVersion = os_ignored_.release();
|
3818
3920
|
if ('darwin' === platform) {
|
3819
3921
|
osName = 'macos';
|
3820
3922
|
// Try to parse the macOS version
|
3821
3923
|
try {
|
3822
|
-
const darwinVersion =
|
3924
|
+
const darwinVersion = os_ignored_.release().split('.');
|
3823
3925
|
if (darwinVersion.length >= 2) {
|
3824
3926
|
const majorVersion = parseInt(darwinVersion[0], 10);
|
3825
3927
|
if (!isNaN(majorVersion) && majorVersion >= 9) {
|
@@ -3832,10 +3934,10 @@
|
|
3832
3934
|
}
|
3833
3935
|
} else if ('win32' === platform) {
|
3834
3936
|
osName = 'windows';
|
3835
|
-
osVersion =
|
3937
|
+
osVersion = os_ignored_.release();
|
3836
3938
|
} else if ('linux' === platform) {
|
3837
3939
|
osName = 'linux';
|
3838
|
-
osVersion =
|
3940
|
+
osVersion = os_ignored_.release();
|
3839
3941
|
}
|
3840
3942
|
return {
|
3841
3943
|
osName,
|
@@ -3845,12 +3947,12 @@
|
|
3845
3947
|
};
|
3846
3948
|
const getUserAgent = ()=>{
|
3847
3949
|
const { nodeVersion, osName, osVersion } = getEnv();
|
3848
|
-
return `coze-js/${
|
3950
|
+
return `coze-js/${esm_version} node/${nodeVersion} ${osName}/${osVersion}`.toLowerCase();
|
3849
3951
|
};
|
3850
3952
|
const getNodeClientUserAgent = ()=>{
|
3851
3953
|
const { osVersion, nodeVersion, osName } = getEnv();
|
3852
3954
|
const ua = {
|
3853
|
-
version:
|
3955
|
+
version: esm_version,
|
3854
3956
|
lang: 'node',
|
3855
3957
|
lang_version: nodeVersion,
|
3856
3958
|
os_name: osName,
|
@@ -3858,17 +3960,64 @@
|
|
3858
3960
|
};
|
3859
3961
|
return JSON.stringify(ua);
|
3860
3962
|
};
|
3861
|
-
|
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
|
+
};
|
4012
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ const esm_handleError = (error)=>{
|
3862
4013
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3863
4014
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
3864
4015
|
var _error_response;
|
3865
4016
|
return new TimeoutError(408, void 0, `Request timed out: ${error.message}`, null === (_error_response = error.response) || void 0 === _error_response ? void 0 : _error_response.headers);
|
3866
4017
|
}
|
3867
4018
|
if ('ERR_CANCELED' === error.code) return new APIUserAbortError(error.message);
|
3868
|
-
|
3869
|
-
|
3870
|
-
return error_APIError.generate((null === (_error_response1 = error.response) || void 0 === _error_response1 ? void 0 : _error_response1.status) || 500, null === (_error_response2 = error.response) || void 0 === _error_response2 ? void 0 : _error_response2.data, error.message, null === (_error_response3 = error.response) || void 0 === _error_response3 ? void 0 : _error_response3.headers);
|
3871
|
-
}
|
4019
|
+
var _error_response1, _error_response2, _error_response3;
|
4020
|
+
return APIError.generate((null === (_error_response1 = error.response) || void 0 === _error_response1 ? void 0 : _error_response1.status) || 500, null === (_error_response2 = error.response) || void 0 === _error_response2 ? void 0 : _error_response2.data, error.message, null === (_error_response3 = error.response) || void 0 === _error_response3 ? void 0 : _error_response3.headers);
|
3872
4021
|
};
|
3873
4022
|
async function fetchAPI(url) {
|
3874
4023
|
let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
|
@@ -3884,7 +4033,7 @@
|
|
3884
4033
|
adapter: options.isStreaming ? 'fetch' : void 0,
|
3885
4034
|
...options
|
3886
4035
|
}).catch((error)=>{
|
3887
|
-
throw
|
4036
|
+
throw esm_handleError(error);
|
3888
4037
|
});
|
3889
4038
|
return {
|
3890
4039
|
async *stream () {
|
@@ -3922,7 +4071,7 @@
|
|
3922
4071
|
buffer = lines[lines.length - 1]; // Keep the last incomplete line in the buffer
|
3923
4072
|
}
|
3924
4073
|
} catch (error) {
|
3925
|
-
|
4074
|
+
esm_handleError(error);
|
3926
4075
|
}
|
3927
4076
|
},
|
3928
4077
|
json: ()=>response.data,
|
@@ -3946,8 +4095,8 @@
|
|
3946
4095
|
}
|
3947
4096
|
/**
|
3948
4097
|
* default coze base URL is api.coze.com
|
3949
|
-
*/ const
|
3950
|
-
/* eslint-disable max-params */ class
|
4098
|
+
*/ const COZE_COM_BASE_URL = 'https://api.coze.com';
|
4099
|
+
/* eslint-disable max-params */ class APIClient {
|
3951
4100
|
async getToken() {
|
3952
4101
|
if ('function' == typeof this.token) return await this.token();
|
3953
4102
|
return this.token;
|
@@ -3957,11 +4106,12 @@
|
|
3957
4106
|
const headers = {
|
3958
4107
|
authorization: `Bearer ${token}`
|
3959
4108
|
};
|
3960
|
-
if (
|
4109
|
+
if (isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
|
4110
|
+
else {
|
3961
4111
|
headers['User-Agent'] = getUserAgent();
|
3962
4112
|
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
3963
4113
|
}
|
3964
|
-
const config =
|
4114
|
+
const config = esm_mergeConfig(this.axiosOptions, options, {
|
3965
4115
|
headers
|
3966
4116
|
});
|
3967
4117
|
config.method = method;
|
@@ -3985,7 +4135,7 @@
|
|
3985
4135
|
if (contentType && contentType.includes('application/json')) {
|
3986
4136
|
const result = await json();
|
3987
4137
|
const { code, msg } = result;
|
3988
|
-
if (0 !== code && void 0 !== code) throw
|
4138
|
+
if (0 !== code && void 0 !== code) throw APIError.generate(response.status, result, msg, response.headers);
|
3989
4139
|
}
|
3990
4140
|
return stream();
|
3991
4141
|
}
|
@@ -3993,7 +4143,7 @@
|
|
3993
4143
|
{
|
3994
4144
|
const result = await json();
|
3995
4145
|
const { code, msg } = result;
|
3996
|
-
if (0 !== code && void 0 !== code) throw
|
4146
|
+
if (0 !== code && void 0 !== code) throw APIError.generate(response.status, result, msg, response.headers);
|
3997
4147
|
return result;
|
3998
4148
|
}
|
3999
4149
|
}
|
@@ -4025,35 +4175,31 @@
|
|
4025
4175
|
}
|
4026
4176
|
constructor(config){
|
4027
4177
|
this._config = config;
|
4028
|
-
this.baseURL = config.baseURL ||
|
4178
|
+
this.baseURL = config.baseURL || COZE_COM_BASE_URL;
|
4029
4179
|
this.token = config.token;
|
4030
4180
|
this.axiosOptions = config.axiosOptions || {};
|
4031
4181
|
this.axiosInstance = config.axiosInstance;
|
4032
4182
|
this.debug = config.debug || false;
|
4033
4183
|
this.allowPersonalAccessTokenInBrowser = config.allowPersonalAccessTokenInBrowser || false;
|
4034
4184
|
this.headers = config.headers;
|
4035
|
-
if (
|
4036
|
-
}
|
4037
|
-
}
|
4038
|
-
|
4039
|
-
|
4040
|
-
|
4041
|
-
|
4042
|
-
|
4043
|
-
|
4044
|
-
|
4045
|
-
|
4046
|
-
|
4047
|
-
|
4048
|
-
|
4049
|
-
__webpack_require__("?666e");
|
4050
|
-
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
4051
|
-
__webpack_require__("?79fd");
|
4052
|
-
class CozeAPI extends core_APIClient {
|
4185
|
+
if (isBrowser() && 'function' != typeof this.token && isPersonalAccessToken(this.token) && !this.allowPersonalAccessTokenInBrowser) throw new CozeError('Browser environments do not support authentication using Personal Access Token (PAT) by default.\nas it may expose secret API keys. \n\nPlease use OAuth2.0 authentication mechanism. see:\nhttps://www.coze.com/docs/developer_guides/oauth_apps?_lang=en \n\nIf you need to force use, please set the `allowPersonalAccessTokenInBrowser` option to `true`. \n\ne.g new CozeAPI({ token, allowPersonalAccessTokenInBrowser: true });\n\n');
|
4186
|
+
}
|
4187
|
+
}
|
4188
|
+
APIClient.APIError = APIError;
|
4189
|
+
APIClient.BadRequestError = BadRequestError;
|
4190
|
+
APIClient.AuthenticationError = AuthenticationError;
|
4191
|
+
APIClient.PermissionDeniedError = PermissionDeniedError;
|
4192
|
+
APIClient.NotFoundError = NotFoundError;
|
4193
|
+
APIClient.RateLimitError = RateLimitError;
|
4194
|
+
APIClient.InternalServerError = InternalServerError;
|
4195
|
+
APIClient.GatewayError = GatewayError;
|
4196
|
+
APIClient.TimeoutError = TimeoutError;
|
4197
|
+
APIClient.UserAbortError = APIUserAbortError;
|
4198
|
+
class CozeAPI extends APIClient {
|
4053
4199
|
constructor(...args){
|
4054
4200
|
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4055
4201
|
* @deprecated
|
4056
|
-
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new
|
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);
|
4057
4203
|
}
|
4058
4204
|
}
|
4059
4205
|
/**
|
@@ -38438,7 +38584,7 @@
|
|
38438
38584
|
+ * @param milliseconds The time to sleep in milliseconds
|
38439
38585
|
+ * @throws {Error} If milliseconds is negative
|
38440
38586
|
+ * @returns Promise that resolves after the specified duration
|
38441
|
-
+ */ const
|
38587
|
+
+ */ const utils_sleep = (milliseconds)=>{
|
38442
38588
|
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
38443
38589
|
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
38444
38590
|
};
|
@@ -38458,7 +38604,11 @@
|
|
38458
38604
|
return false;
|
38459
38605
|
}
|
38460
38606
|
};
|
38461
|
-
|
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() {
|
38462
38612
|
let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
|
38463
38613
|
return await index_esm_min_index.enableDevices({
|
38464
38614
|
audio: true,
|
@@ -38471,7 +38621,16 @@
|
|
38471
38621
|
*/ const getAudioDevices = async function() {
|
38472
38622
|
let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
38473
38623
|
let devices = [];
|
38474
|
-
|
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 [
|
38475
38634
|
...await index_esm_min_index.enumerateAudioCaptureDevices(),
|
38476
38635
|
...await index_esm_min_index.enumerateAudioPlaybackDevices()
|
38477
38636
|
];
|
@@ -38486,6 +38645,14 @@
|
|
38486
38645
|
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
38487
38646
|
};
|
38488
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
|
+
}
|
38489
38656
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
38490
38657
|
RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
|
38491
38658
|
RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
|
@@ -38579,6 +38746,10 @@
|
|
38579
38746
|
* zh: 音频输出设备改变
|
38580
38747
|
*/ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
38581
38748
|
/**
|
38749
|
+
* en: Video input device changed
|
38750
|
+
* zh: 视频输入设备改变
|
38751
|
+
*/ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
|
38752
|
+
/**
|
38582
38753
|
* en: Bot joined
|
38583
38754
|
* zh: Bot 加入
|
38584
38755
|
*/ EventNames["BOT_JOIN"] = "server.bot.join";
|
@@ -41996,23 +42167,47 @@
|
|
41996
42167
|
if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
|
41997
42168
|
await this.engine.setAudioPlaybackDevice(deviceId);
|
41998
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
|
+
}
|
41999
42197
|
async createLocalStream(userId, videoConfig) {
|
42198
|
+
this._roomUserId = userId;
|
42000
42199
|
const devices = await getAudioDevices({
|
42001
42200
|
video: this._isSupportVideo
|
42002
42201
|
});
|
42003
42202
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
42004
42203
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
42005
42204
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
42006
|
-
if (this._isSupportVideo
|
42007
|
-
if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
|
42008
|
-
renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
|
42009
|
-
userId
|
42010
|
-
});
|
42205
|
+
if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
42011
42206
|
}
|
42012
42207
|
async disconnect() {
|
42013
42208
|
try {
|
42014
|
-
if (this._isSupportVideo) await this.
|
42015
|
-
await this.
|
42209
|
+
if (this._isSupportVideo) await this.changeVideoState(false);
|
42210
|
+
await this.changeAudioState(false);
|
42016
42211
|
await this.engine.unpublishStream(MediaType$1.AUDIO);
|
42017
42212
|
await this.engine.leaveRoom();
|
42018
42213
|
this.removeEventListener();
|
@@ -42032,8 +42227,19 @@
|
|
42032
42227
|
}
|
42033
42228
|
async changeVideoState(isVideoOn) {
|
42034
42229
|
try {
|
42035
|
-
if (isVideoOn)
|
42036
|
-
|
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
|
+
}
|
42037
42243
|
} catch (e) {
|
42038
42244
|
this.dispatch(event_handler_EventNames.ERROR, e);
|
42039
42245
|
throw e;
|
@@ -42111,7 +42317,7 @@
|
|
42111
42317
|
}
|
42112
42318
|
}
|
42113
42319
|
// eslint-disable-next-line max-params
|
42114
|
-
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
|
42320
|
+
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
|
42115
42321
|
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
42116
42322
|
if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
42117
42323
|
'rtc-test.bytedance.com'
|
@@ -42126,6 +42332,7 @@
|
|
42126
42332
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
42127
42333
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
42128
42334
|
this._isSupportVideo = isSupportVideo;
|
42335
|
+
this._videoConfig = videoConfig;
|
42129
42336
|
}
|
42130
42337
|
}
|
42131
42338
|
class RealtimeClient extends RealtimeEventHandler {
|
@@ -42150,7 +42357,7 @@
|
|
42150
42357
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
42151
42358
|
}
|
42152
42359
|
// Step2 create engine
|
42153
|
-
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);
|
42154
42361
|
// Step3 bind engine events
|
42155
42362
|
this._client.bindEngineEvents();
|
42156
42363
|
this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
|
@@ -42286,6 +42493,13 @@
|
|
42286
42493
|
deviceId
|
42287
42494
|
});
|
42288
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
|
+
}
|
42289
42503
|
/**
|
42290
42504
|
* Constructor for initializing a RealtimeClient instance.
|
42291
42505
|
*
|
@@ -42316,6 +42530,16 @@
|
|
42316
42530
|
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
42317
42531
|
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
42318
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 了解更多详情。
|
42319
42543
|
*/ constructor(config){
|
42320
42544
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
42321
42545
|
this._config = config;
|