@coze/realtime-api 1.0.3 → 1.0.4-alpha.2d8e39
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.cjs +1645 -1385
- package/dist/esm/index.js +1645 -1385
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- 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 +1645 -1385
- package/package.json +18 -15
- package/assets/api-overview.png +0 -0
package/dist/cjs/index.cjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
/*! For license information please see index.cjs.LICENSE.txt */
|
2
2
|
"use strict";
|
3
3
|
var __webpack_modules__ = {
|
4
|
-
"?
|
4
|
+
"?666e": function() {
|
5
5
|
/* (ignored) */ },
|
6
|
-
"?
|
6
|
+
"?79fd": function() {
|
7
7
|
/* (ignored) */ },
|
8
|
-
"?
|
8
|
+
"?9050": function() {
|
9
9
|
/* (ignored) */ }
|
10
10
|
};
|
11
11
|
/************************************************************************/ // The module cache
|
@@ -24,7 +24,22 @@ function __webpack_require__(moduleId) {
|
|
24
24
|
// Return the exports of the module
|
25
25
|
return module.exports;
|
26
26
|
}
|
27
|
-
/************************************************************************/ // webpack/runtime/
|
27
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
28
|
+
(()=>{
|
29
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
30
|
+
__webpack_require__.n = function(module) {
|
31
|
+
var getter = module && module.__esModule ? function() {
|
32
|
+
return module['default'];
|
33
|
+
} : function() {
|
34
|
+
return module;
|
35
|
+
};
|
36
|
+
__webpack_require__.d(getter, {
|
37
|
+
a: getter
|
38
|
+
});
|
39
|
+
return getter;
|
40
|
+
};
|
41
|
+
})();
|
42
|
+
// webpack/runtime/define_property_getters
|
28
43
|
(()=>{
|
29
44
|
__webpack_require__.d = function(exports1, definition) {
|
30
45
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
@@ -80,7 +95,7 @@ __webpack_require__.d(common_utils_namespaceObject, {
|
|
80
95
|
hasBrowserEnv: ()=>hasBrowserEnv,
|
81
96
|
hasStandardBrowserEnv: ()=>hasStandardBrowserEnv,
|
82
97
|
hasStandardBrowserWebWorkerEnv: ()=>hasStandardBrowserWebWorkerEnv,
|
83
|
-
navigator: ()=>
|
98
|
+
navigator: ()=>utils_navigator,
|
84
99
|
origin: ()=>origin
|
85
100
|
});
|
86
101
|
// NAMESPACE OBJECT: ./src/utils.ts
|
@@ -90,480 +105,1043 @@ __webpack_require__.d(src_utils_namespaceObject, {
|
|
90
105
|
checkDevicePermission: ()=>checkDevicePermission,
|
91
106
|
checkPermission: ()=>checkPermission,
|
92
107
|
getAudioDevices: ()=>getAudioDevices,
|
93
|
-
|
108
|
+
isScreenShareDevice: ()=>isScreenShareDevice,
|
109
|
+
isScreenShareSupported: ()=>isScreenShareSupported,
|
110
|
+
sleep: ()=>src_utils_sleep
|
94
111
|
});
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
112
|
+
class APIResource {
|
113
|
+
constructor(client){
|
114
|
+
this._client = client;
|
115
|
+
}
|
99
116
|
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
117
|
+
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
118
|
+
/**
|
119
|
+
* Create a new agent. | 调用接口创建一个新的智能体。
|
120
|
+
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
121
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
122
|
+
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
123
|
+
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
124
|
+
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
125
|
+
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
126
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
127
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
128
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
129
|
+
* @returns Information about the created bot. | 创建的 Bot 信息。
|
130
|
+
*/ async create(params, options) {
|
131
|
+
const apiUrl = '/v1/bot/create';
|
132
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
133
|
+
return result.data;
|
134
|
+
}
|
135
|
+
/**
|
136
|
+
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
137
|
+
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
138
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
139
|
+
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
140
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
141
|
+
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
142
|
+
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
143
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
144
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
145
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
146
|
+
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
147
|
+
* @returns Undefined | 无返回值
|
148
|
+
*/ async update(params, options) {
|
149
|
+
const apiUrl = '/v1/bot/update';
|
150
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
151
|
+
return result.data;
|
152
|
+
}
|
153
|
+
/**
|
154
|
+
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
155
|
+
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
156
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
157
|
+
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
158
|
+
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
159
|
+
* @param params.page_size - Optional Pagination size. | 分页大小。
|
160
|
+
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
161
|
+
* @returns List of published bots. | 已发布的 Bot 列表。
|
162
|
+
*/ async list(params, options) {
|
163
|
+
const apiUrl = '/v1/space/published_bots_list';
|
164
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
165
|
+
return result.data;
|
166
|
+
}
|
167
|
+
/**
|
168
|
+
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
169
|
+
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
170
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
171
|
+
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
172
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
173
|
+
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
174
|
+
* @returns Undefined | 无返回值
|
175
|
+
*/ async publish(params, options) {
|
176
|
+
const apiUrl = '/v1/bot/publish';
|
177
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
178
|
+
return result.data;
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
182
|
+
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
183
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
184
|
+
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
185
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
186
|
+
* @returns Information about the bot. | Bot 的配置信息。
|
187
|
+
*/ async retrieve(params, options) {
|
188
|
+
const apiUrl = '/v1/bot/get_online_info';
|
189
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
190
|
+
return result.data;
|
191
|
+
}
|
134
192
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
/**
|
143
|
-
* Determine if a value is a view on an ArrayBuffer
|
144
|
-
*
|
145
|
-
* @param {*} val The value to test
|
146
|
-
*
|
147
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
148
|
-
*/ function isArrayBufferView(val) {
|
149
|
-
let result;
|
150
|
-
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
151
|
-
return result;
|
193
|
+
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
194
|
+
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
195
|
+
try {
|
196
|
+
return JSON.parse(jsonString);
|
197
|
+
} catch (error) {
|
198
|
+
return defaultValue;
|
199
|
+
}
|
152
200
|
}
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
*
|
200
|
-
* @param {*} val The value to test
|
201
|
-
*
|
202
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
203
|
-
*/ const isDate = kindOfTest('Date');
|
204
|
-
/**
|
205
|
-
* Determine if a value is a File
|
206
|
-
*
|
207
|
-
* @param {*} val The value to test
|
208
|
-
*
|
209
|
-
* @returns {boolean} True if value is a File, otherwise false
|
210
|
-
*/ const isFile = kindOfTest('File');
|
211
|
-
/**
|
212
|
-
* Determine if a value is a Blob
|
213
|
-
*
|
214
|
-
* @param {*} val The value to test
|
215
|
-
*
|
216
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
217
|
-
*/ const isBlob = kindOfTest('Blob');
|
218
|
-
/**
|
219
|
-
* Determine if a value is a FileList
|
220
|
-
*
|
221
|
-
* @param {*} val The value to test
|
222
|
-
*
|
223
|
-
* @returns {boolean} True if value is a File, otherwise false
|
224
|
-
*/ const utils_isFileList = kindOfTest('FileList');
|
225
|
-
/**
|
226
|
-
* Determine if a value is a Stream
|
227
|
-
*
|
228
|
-
* @param {*} val The value to test
|
229
|
-
*
|
230
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
231
|
-
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
232
|
-
/**
|
233
|
-
* Determine if a value is a FormData
|
234
|
-
*
|
235
|
-
* @param {*} thing The value to test
|
236
|
-
*
|
237
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
238
|
-
*/ const utils_isFormData = (thing)=>{
|
239
|
-
let kind;
|
240
|
-
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
241
|
-
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
242
|
-
};
|
243
|
-
/**
|
244
|
-
* Determine if a value is a URLSearchParams object
|
245
|
-
*
|
246
|
-
* @param {*} val The value to test
|
247
|
-
*
|
248
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
249
|
-
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
250
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
251
|
-
'ReadableStream',
|
252
|
-
'Request',
|
253
|
-
'Response',
|
254
|
-
'Headers'
|
255
|
-
].map(kindOfTest);
|
256
|
-
/**
|
257
|
-
* Trim excess whitespace off the beginning and end of a string
|
258
|
-
*
|
259
|
-
* @param {String} str The String to trim
|
260
|
-
*
|
261
|
-
* @returns {String} The String freed of excess whitespace
|
262
|
-
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
263
|
-
/**
|
264
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
265
|
-
*
|
266
|
-
* If `obj` is an Array callback will be called passing
|
267
|
-
* the value, index, and complete array for each item.
|
268
|
-
*
|
269
|
-
* If 'obj' is an Object callback will be called passing
|
270
|
-
* the value, key, and complete object for each property.
|
271
|
-
*
|
272
|
-
* @param {Object|Array} obj The object to iterate
|
273
|
-
* @param {Function} fn The callback to invoke for each item
|
274
|
-
*
|
275
|
-
* @param {Boolean} [allOwnKeys = false]
|
276
|
-
* @returns {any}
|
277
|
-
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
278
|
-
// Don't bother if no value provided
|
279
|
-
if (null == obj) return;
|
280
|
-
let i;
|
281
|
-
let l;
|
282
|
-
// Force an array if not already something iterable
|
283
|
-
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
284
|
-
obj
|
285
|
-
];
|
286
|
-
if (isArray(obj)) // Iterate over array values
|
287
|
-
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
288
|
-
else {
|
289
|
-
// Iterate over object keys
|
290
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
291
|
-
const len = keys.length;
|
292
|
-
let key;
|
293
|
-
for(i = 0; i < len; i++){
|
294
|
-
key = keys[i];
|
295
|
-
fn.call(null, obj[key], key, obj);
|
201
|
+
function utils_sleep(ms) {
|
202
|
+
return new Promise((resolve)=>{
|
203
|
+
setTimeout(resolve, ms);
|
204
|
+
});
|
205
|
+
}
|
206
|
+
function utils_isBrowser() {
|
207
|
+
return 'undefined' != typeof window;
|
208
|
+
}
|
209
|
+
function isPlainObject(obj) {
|
210
|
+
if ('object' != typeof obj || null === obj) return false;
|
211
|
+
const proto = Object.getPrototypeOf(obj);
|
212
|
+
if (null === proto) return true;
|
213
|
+
let baseProto = proto;
|
214
|
+
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
215
|
+
return proto === baseProto;
|
216
|
+
}
|
217
|
+
function mergeConfig() {
|
218
|
+
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
219
|
+
return objects.reduce((result, obj)=>{
|
220
|
+
if (void 0 === obj) return result || {};
|
221
|
+
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
222
|
+
if (isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = mergeConfig(result[key] || {}, obj[key]);
|
223
|
+
else result[key] = obj[key];
|
224
|
+
}
|
225
|
+
return result;
|
226
|
+
}, {});
|
227
|
+
}
|
228
|
+
function isPersonalAccessToken(token) {
|
229
|
+
return null == token ? void 0 : token.startsWith('pat_');
|
230
|
+
}
|
231
|
+
/* eslint-disable max-params */ class CozeError extends Error {
|
232
|
+
}
|
233
|
+
class error_APIError extends CozeError {
|
234
|
+
static makeMessage(status, errorBody, message, headers) {
|
235
|
+
if (!errorBody && message) return message;
|
236
|
+
if (errorBody) {
|
237
|
+
const list = [];
|
238
|
+
const { code, msg, error } = errorBody;
|
239
|
+
if (code) list.push(`code: ${code}`);
|
240
|
+
if (msg) list.push(`msg: ${msg}`);
|
241
|
+
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
242
|
+
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
243
|
+
if (logId) list.push(`logid: ${logId}`);
|
244
|
+
const help_doc = null == error ? void 0 : error.help_doc;
|
245
|
+
if (help_doc) list.push(`help doc: ${help_doc}`);
|
246
|
+
return list.join(', ');
|
296
247
|
}
|
248
|
+
if (status) return `http status code: ${status} (no body)`;
|
249
|
+
return '(no status code or body)';
|
250
|
+
}
|
251
|
+
static generate(status, errorResponse, message, headers) {
|
252
|
+
if (!status) return new APIConnectionError({
|
253
|
+
cause: castToError(errorResponse)
|
254
|
+
});
|
255
|
+
const error = errorResponse;
|
256
|
+
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
257
|
+
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
258
|
+
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
259
|
+
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
260
|
+
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
261
|
+
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
262
|
+
if (408 === status) return new TimeoutError(status, error, message, headers);
|
263
|
+
if (502 === status) return new GatewayError(status, error, message, headers);
|
264
|
+
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
265
|
+
return new error_APIError(status, error, message, headers);
|
266
|
+
}
|
267
|
+
constructor(status, error, message, headers){
|
268
|
+
var _error_error, _error_error1;
|
269
|
+
super(`${error_APIError.makeMessage(status, error, message, headers)}`);
|
270
|
+
this.status = status;
|
271
|
+
this.headers = headers;
|
272
|
+
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
273
|
+
// this.error = error;
|
274
|
+
this.code = null == error ? void 0 : error.code;
|
275
|
+
this.msg = null == error ? void 0 : error.msg;
|
276
|
+
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
277
|
+
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
278
|
+
this.rawError = error;
|
297
279
|
}
|
298
280
|
}
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
_key = keys[i];
|
306
|
-
if (key === _key.toLowerCase()) return _key;
|
281
|
+
class APIConnectionError extends error_APIError {
|
282
|
+
constructor({ message, cause }){
|
283
|
+
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
284
|
+
// if (cause) {
|
285
|
+
// this.cause = cause;
|
286
|
+
// }
|
307
287
|
}
|
308
|
-
return null;
|
309
288
|
}
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
}
|
314
|
-
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
315
|
-
/**
|
316
|
-
* Accepts varargs expecting each argument to be an object, then
|
317
|
-
* immutably merges the properties of each object and returns result.
|
318
|
-
*
|
319
|
-
* When multiple objects contain the same key the later object in
|
320
|
-
* the arguments list will take precedence.
|
321
|
-
*
|
322
|
-
* Example:
|
323
|
-
*
|
324
|
-
* ```js
|
325
|
-
* var result = merge({foo: 123}, {foo: 456});
|
326
|
-
* console.log(result.foo); // outputs 456
|
327
|
-
* ```
|
328
|
-
*
|
329
|
-
* @param {Object} obj1 Object to merge
|
330
|
-
*
|
331
|
-
* @returns {Object} Result of all merge properties
|
332
|
-
*/ function utils_merge() {
|
333
|
-
const { caseless } = isContextDefined(this) && this || {};
|
334
|
-
const result = {};
|
335
|
-
const assignValue = (val, key)=>{
|
336
|
-
const targetKey = caseless && findKey(result, key) || key;
|
337
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
338
|
-
else if (isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
339
|
-
else if (isArray(val)) result[targetKey] = val.slice();
|
340
|
-
else result[targetKey] = val;
|
341
|
-
};
|
342
|
-
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
343
|
-
return result;
|
289
|
+
class APIUserAbortError extends error_APIError {
|
290
|
+
constructor(message){
|
291
|
+
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
292
|
+
}
|
344
293
|
}
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
}
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
294
|
+
class BadRequestError extends error_APIError {
|
295
|
+
constructor(...args){
|
296
|
+
super(...args), this.name = 'BadRequestError', this.status = 400;
|
297
|
+
}
|
298
|
+
}
|
299
|
+
class AuthenticationError extends error_APIError {
|
300
|
+
constructor(...args){
|
301
|
+
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
class PermissionDeniedError extends error_APIError {
|
305
|
+
constructor(...args){
|
306
|
+
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
class NotFoundError extends error_APIError {
|
310
|
+
constructor(...args){
|
311
|
+
super(...args), this.name = 'NotFoundError', this.status = 404;
|
312
|
+
}
|
313
|
+
}
|
314
|
+
class TimeoutError extends error_APIError {
|
315
|
+
constructor(...args){
|
316
|
+
super(...args), this.name = 'TimeoutError', this.status = 408;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
class RateLimitError extends error_APIError {
|
320
|
+
constructor(...args){
|
321
|
+
super(...args), this.name = 'RateLimitError', this.status = 429;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
class InternalServerError extends error_APIError {
|
325
|
+
constructor(...args){
|
326
|
+
super(...args), this.name = 'InternalServerError', this.status = 500;
|
327
|
+
}
|
328
|
+
}
|
329
|
+
class GatewayError extends error_APIError {
|
330
|
+
constructor(...args){
|
331
|
+
super(...args), this.name = 'GatewayError', this.status = 502;
|
332
|
+
}
|
333
|
+
}
|
334
|
+
const castToError = (err)=>{
|
335
|
+
if (err instanceof Error) return err;
|
336
|
+
return new Error(err);
|
388
337
|
};
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
338
|
+
class Messages extends APIResource {
|
339
|
+
/**
|
340
|
+
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
341
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
342
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
343
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
344
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
345
|
+
* @returns An array of chat messages. | 对话消息数组。
|
346
|
+
*/ async list(conversation_id, chat_id, options) {
|
347
|
+
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
348
|
+
const result = await this._client.get(apiUrl, void 0, false, options);
|
349
|
+
return result.data;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
353
|
+
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
354
|
+
...i,
|
355
|
+
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
356
|
+
}));
|
357
|
+
class Chat extends APIResource {
|
358
|
+
/**
|
359
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
360
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
361
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
362
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
363
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
364
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
365
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
366
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
367
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
368
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
369
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
370
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
371
|
+
* @returns The data of the created chat. | 创建的对话数据。
|
372
|
+
*/ async create(params, options) {
|
373
|
+
if (!params.user_id) params.user_id = uuid();
|
374
|
+
const { conversation_id, ...rest } = params;
|
375
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
376
|
+
const payload = {
|
377
|
+
...rest,
|
378
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
379
|
+
stream: false
|
380
|
+
};
|
381
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
382
|
+
return result.data;
|
383
|
+
}
|
384
|
+
/**
|
385
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
386
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
387
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
388
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
389
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
390
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
391
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
392
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
393
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
394
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
395
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
396
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
397
|
+
* @returns
|
398
|
+
*/ async createAndPoll(params, options) {
|
399
|
+
if (!params.user_id) params.user_id = uuid();
|
400
|
+
const { conversation_id, ...rest } = params;
|
401
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
402
|
+
const payload = {
|
403
|
+
...rest,
|
404
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
405
|
+
stream: false
|
406
|
+
};
|
407
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
408
|
+
const chatId = result.data.id;
|
409
|
+
const conversationId = result.data.conversation_id;
|
410
|
+
let chat;
|
411
|
+
while(true){
|
412
|
+
await utils_sleep(100);
|
413
|
+
chat = await this.retrieve(conversationId, chatId);
|
414
|
+
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
415
|
+
}
|
416
|
+
const messageList = await this.messages.list(conversationId, chatId);
|
417
|
+
return {
|
418
|
+
chat,
|
419
|
+
messages: messageList
|
420
|
+
};
|
421
|
+
}
|
422
|
+
/**
|
423
|
+
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
424
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
425
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
426
|
+
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
427
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
428
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
429
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
430
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
431
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
432
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
433
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
434
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
435
|
+
* @returns A stream of chat data. | 对话数据流。
|
436
|
+
*/ async *stream(params, options) {
|
437
|
+
if (!params.user_id) params.user_id = uuid();
|
438
|
+
const { conversation_id, ...rest } = params;
|
439
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
440
|
+
const payload = {
|
441
|
+
...rest,
|
442
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
443
|
+
stream: true
|
444
|
+
};
|
445
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
446
|
+
for await (const message of result)if ("done" === message.event) {
|
447
|
+
const ret = {
|
448
|
+
event: message.event,
|
449
|
+
data: '[DONE]'
|
450
|
+
};
|
451
|
+
yield ret;
|
452
|
+
} else try {
|
453
|
+
const ret = {
|
454
|
+
event: message.event,
|
455
|
+
data: JSON.parse(message.data)
|
456
|
+
};
|
457
|
+
yield ret;
|
458
|
+
} catch (error) {
|
459
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
460
|
+
}
|
461
|
+
}
|
462
|
+
/**
|
463
|
+
* Get the detailed information of the chat. | 查看对话的详细信息。
|
464
|
+
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
465
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
466
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
467
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
468
|
+
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
469
|
+
*/ async retrieve(conversation_id, chat_id, options) {
|
470
|
+
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
471
|
+
const result = await this._client.post(apiUrl, void 0, false, options);
|
472
|
+
return result.data;
|
473
|
+
}
|
474
|
+
/**
|
475
|
+
* Cancel a chat session. | 取消对话会话。
|
476
|
+
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
477
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
478
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
479
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
480
|
+
* @returns The data of the canceled chat. | 取消的对话数据。
|
481
|
+
*/ async cancel(conversation_id, chat_id, options) {
|
482
|
+
const apiUrl = '/v3/chat/cancel';
|
483
|
+
const payload = {
|
484
|
+
conversation_id,
|
485
|
+
chat_id
|
486
|
+
};
|
487
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
488
|
+
return result.data;
|
489
|
+
}
|
490
|
+
/**
|
491
|
+
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
492
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
493
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
494
|
+
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
495
|
+
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
496
|
+
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
497
|
+
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
498
|
+
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
499
|
+
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
500
|
+
*/ async *submitToolOutputs(params, options) {
|
501
|
+
const { conversation_id, chat_id, ...rest } = params;
|
502
|
+
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
503
|
+
const payload = {
|
504
|
+
...rest
|
505
|
+
};
|
506
|
+
if (false === params.stream) {
|
507
|
+
const response = await this._client.post(apiUrl, payload, false, options);
|
508
|
+
return response.data;
|
509
|
+
}
|
510
|
+
{
|
511
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
512
|
+
for await (const message of result)if ("done" === message.event) {
|
513
|
+
const ret = {
|
514
|
+
event: message.event,
|
515
|
+
data: '[DONE]'
|
516
|
+
};
|
517
|
+
yield ret;
|
518
|
+
} else try {
|
519
|
+
const ret = {
|
520
|
+
event: message.event,
|
521
|
+
data: JSON.parse(message.data)
|
522
|
+
};
|
523
|
+
yield ret;
|
524
|
+
} catch (error) {
|
525
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
}
|
529
|
+
constructor(...args){
|
530
|
+
super(...args), this.messages = new Messages(this._client);
|
531
|
+
}
|
532
|
+
}
|
533
|
+
var chat_ChatEventType = /*#__PURE__*/ function(ChatEventType) {
|
534
|
+
ChatEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
|
535
|
+
ChatEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
|
536
|
+
ChatEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
|
537
|
+
ChatEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
|
538
|
+
ChatEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
|
539
|
+
ChatEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
|
540
|
+
ChatEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
|
541
|
+
ChatEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
|
542
|
+
ChatEventType["DONE"] = "done";
|
543
|
+
ChatEventType["ERROR"] = "error";
|
544
|
+
return ChatEventType;
|
545
|
+
}({});
|
546
|
+
class messages_Messages extends APIResource {
|
547
|
+
/**
|
548
|
+
* Create a message and add it to the specified conversation. | 创建一条消息,并将其添加到指定的会话中。
|
549
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_message?_lang=en
|
550
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_message?_lang=zh
|
551
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
552
|
+
* @param params - Required The parameters for creating a message | 创建消息所需的参数
|
553
|
+
* @param params.role - Required The entity that sent this message. Possible values: user, assistant. | 发送这条消息的实体。取值:user, assistant。
|
554
|
+
* @param params.content - Required The content of the message. | 消息的内容。
|
555
|
+
* @param params.content_type - Required The type of the message content. | 消息内容的类型。
|
556
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
557
|
+
* @returns Information about the new message. | 消息详情。
|
558
|
+
*/ async create(conversation_id, params, options) {
|
559
|
+
const apiUrl = `/v1/conversation/message/create?conversation_id=${conversation_id}`;
|
560
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
561
|
+
return response.data;
|
562
|
+
}
|
563
|
+
/**
|
564
|
+
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
565
|
+
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
566
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
567
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
568
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
569
|
+
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
570
|
+
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
571
|
+
* @param params.content - Optional The content of the message. | 消息的内容。
|
572
|
+
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
573
|
+
* @returns Information about the modified message. | 消息详情。
|
574
|
+
*/ // eslint-disable-next-line max-params
|
575
|
+
async update(conversation_id, message_id, params, options) {
|
576
|
+
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
577
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
578
|
+
return response.message;
|
579
|
+
}
|
580
|
+
/**
|
581
|
+
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
582
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
583
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
584
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
585
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
586
|
+
* @returns Information about the message. | 消息详情。
|
587
|
+
*/ async retrieve(conversation_id, message_id, options) {
|
588
|
+
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
589
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
590
|
+
return response.data;
|
591
|
+
}
|
592
|
+
/**
|
593
|
+
* List messages in a conversation. | 列出会话中的消息。
|
594
|
+
* @docs en: https://www.coze.com/docs/developer_guides/message_list?_lang=en
|
595
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/message_list?_lang=zh
|
596
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
597
|
+
* @param params - Optional The parameters for listing messages | 列出消息所需的参数
|
598
|
+
* @param params.order - Optional The order of the messages. | 消息的顺序。
|
599
|
+
* @param params.chat_id - Optional The ID of the chat. | 聊天 ID。
|
600
|
+
* @param params.before_id - Optional The ID of the message before which to list. | 列出此消息之前的消息 ID。
|
601
|
+
* @param params.after_id - Optional The ID of the message after which to list. | 列出此消息之后的消息 ID。
|
602
|
+
* @param params.limit - Optional The maximum number of messages to return. | 返回的最大消息数。
|
603
|
+
* @returns A list of messages. | 消息列表。
|
604
|
+
*/ async list(conversation_id, params, options) {
|
605
|
+
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
606
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
607
|
+
return response;
|
608
|
+
}
|
609
|
+
/**
|
610
|
+
* Call the API to delete a message within a specified conversation. | 调用接口在指定会话中删除消息。
|
611
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_message?_lang=en
|
612
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_message?_lang=zh
|
613
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
614
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
615
|
+
* @returns Details of the deleted message. | 已删除的消息详情。
|
616
|
+
*/ async delete(conversation_id, message_id, options) {
|
617
|
+
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
618
|
+
const response = await this._client.post(apiUrl, void 0, false, options);
|
619
|
+
return response.data;
|
620
|
+
}
|
621
|
+
}
|
622
|
+
class Conversations extends APIResource {
|
623
|
+
/**
|
624
|
+
* Create a conversation. Conversation is an interaction between an agent and a user, including one or more messages. | 调用接口创建一个会话。
|
625
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_conversation?_lang=en
|
626
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_conversation?_lang=zh
|
627
|
+
* @param params - Required The parameters for creating a conversation | 创建会话所需的参数
|
628
|
+
* @param params.messages - Optional Messages in the conversation. | 会话中的消息内容。
|
629
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
630
|
+
* @param params.bot_id - Optional Bind and isolate conversation on different bots. | 绑定和隔离不同Bot的会话。
|
631
|
+
* @returns Information about the created conversation. | 会话的基础信息。
|
632
|
+
*/ async create(params, options) {
|
633
|
+
const apiUrl = '/v1/conversation/create';
|
634
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
635
|
+
return response.data;
|
636
|
+
}
|
637
|
+
/**
|
638
|
+
* Get the information of specific conversation. | 通过会话 ID 查看会话信息。
|
639
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_conversation?_lang=en
|
640
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_conversation?_lang=zh
|
641
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
642
|
+
* @returns Information about the conversation. | 会话的基础信息。
|
643
|
+
*/ async retrieve(conversation_id, options) {
|
644
|
+
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
645
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
646
|
+
return response.data;
|
647
|
+
}
|
648
|
+
/**
|
649
|
+
* List all conversations. | 列出 Bot 下所有会话。
|
650
|
+
* @param params
|
651
|
+
* @param params.bot_id - Required Bot ID. | Bot ID。
|
652
|
+
* @param params.page_num - Optional The page number. | 页码,默认值为 1。
|
653
|
+
* @param params.page_size - Optional The number of conversations per page. | 每页的会话数量,默认值为 50。
|
654
|
+
* @returns Information about the conversations. | 会话的信息。
|
655
|
+
*/ async list(params, options) {
|
656
|
+
const apiUrl = '/v1/conversations';
|
657
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
658
|
+
return response.data;
|
659
|
+
}
|
660
|
+
/**
|
661
|
+
* Clear a conversation. | 清空会话。
|
662
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
663
|
+
* @returns Information about the conversation session. | 会话的会话 ID。
|
664
|
+
*/ async clear(conversation_id, options) {
|
665
|
+
const apiUrl = `/v1/conversations/${conversation_id}/clear`;
|
666
|
+
const response = await this._client.post(apiUrl, null, false, options);
|
667
|
+
return response.data;
|
668
|
+
}
|
669
|
+
constructor(...args){
|
670
|
+
super(...args), this.messages = new messages_Messages(this._client);
|
671
|
+
}
|
672
|
+
}
|
673
|
+
function bind(fn, thisArg) {
|
674
|
+
return function() {
|
675
|
+
return fn.apply(thisArg, arguments);
|
676
|
+
};
|
677
|
+
}
|
678
|
+
// utils is a library of generic helper functions non-specific to axios
|
679
|
+
const { toString: utils_toString } = Object.prototype;
|
680
|
+
const { getPrototypeOf } = Object;
|
681
|
+
const kindOf = ((cache)=>(thing)=>{
|
682
|
+
const str = utils_toString.call(thing);
|
683
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
684
|
+
})(Object.create(null));
|
685
|
+
const kindOfTest = (type)=>{
|
686
|
+
type = type.toLowerCase();
|
687
|
+
return (thing)=>kindOf(thing) === type;
|
418
688
|
};
|
689
|
+
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
419
690
|
/**
|
420
|
-
*
|
691
|
+
* Determine if a value is an Array
|
421
692
|
*
|
422
|
-
* @param {
|
423
|
-
* @param {String} searchString
|
424
|
-
* @param {Number} [position= 0]
|
693
|
+
* @param {Object} val The value to test
|
425
694
|
*
|
426
|
-
* @returns {boolean}
|
427
|
-
*/ const
|
428
|
-
str = String(str);
|
429
|
-
if (void 0 === position || position > str.length) position = str.length;
|
430
|
-
position -= searchString.length;
|
431
|
-
const lastIndex = str.indexOf(searchString, position);
|
432
|
-
return -1 !== lastIndex && lastIndex === position;
|
433
|
-
};
|
695
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
696
|
+
*/ const { isArray } = Array;
|
434
697
|
/**
|
435
|
-
*
|
698
|
+
* Determine if a value is undefined
|
436
699
|
*
|
437
|
-
* @param {*}
|
700
|
+
* @param {*} val The value to test
|
438
701
|
*
|
439
|
-
* @returns {
|
440
|
-
*/ const
|
441
|
-
if (!thing) return null;
|
442
|
-
if (isArray(thing)) return thing;
|
443
|
-
let i = thing.length;
|
444
|
-
if (!isNumber(i)) return null;
|
445
|
-
const arr = new Array(i);
|
446
|
-
while(i-- > 0)arr[i] = thing[i];
|
447
|
-
return arr;
|
448
|
-
};
|
702
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
703
|
+
*/ const isUndefined = typeOfTest('undefined');
|
449
704
|
/**
|
450
|
-
*
|
451
|
-
* thing passed in is an instance of Uint8Array
|
705
|
+
* Determine if a value is a Buffer
|
452
706
|
*
|
453
|
-
* @param {
|
707
|
+
* @param {*} val The value to test
|
454
708
|
*
|
455
|
-
* @returns {
|
456
|
-
*/
|
457
|
-
|
709
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
710
|
+
*/ function isBuffer(val) {
|
711
|
+
return null !== val && !isUndefined(val) && null !== val.constructor && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
712
|
+
}
|
458
713
|
/**
|
459
|
-
*
|
714
|
+
* Determine if a value is an ArrayBuffer
|
460
715
|
*
|
461
|
-
* @param {
|
462
|
-
* @param {Function} fn - The function to call for each entry.
|
716
|
+
* @param {*} val The value to test
|
463
717
|
*
|
464
|
-
* @returns {
|
465
|
-
*/ const
|
466
|
-
const generator = obj && obj[Symbol.iterator];
|
467
|
-
const iterator = generator.call(obj);
|
468
|
-
let result;
|
469
|
-
while((result = iterator.next()) && !result.done){
|
470
|
-
const pair = result.value;
|
471
|
-
fn.call(obj, pair[0], pair[1]);
|
472
|
-
}
|
473
|
-
};
|
718
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
719
|
+
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
474
720
|
/**
|
475
|
-
*
|
721
|
+
* Determine if a value is a view on an ArrayBuffer
|
476
722
|
*
|
477
|
-
* @param {
|
478
|
-
* @param {string} str - The string to search.
|
723
|
+
* @param {*} val The value to test
|
479
724
|
*
|
480
|
-
* @returns {
|
481
|
-
*/
|
482
|
-
let
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
};
|
487
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
488
|
-
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
489
|
-
return p1.toUpperCase() + p2;
|
490
|
-
});
|
491
|
-
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
725
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
726
|
+
*/ function isArrayBufferView(val) {
|
727
|
+
let result;
|
728
|
+
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
729
|
+
return result;
|
730
|
+
}
|
492
731
|
/**
|
493
|
-
* Determine if a value is a
|
732
|
+
* Determine if a value is a String
|
494
733
|
*
|
495
734
|
* @param {*} val The value to test
|
496
735
|
*
|
497
|
-
* @returns {boolean} True if value is a
|
498
|
-
*/ const
|
499
|
-
const reduceDescriptors = (obj, reducer)=>{
|
500
|
-
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
501
|
-
const reducedDescriptors = {};
|
502
|
-
forEach(descriptors, (descriptor, name)=>{
|
503
|
-
let ret;
|
504
|
-
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
505
|
-
});
|
506
|
-
Object.defineProperties(obj, reducedDescriptors);
|
507
|
-
};
|
736
|
+
* @returns {boolean} True if value is a String, otherwise false
|
737
|
+
*/ const isString = typeOfTest('string');
|
508
738
|
/**
|
509
|
-
*
|
510
|
-
*
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
if (isFunction(obj) && -1 !== [
|
515
|
-
'arguments',
|
516
|
-
'caller',
|
517
|
-
'callee'
|
518
|
-
].indexOf(name)) return false;
|
519
|
-
const value = obj[name];
|
520
|
-
if (!isFunction(value)) return;
|
521
|
-
descriptor.enumerable = false;
|
522
|
-
if ('writable' in descriptor) {
|
523
|
-
descriptor.writable = false;
|
524
|
-
return;
|
525
|
-
}
|
526
|
-
if (!descriptor.set) descriptor.set = ()=>{
|
527
|
-
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
528
|
-
};
|
529
|
-
});
|
530
|
-
};
|
531
|
-
const toObjectSet = (arrayOrString, delimiter)=>{
|
532
|
-
const obj = {};
|
533
|
-
const define = (arr)=>{
|
534
|
-
arr.forEach((value)=>{
|
535
|
-
obj[value] = true;
|
536
|
-
});
|
537
|
-
};
|
538
|
-
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
539
|
-
return obj;
|
540
|
-
};
|
541
|
-
const noop = ()=>{};
|
542
|
-
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
543
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
544
|
-
const DIGIT = '0123456789';
|
545
|
-
const ALPHABET = {
|
546
|
-
DIGIT,
|
547
|
-
ALPHA,
|
548
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
549
|
-
};
|
550
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
551
|
-
let str = '';
|
552
|
-
const { length } = alphabet;
|
553
|
-
while(size--)str += alphabet[Math.random() * length | 0];
|
554
|
-
return str;
|
555
|
-
};
|
739
|
+
* Determine if a value is a Function
|
740
|
+
*
|
741
|
+
* @param {*} val The value to test
|
742
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
743
|
+
*/ const isFunction = typeOfTest('function');
|
556
744
|
/**
|
557
|
-
*
|
745
|
+
* Determine if a value is a Number
|
558
746
|
*
|
559
|
-
* @param {
|
747
|
+
* @param {*} val The value to test
|
560
748
|
*
|
561
|
-
* @returns {boolean}
|
562
|
-
*/
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
749
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
750
|
+
*/ const isNumber = typeOfTest('number');
|
751
|
+
/**
|
752
|
+
* Determine if a value is an Object
|
753
|
+
*
|
754
|
+
* @param {*} thing The value to test
|
755
|
+
*
|
756
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
757
|
+
*/ const isObject = (thing)=>null !== thing && 'object' == typeof thing;
|
758
|
+
/**
|
759
|
+
* Determine if a value is a Boolean
|
760
|
+
*
|
761
|
+
* @param {*} thing The value to test
|
762
|
+
* @returns {boolean} True if value is a Boolean, otherwise false
|
763
|
+
*/ const isBoolean = (thing)=>true === thing || false === thing;
|
764
|
+
/**
|
765
|
+
* Determine if a value is a plain Object
|
766
|
+
*
|
767
|
+
* @param {*} val The value to test
|
768
|
+
*
|
769
|
+
* @returns {boolean} True if value is a plain Object, otherwise false
|
770
|
+
*/ const utils_isPlainObject = (val)=>{
|
771
|
+
if ('object' !== kindOf(val)) return false;
|
772
|
+
const prototype = getPrototypeOf(val);
|
773
|
+
return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
774
|
+
};
|
775
|
+
/**
|
776
|
+
* Determine if a value is a Date
|
777
|
+
*
|
778
|
+
* @param {*} val The value to test
|
779
|
+
*
|
780
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
781
|
+
*/ const isDate = kindOfTest('Date');
|
782
|
+
/**
|
783
|
+
* Determine if a value is a File
|
784
|
+
*
|
785
|
+
* @param {*} val The value to test
|
786
|
+
*
|
787
|
+
* @returns {boolean} True if value is a File, otherwise false
|
788
|
+
*/ const isFile = kindOfTest('File');
|
789
|
+
/**
|
790
|
+
* Determine if a value is a Blob
|
791
|
+
*
|
792
|
+
* @param {*} val The value to test
|
793
|
+
*
|
794
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
795
|
+
*/ const isBlob = kindOfTest('Blob');
|
796
|
+
/**
|
797
|
+
* Determine if a value is a FileList
|
798
|
+
*
|
799
|
+
* @param {*} val The value to test
|
800
|
+
*
|
801
|
+
* @returns {boolean} True if value is a File, otherwise false
|
802
|
+
*/ const utils_isFileList = kindOfTest('FileList');
|
803
|
+
/**
|
804
|
+
* Determine if a value is a Stream
|
805
|
+
*
|
806
|
+
* @param {*} val The value to test
|
807
|
+
*
|
808
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
809
|
+
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
810
|
+
/**
|
811
|
+
* Determine if a value is a FormData
|
812
|
+
*
|
813
|
+
* @param {*} thing The value to test
|
814
|
+
*
|
815
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
816
|
+
*/ const utils_isFormData = (thing)=>{
|
817
|
+
let kind;
|
818
|
+
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
819
|
+
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
820
|
+
};
|
821
|
+
/**
|
822
|
+
* Determine if a value is a URLSearchParams object
|
823
|
+
*
|
824
|
+
* @param {*} val The value to test
|
825
|
+
*
|
826
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
827
|
+
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
828
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
829
|
+
'ReadableStream',
|
830
|
+
'Request',
|
831
|
+
'Response',
|
832
|
+
'Headers'
|
833
|
+
].map(kindOfTest);
|
834
|
+
/**
|
835
|
+
* Trim excess whitespace off the beginning and end of a string
|
836
|
+
*
|
837
|
+
* @param {String} str The String to trim
|
838
|
+
*
|
839
|
+
* @returns {String} The String freed of excess whitespace
|
840
|
+
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
841
|
+
/**
|
842
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
843
|
+
*
|
844
|
+
* If `obj` is an Array callback will be called passing
|
845
|
+
* the value, index, and complete array for each item.
|
846
|
+
*
|
847
|
+
* If 'obj' is an Object callback will be called passing
|
848
|
+
* the value, key, and complete object for each property.
|
849
|
+
*
|
850
|
+
* @param {Object|Array} obj The object to iterate
|
851
|
+
* @param {Function} fn The callback to invoke for each item
|
852
|
+
*
|
853
|
+
* @param {Boolean} [allOwnKeys = false]
|
854
|
+
* @returns {any}
|
855
|
+
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
856
|
+
// Don't bother if no value provided
|
857
|
+
if (null == obj) return;
|
858
|
+
let i;
|
859
|
+
let l;
|
860
|
+
// Force an array if not already something iterable
|
861
|
+
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
862
|
+
obj
|
863
|
+
];
|
864
|
+
if (isArray(obj)) // Iterate over array values
|
865
|
+
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
866
|
+
else {
|
867
|
+
// Iterate over object keys
|
868
|
+
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
869
|
+
const len = keys.length;
|
870
|
+
let key;
|
871
|
+
for(i = 0; i < len; i++){
|
872
|
+
key = keys[i];
|
873
|
+
fn.call(null, obj[key], key, obj);
|
874
|
+
}
|
875
|
+
}
|
876
|
+
}
|
877
|
+
function findKey(obj, key) {
|
878
|
+
key = key.toLowerCase();
|
879
|
+
const keys = Object.keys(obj);
|
880
|
+
let i = keys.length;
|
881
|
+
let _key;
|
882
|
+
while(i-- > 0){
|
883
|
+
_key = keys[i];
|
884
|
+
if (key === _key.toLowerCase()) return _key;
|
885
|
+
}
|
886
|
+
return null;
|
887
|
+
}
|
888
|
+
const _global = (()=>{
|
889
|
+
/*eslint no-undef:0*/ if ("undefined" != typeof globalThis) return globalThis;
|
890
|
+
return "undefined" != typeof self ? self : 'undefined' != typeof window ? window : global;
|
891
|
+
})();
|
892
|
+
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
893
|
+
/**
|
894
|
+
* Accepts varargs expecting each argument to be an object, then
|
895
|
+
* immutably merges the properties of each object and returns result.
|
896
|
+
*
|
897
|
+
* When multiple objects contain the same key the later object in
|
898
|
+
* the arguments list will take precedence.
|
899
|
+
*
|
900
|
+
* Example:
|
901
|
+
*
|
902
|
+
* ```js
|
903
|
+
* var result = merge({foo: 123}, {foo: 456});
|
904
|
+
* console.log(result.foo); // outputs 456
|
905
|
+
* ```
|
906
|
+
*
|
907
|
+
* @param {Object} obj1 Object to merge
|
908
|
+
*
|
909
|
+
* @returns {Object} Result of all merge properties
|
910
|
+
*/ function utils_merge() {
|
911
|
+
const { caseless } = isContextDefined(this) && this || {};
|
912
|
+
const result = {};
|
913
|
+
const assignValue = (val, key)=>{
|
914
|
+
const targetKey = caseless && findKey(result, key) || key;
|
915
|
+
if (utils_isPlainObject(result[targetKey]) && utils_isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
916
|
+
else if (utils_isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
917
|
+
else if (isArray(val)) result[targetKey] = val.slice();
|
918
|
+
else result[targetKey] = val;
|
919
|
+
};
|
920
|
+
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
921
|
+
return result;
|
922
|
+
}
|
923
|
+
/**
|
924
|
+
* Extends object a by mutably adding to it the properties of object b.
|
925
|
+
*
|
926
|
+
* @param {Object} a The object to be extended
|
927
|
+
* @param {Object} b The object to copy properties from
|
928
|
+
* @param {Object} thisArg The object to bind function to
|
929
|
+
*
|
930
|
+
* @param {Boolean} [allOwnKeys]
|
931
|
+
* @returns {Object} The resulting value of object a
|
932
|
+
*/ const extend = (a, b, thisArg, { allOwnKeys } = {})=>{
|
933
|
+
forEach(b, (val, key)=>{
|
934
|
+
if (thisArg && isFunction(val)) a[key] = bind(val, thisArg);
|
935
|
+
else a[key] = val;
|
936
|
+
}, {
|
937
|
+
allOwnKeys
|
938
|
+
});
|
939
|
+
return a;
|
940
|
+
};
|
941
|
+
/**
|
942
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
943
|
+
*
|
944
|
+
* @param {string} content with BOM
|
945
|
+
*
|
946
|
+
* @returns {string} content value without BOM
|
947
|
+
*/ const stripBOM = (content)=>{
|
948
|
+
if (0xFEFF === content.charCodeAt(0)) content = content.slice(1);
|
949
|
+
return content;
|
950
|
+
};
|
951
|
+
/**
|
952
|
+
* Inherit the prototype methods from one constructor into another
|
953
|
+
* @param {function} constructor
|
954
|
+
* @param {function} superConstructor
|
955
|
+
* @param {object} [props]
|
956
|
+
* @param {object} [descriptors]
|
957
|
+
*
|
958
|
+
* @returns {void}
|
959
|
+
*/ const inherits = (constructor, superConstructor, props, descriptors)=>{
|
960
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
961
|
+
constructor.prototype.constructor = constructor;
|
962
|
+
Object.defineProperty(constructor, 'super', {
|
963
|
+
value: superConstructor.prototype
|
964
|
+
});
|
965
|
+
props && Object.assign(constructor.prototype, props);
|
966
|
+
};
|
967
|
+
/**
|
968
|
+
* Resolve object with deep prototype chain to a flat object
|
969
|
+
* @param {Object} sourceObj source object
|
970
|
+
* @param {Object} [destObj]
|
971
|
+
* @param {Function|Boolean} [filter]
|
972
|
+
* @param {Function} [propFilter]
|
973
|
+
*
|
974
|
+
* @returns {Object}
|
975
|
+
*/ const toFlatObject = (sourceObj, destObj, filter, propFilter)=>{
|
976
|
+
let props;
|
977
|
+
let i;
|
978
|
+
let prop;
|
979
|
+
const merged = {};
|
980
|
+
destObj = destObj || {};
|
981
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
982
|
+
if (null == sourceObj) return destObj;
|
983
|
+
do {
|
984
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
985
|
+
i = props.length;
|
986
|
+
while(i-- > 0){
|
987
|
+
prop = props[i];
|
988
|
+
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
989
|
+
destObj[prop] = sourceObj[prop];
|
990
|
+
merged[prop] = true;
|
991
|
+
}
|
992
|
+
}
|
993
|
+
sourceObj = false !== filter && getPrototypeOf(sourceObj);
|
994
|
+
}while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
995
|
+
return destObj;
|
996
|
+
};
|
997
|
+
/**
|
998
|
+
* Determines whether a string ends with the characters of a specified string
|
999
|
+
*
|
1000
|
+
* @param {String} str
|
1001
|
+
* @param {String} searchString
|
1002
|
+
* @param {Number} [position= 0]
|
1003
|
+
*
|
1004
|
+
* @returns {boolean}
|
1005
|
+
*/ const endsWith = (str, searchString, position)=>{
|
1006
|
+
str = String(str);
|
1007
|
+
if (void 0 === position || position > str.length) position = str.length;
|
1008
|
+
position -= searchString.length;
|
1009
|
+
const lastIndex = str.indexOf(searchString, position);
|
1010
|
+
return -1 !== lastIndex && lastIndex === position;
|
1011
|
+
};
|
1012
|
+
/**
|
1013
|
+
* Returns new array from array like object or null if failed
|
1014
|
+
*
|
1015
|
+
* @param {*} [thing]
|
1016
|
+
*
|
1017
|
+
* @returns {?Array}
|
1018
|
+
*/ const toArray = (thing)=>{
|
1019
|
+
if (!thing) return null;
|
1020
|
+
if (isArray(thing)) return thing;
|
1021
|
+
let i = thing.length;
|
1022
|
+
if (!isNumber(i)) return null;
|
1023
|
+
const arr = new Array(i);
|
1024
|
+
while(i-- > 0)arr[i] = thing[i];
|
1025
|
+
return arr;
|
1026
|
+
};
|
1027
|
+
/**
|
1028
|
+
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
1029
|
+
* thing passed in is an instance of Uint8Array
|
1030
|
+
*
|
1031
|
+
* @param {TypedArray}
|
1032
|
+
*
|
1033
|
+
* @returns {Array}
|
1034
|
+
*/ // eslint-disable-next-line func-names
|
1035
|
+
const isTypedArray = ((TypedArray)=>(thing)=>TypedArray && thing instanceof TypedArray)('undefined' != typeof Uint8Array && getPrototypeOf(Uint8Array));
|
1036
|
+
/**
|
1037
|
+
* For each entry in the object, call the function with the key and value.
|
1038
|
+
*
|
1039
|
+
* @param {Object<any, any>} obj - The object to iterate over.
|
1040
|
+
* @param {Function} fn - The function to call for each entry.
|
1041
|
+
*
|
1042
|
+
* @returns {void}
|
1043
|
+
*/ const forEachEntry = (obj, fn)=>{
|
1044
|
+
const generator = obj && obj[Symbol.iterator];
|
1045
|
+
const iterator = generator.call(obj);
|
1046
|
+
let result;
|
1047
|
+
while((result = iterator.next()) && !result.done){
|
1048
|
+
const pair = result.value;
|
1049
|
+
fn.call(obj, pair[0], pair[1]);
|
1050
|
+
}
|
1051
|
+
};
|
1052
|
+
/**
|
1053
|
+
* It takes a regular expression and a string, and returns an array of all the matches
|
1054
|
+
*
|
1055
|
+
* @param {string} regExp - The regular expression to match against.
|
1056
|
+
* @param {string} str - The string to search.
|
1057
|
+
*
|
1058
|
+
* @returns {Array<boolean>}
|
1059
|
+
*/ const matchAll = (regExp, str)=>{
|
1060
|
+
let matches;
|
1061
|
+
const arr = [];
|
1062
|
+
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
1063
|
+
return arr;
|
1064
|
+
};
|
1065
|
+
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
1066
|
+
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
1067
|
+
return p1.toUpperCase() + p2;
|
1068
|
+
});
|
1069
|
+
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
1070
|
+
/**
|
1071
|
+
* Determine if a value is a RegExp object
|
1072
|
+
*
|
1073
|
+
* @param {*} val The value to test
|
1074
|
+
*
|
1075
|
+
* @returns {boolean} True if value is a RegExp object, otherwise false
|
1076
|
+
*/ const isRegExp = kindOfTest('RegExp');
|
1077
|
+
const reduceDescriptors = (obj, reducer)=>{
|
1078
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
1079
|
+
const reducedDescriptors = {};
|
1080
|
+
forEach(descriptors, (descriptor, name)=>{
|
1081
|
+
let ret;
|
1082
|
+
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
1083
|
+
});
|
1084
|
+
Object.defineProperties(obj, reducedDescriptors);
|
1085
|
+
};
|
1086
|
+
/**
|
1087
|
+
* Makes all methods read-only
|
1088
|
+
* @param {Object} obj
|
1089
|
+
*/ const freezeMethods = (obj)=>{
|
1090
|
+
reduceDescriptors(obj, (descriptor, name)=>{
|
1091
|
+
// skip restricted props in strict mode
|
1092
|
+
if (isFunction(obj) && -1 !== [
|
1093
|
+
'arguments',
|
1094
|
+
'caller',
|
1095
|
+
'callee'
|
1096
|
+
].indexOf(name)) return false;
|
1097
|
+
const value = obj[name];
|
1098
|
+
if (!isFunction(value)) return;
|
1099
|
+
descriptor.enumerable = false;
|
1100
|
+
if ('writable' in descriptor) {
|
1101
|
+
descriptor.writable = false;
|
1102
|
+
return;
|
1103
|
+
}
|
1104
|
+
if (!descriptor.set) descriptor.set = ()=>{
|
1105
|
+
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
1106
|
+
};
|
1107
|
+
});
|
1108
|
+
};
|
1109
|
+
const toObjectSet = (arrayOrString, delimiter)=>{
|
1110
|
+
const obj = {};
|
1111
|
+
const define = (arr)=>{
|
1112
|
+
arr.forEach((value)=>{
|
1113
|
+
obj[value] = true;
|
1114
|
+
});
|
1115
|
+
};
|
1116
|
+
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
1117
|
+
return obj;
|
1118
|
+
};
|
1119
|
+
const noop = ()=>{};
|
1120
|
+
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
1121
|
+
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
1122
|
+
const DIGIT = '0123456789';
|
1123
|
+
const ALPHABET = {
|
1124
|
+
DIGIT,
|
1125
|
+
ALPHA,
|
1126
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
1127
|
+
};
|
1128
|
+
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
1129
|
+
let str = '';
|
1130
|
+
const { length } = alphabet;
|
1131
|
+
while(size--)str += alphabet[Math.random() * length | 0];
|
1132
|
+
return str;
|
1133
|
+
};
|
1134
|
+
/**
|
1135
|
+
* If the thing is a FormData object, return true, otherwise return false.
|
1136
|
+
*
|
1137
|
+
* @param {unknown} thing - The thing to check.
|
1138
|
+
*
|
1139
|
+
* @returns {boolean}
|
1140
|
+
*/ function isSpecCompliantForm(thing) {
|
1141
|
+
return !!(thing && isFunction(thing.append) && 'FormData' === thing[Symbol.toStringTag] && thing[Symbol.iterator]);
|
1142
|
+
}
|
1143
|
+
const toJSONObject = (obj)=>{
|
1144
|
+
const stack = new Array(10);
|
567
1145
|
const visit = (source, i)=>{
|
568
1146
|
if (isObject(source)) {
|
569
1147
|
if (stack.indexOf(source) >= 0) return;
|
@@ -610,7 +1188,7 @@ const asap = 'undefined' != typeof queueMicrotask ? queueMicrotask.bind(_global)
|
|
610
1188
|
isNumber,
|
611
1189
|
isBoolean,
|
612
1190
|
isObject,
|
613
|
-
isPlainObject,
|
1191
|
+
isPlainObject: utils_isPlainObject,
|
614
1192
|
isReadableStream,
|
615
1193
|
isRequest,
|
616
1194
|
isResponse,
|
@@ -1052,7 +1630,7 @@ class InterceptorManager_InterceptorManager {
|
|
1052
1630
|
]
|
1053
1631
|
};
|
1054
1632
|
const hasBrowserEnv = 'undefined' != typeof window && 'undefined' != typeof document;
|
1055
|
-
const
|
1633
|
+
const utils_navigator = 'object' == typeof navigator && navigator || void 0;
|
1056
1634
|
/**
|
1057
1635
|
* Determine if we're running in a standard browser environment
|
1058
1636
|
*
|
@@ -1069,11 +1647,11 @@ const _navigator = 'object' == typeof navigator && navigator || void 0;
|
|
1069
1647
|
* navigator.product -> 'NativeScript' or 'NS'
|
1070
1648
|
*
|
1071
1649
|
* @returns {boolean}
|
1072
|
-
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!
|
1650
|
+
*/ const hasStandardBrowserEnv = hasBrowserEnv && (!utils_navigator || [
|
1073
1651
|
'ReactNative',
|
1074
1652
|
'NativeScript',
|
1075
1653
|
'NS'
|
1076
|
-
].indexOf(
|
1654
|
+
].indexOf(utils_navigator.product) < 0);
|
1077
1655
|
/**
|
1078
1656
|
* Determine if we're running in a standard browser webWorker environment
|
1079
1657
|
*
|
@@ -1808,7 +2386,7 @@ const headersToObject = (thing)=>thing instanceof AxiosHeaders ? {
|
|
1808
2386
|
* @param {Object} config2
|
1809
2387
|
*
|
1810
2388
|
* @returns {Object} New object resulting from merging config2 to config1
|
1811
|
-
*/ function
|
2389
|
+
*/ function mergeConfig_mergeConfig(config1, config2) {
|
1812
2390
|
// eslint-disable-next-line no-param-reassign
|
1813
2391
|
config2 = config2 || {};
|
1814
2392
|
const config = {};
|
@@ -1878,7 +2456,7 @@ const headersToObject = (thing)=>thing instanceof AxiosHeaders ? {
|
|
1878
2456
|
return config;
|
1879
2457
|
}
|
1880
2458
|
/* ESM default export */ const resolveConfig = (config)=>{
|
1881
|
-
const newConfig =
|
2459
|
+
const newConfig = mergeConfig_mergeConfig({}, config);
|
1882
2460
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
1883
2461
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
1884
2462
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
@@ -2484,7 +3062,7 @@ const Axios_validators = helpers_validator.validators;
|
|
2484
3062
|
config = config || {};
|
2485
3063
|
config.url = configOrUrl;
|
2486
3064
|
} else config = configOrUrl || {};
|
2487
|
-
config =
|
3065
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
2488
3066
|
const { transitional, paramsSerializer, headers } = config;
|
2489
3067
|
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
2490
3068
|
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
@@ -2533,897 +3111,330 @@ const Axios_validators = helpers_validator.validators;
|
|
2533
3111
|
let len;
|
2534
3112
|
if (!synchronousRequestInterceptors) {
|
2535
3113
|
const chain = [
|
2536
|
-
dispatchRequest.bind(this),
|
2537
|
-
void 0
|
2538
|
-
];
|
2539
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
2540
|
-
chain.push.apply(chain, responseInterceptorChain);
|
2541
|
-
len = chain.length;
|
2542
|
-
promise = Promise.resolve(config);
|
2543
|
-
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
2544
|
-
return promise;
|
2545
|
-
}
|
2546
|
-
len = requestInterceptorChain.length;
|
2547
|
-
let newConfig = config;
|
2548
|
-
i = 0;
|
2549
|
-
while(i < len){
|
2550
|
-
const onFulfilled = requestInterceptorChain[i++];
|
2551
|
-
const onRejected = requestInterceptorChain[i++];
|
2552
|
-
try {
|
2553
|
-
newConfig = onFulfilled(newConfig);
|
2554
|
-
} catch (error) {
|
2555
|
-
onRejected.call(this, error);
|
2556
|
-
break;
|
2557
|
-
}
|
2558
|
-
}
|
2559
|
-
try {
|
2560
|
-
promise = dispatchRequest.call(this, newConfig);
|
2561
|
-
} catch (error) {
|
2562
|
-
return Promise.reject(error);
|
2563
|
-
}
|
2564
|
-
i = 0;
|
2565
|
-
len = responseInterceptorChain.length;
|
2566
|
-
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
2567
|
-
return promise;
|
2568
|
-
}
|
2569
|
-
getUri(config) {
|
2570
|
-
config = mergeConfig(this.defaults, config);
|
2571
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2572
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2573
|
-
}
|
2574
|
-
}
|
2575
|
-
// Provide aliases for supported request methods
|
2576
|
-
utils.forEach([
|
2577
|
-
'delete',
|
2578
|
-
'get',
|
2579
|
-
'head',
|
2580
|
-
'options'
|
2581
|
-
], function(method) {
|
2582
|
-
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
2583
|
-
return this.request(mergeConfig(config || {}, {
|
2584
|
-
method,
|
2585
|
-
url,
|
2586
|
-
data: (config || {}).data
|
2587
|
-
}));
|
2588
|
-
};
|
2589
|
-
});
|
2590
|
-
utils.forEach([
|
2591
|
-
'post',
|
2592
|
-
'put',
|
2593
|
-
'patch'
|
2594
|
-
], function(method) {
|
2595
|
-
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
2596
|
-
return function(url, data, config) {
|
2597
|
-
return this.request(mergeConfig(config || {}, {
|
2598
|
-
method,
|
2599
|
-
headers: isForm ? {
|
2600
|
-
'Content-Type': 'multipart/form-data'
|
2601
|
-
} : {},
|
2602
|
-
url,
|
2603
|
-
data
|
2604
|
-
}));
|
2605
|
-
};
|
2606
|
-
}
|
2607
|
-
Axios_Axios.prototype[method] = generateHTTPMethod();
|
2608
|
-
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2609
|
-
});
|
2610
|
-
/* ESM default export */ const Axios = Axios_Axios;
|
2611
|
-
/**
|
2612
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2613
|
-
*
|
2614
|
-
* @param {Function} executor The executor function.
|
2615
|
-
*
|
2616
|
-
* @returns {CancelToken}
|
2617
|
-
*/ class CancelToken_CancelToken {
|
2618
|
-
constructor(executor){
|
2619
|
-
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
2620
|
-
let resolvePromise;
|
2621
|
-
this.promise = new Promise(function(resolve) {
|
2622
|
-
resolvePromise = resolve;
|
2623
|
-
});
|
2624
|
-
const token = this;
|
2625
|
-
// eslint-disable-next-line func-names
|
2626
|
-
this.promise.then((cancel)=>{
|
2627
|
-
if (!token._listeners) return;
|
2628
|
-
let i = token._listeners.length;
|
2629
|
-
while(i-- > 0)token._listeners[i](cancel);
|
2630
|
-
token._listeners = null;
|
2631
|
-
});
|
2632
|
-
// eslint-disable-next-line func-names
|
2633
|
-
this.promise.then = (onfulfilled)=>{
|
2634
|
-
let _resolve;
|
2635
|
-
// eslint-disable-next-line func-names
|
2636
|
-
const promise = new Promise((resolve)=>{
|
2637
|
-
token.subscribe(resolve);
|
2638
|
-
_resolve = resolve;
|
2639
|
-
}).then(onfulfilled);
|
2640
|
-
promise.cancel = function() {
|
2641
|
-
token.unsubscribe(_resolve);
|
2642
|
-
};
|
2643
|
-
return promise;
|
2644
|
-
};
|
2645
|
-
executor(function(message, config, request) {
|
2646
|
-
if (token.reason) // Cancellation has already been requested
|
2647
|
-
return;
|
2648
|
-
token.reason = new CanceledError(message, config, request);
|
2649
|
-
resolvePromise(token.reason);
|
2650
|
-
});
|
2651
|
-
}
|
2652
|
-
/**
|
2653
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2654
|
-
*/ throwIfRequested() {
|
2655
|
-
if (this.reason) throw this.reason;
|
2656
|
-
}
|
2657
|
-
/**
|
2658
|
-
* Subscribe to the cancel signal
|
2659
|
-
*/ subscribe(listener) {
|
2660
|
-
if (this.reason) {
|
2661
|
-
listener(this.reason);
|
2662
|
-
return;
|
2663
|
-
}
|
2664
|
-
if (this._listeners) this._listeners.push(listener);
|
2665
|
-
else this._listeners = [
|
2666
|
-
listener
|
2667
|
-
];
|
2668
|
-
}
|
2669
|
-
/**
|
2670
|
-
* Unsubscribe from the cancel signal
|
2671
|
-
*/ unsubscribe(listener) {
|
2672
|
-
if (!this._listeners) return;
|
2673
|
-
const index = this._listeners.indexOf(listener);
|
2674
|
-
if (-1 !== index) this._listeners.splice(index, 1);
|
2675
|
-
}
|
2676
|
-
toAbortSignal() {
|
2677
|
-
const controller = new AbortController();
|
2678
|
-
const abort = (err)=>{
|
2679
|
-
controller.abort(err);
|
2680
|
-
};
|
2681
|
-
this.subscribe(abort);
|
2682
|
-
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
2683
|
-
return controller.signal;
|
2684
|
-
}
|
2685
|
-
/**
|
2686
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2687
|
-
* cancels the `CancelToken`.
|
2688
|
-
*/ static source() {
|
2689
|
-
let cancel;
|
2690
|
-
const token = new CancelToken_CancelToken(function(c) {
|
2691
|
-
cancel = c;
|
2692
|
-
});
|
2693
|
-
return {
|
2694
|
-
token,
|
2695
|
-
cancel
|
2696
|
-
};
|
2697
|
-
}
|
2698
|
-
}
|
2699
|
-
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
2700
|
-
/**
|
2701
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2702
|
-
*
|
2703
|
-
* Common use case would be to use `Function.prototype.apply`.
|
2704
|
-
*
|
2705
|
-
* ```js
|
2706
|
-
* function f(x, y, z) {}
|
2707
|
-
* var args = [1, 2, 3];
|
2708
|
-
* f.apply(null, args);
|
2709
|
-
* ```
|
2710
|
-
*
|
2711
|
-
* With `spread` this example can be re-written.
|
2712
|
-
*
|
2713
|
-
* ```js
|
2714
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
2715
|
-
* ```
|
2716
|
-
*
|
2717
|
-
* @param {Function} callback
|
2718
|
-
*
|
2719
|
-
* @returns {Function}
|
2720
|
-
*/ function spread(callback) {
|
2721
|
-
return function(arr) {
|
2722
|
-
return callback.apply(null, arr);
|
2723
|
-
};
|
2724
|
-
}
|
2725
|
-
/**
|
2726
|
-
* Determines whether the payload is an error thrown by Axios
|
2727
|
-
*
|
2728
|
-
* @param {*} payload The value to test
|
2729
|
-
*
|
2730
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2731
|
-
*/ function isAxiosError(payload) {
|
2732
|
-
return utils.isObject(payload) && true === payload.isAxiosError;
|
2733
|
-
}
|
2734
|
-
const HttpStatusCode = {
|
2735
|
-
Continue: 100,
|
2736
|
-
SwitchingProtocols: 101,
|
2737
|
-
Processing: 102,
|
2738
|
-
EarlyHints: 103,
|
2739
|
-
Ok: 200,
|
2740
|
-
Created: 201,
|
2741
|
-
Accepted: 202,
|
2742
|
-
NonAuthoritativeInformation: 203,
|
2743
|
-
NoContent: 204,
|
2744
|
-
ResetContent: 205,
|
2745
|
-
PartialContent: 206,
|
2746
|
-
MultiStatus: 207,
|
2747
|
-
AlreadyReported: 208,
|
2748
|
-
ImUsed: 226,
|
2749
|
-
MultipleChoices: 300,
|
2750
|
-
MovedPermanently: 301,
|
2751
|
-
Found: 302,
|
2752
|
-
SeeOther: 303,
|
2753
|
-
NotModified: 304,
|
2754
|
-
UseProxy: 305,
|
2755
|
-
Unused: 306,
|
2756
|
-
TemporaryRedirect: 307,
|
2757
|
-
PermanentRedirect: 308,
|
2758
|
-
BadRequest: 400,
|
2759
|
-
Unauthorized: 401,
|
2760
|
-
PaymentRequired: 402,
|
2761
|
-
Forbidden: 403,
|
2762
|
-
NotFound: 404,
|
2763
|
-
MethodNotAllowed: 405,
|
2764
|
-
NotAcceptable: 406,
|
2765
|
-
ProxyAuthenticationRequired: 407,
|
2766
|
-
RequestTimeout: 408,
|
2767
|
-
Conflict: 409,
|
2768
|
-
Gone: 410,
|
2769
|
-
LengthRequired: 411,
|
2770
|
-
PreconditionFailed: 412,
|
2771
|
-
PayloadTooLarge: 413,
|
2772
|
-
UriTooLong: 414,
|
2773
|
-
UnsupportedMediaType: 415,
|
2774
|
-
RangeNotSatisfiable: 416,
|
2775
|
-
ExpectationFailed: 417,
|
2776
|
-
ImATeapot: 418,
|
2777
|
-
MisdirectedRequest: 421,
|
2778
|
-
UnprocessableEntity: 422,
|
2779
|
-
Locked: 423,
|
2780
|
-
FailedDependency: 424,
|
2781
|
-
TooEarly: 425,
|
2782
|
-
UpgradeRequired: 426,
|
2783
|
-
PreconditionRequired: 428,
|
2784
|
-
TooManyRequests: 429,
|
2785
|
-
RequestHeaderFieldsTooLarge: 431,
|
2786
|
-
UnavailableForLegalReasons: 451,
|
2787
|
-
InternalServerError: 500,
|
2788
|
-
NotImplemented: 501,
|
2789
|
-
BadGateway: 502,
|
2790
|
-
ServiceUnavailable: 503,
|
2791
|
-
GatewayTimeout: 504,
|
2792
|
-
HttpVersionNotSupported: 505,
|
2793
|
-
VariantAlsoNegotiates: 506,
|
2794
|
-
InsufficientStorage: 507,
|
2795
|
-
LoopDetected: 508,
|
2796
|
-
NotExtended: 510,
|
2797
|
-
NetworkAuthenticationRequired: 511
|
2798
|
-
};
|
2799
|
-
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
2800
|
-
HttpStatusCode[value] = key;
|
2801
|
-
});
|
2802
|
-
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
2803
|
-
/**
|
2804
|
-
* Create an instance of Axios
|
2805
|
-
*
|
2806
|
-
* @param {Object} defaultConfig The default config for the instance
|
2807
|
-
*
|
2808
|
-
* @returns {Axios} A new instance of Axios
|
2809
|
-
*/ function createInstance(defaultConfig) {
|
2810
|
-
const context = new Axios(defaultConfig);
|
2811
|
-
const instance = bind(Axios.prototype.request, context);
|
2812
|
-
// Copy axios.prototype to instance
|
2813
|
-
utils.extend(instance, Axios.prototype, context, {
|
2814
|
-
allOwnKeys: true
|
2815
|
-
});
|
2816
|
-
// Copy context to instance
|
2817
|
-
utils.extend(instance, context, null, {
|
2818
|
-
allOwnKeys: true
|
2819
|
-
});
|
2820
|
-
// Factory for creating new instances
|
2821
|
-
instance.create = function(instanceConfig) {
|
2822
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2823
|
-
};
|
2824
|
-
return instance;
|
2825
|
-
}
|
2826
|
-
// Create the default instance to be exported
|
2827
|
-
const axios = createInstance(defaults);
|
2828
|
-
// Expose Axios class to allow class inheritance
|
2829
|
-
axios.Axios = Axios;
|
2830
|
-
// Expose Cancel & CancelToken
|
2831
|
-
axios.CanceledError = CanceledError;
|
2832
|
-
axios.CancelToken = CancelToken;
|
2833
|
-
axios.isCancel = isCancel;
|
2834
|
-
axios.VERSION = VERSION;
|
2835
|
-
axios.toFormData = toFormData;
|
2836
|
-
// Expose AxiosError class
|
2837
|
-
axios.AxiosError = core_AxiosError;
|
2838
|
-
// alias for CanceledError for backward compatibility
|
2839
|
-
axios.Cancel = axios.CanceledError;
|
2840
|
-
// Expose all/spread
|
2841
|
-
axios.all = function(promises) {
|
2842
|
-
return Promise.all(promises);
|
2843
|
-
};
|
2844
|
-
axios.spread = spread;
|
2845
|
-
// Expose isAxiosError
|
2846
|
-
axios.isAxiosError = isAxiosError;
|
2847
|
-
// Expose mergeConfig
|
2848
|
-
axios.mergeConfig = mergeConfig;
|
2849
|
-
axios.AxiosHeaders = AxiosHeaders;
|
2850
|
-
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2851
|
-
axios.getAdapter = adapters_adapters.getAdapter;
|
2852
|
-
axios.HttpStatusCode = helpers_HttpStatusCode;
|
2853
|
-
axios.default = axios;
|
2854
|
-
// this module should only have a default export
|
2855
|
-
/* ESM default export */ const lib_axios = axios;
|
2856
|
-
// This module is intended to unwrap Axios default export as named.
|
2857
|
-
// Keep top-level export same with static properties
|
2858
|
-
// so that it can keep same with es module or cjs
|
2859
|
-
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;
|
2860
|
-
// EXTERNAL MODULE: os (ignored)
|
2861
|
-
var os_ignored_ = __webpack_require__("?e2b1");
|
2862
|
-
// EXTERNAL MODULE: crypto (ignored)
|
2863
|
-
__webpack_require__("?c628");
|
2864
|
-
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
2865
|
-
__webpack_require__("?9452");
|
2866
|
-
class APIResource {
|
2867
|
-
constructor(client){
|
2868
|
-
this._client = client;
|
2869
|
-
}
|
2870
|
-
}
|
2871
|
-
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
2872
|
-
/**
|
2873
|
-
* Create a new agent. | 调用接口创建一个新的智能体。
|
2874
|
-
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
2875
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
2876
|
-
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
2877
|
-
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
2878
|
-
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
2879
|
-
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
2880
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2881
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2882
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2883
|
-
* @returns Information about the created bot. | 创建的 Bot 信息。
|
2884
|
-
*/ async create(params, options) {
|
2885
|
-
const apiUrl = '/v1/bot/create';
|
2886
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2887
|
-
return result.data;
|
2888
|
-
}
|
2889
|
-
/**
|
2890
|
-
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
2891
|
-
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
2892
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
2893
|
-
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
2894
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
2895
|
-
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
2896
|
-
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
2897
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2898
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2899
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2900
|
-
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
2901
|
-
* @returns Undefined | 无返回值
|
2902
|
-
*/ async update(params, options) {
|
2903
|
-
const apiUrl = '/v1/bot/update';
|
2904
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2905
|
-
return result.data;
|
2906
|
-
}
|
2907
|
-
/**
|
2908
|
-
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
2909
|
-
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
2910
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
2911
|
-
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
2912
|
-
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
2913
|
-
* @param params.page_size - Optional Pagination size. | 分页大小。
|
2914
|
-
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
2915
|
-
* @returns List of published bots. | 已发布的 Bot 列表。
|
2916
|
-
*/ async list(params, options) {
|
2917
|
-
const apiUrl = '/v1/space/published_bots_list';
|
2918
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2919
|
-
return result.data;
|
2920
|
-
}
|
2921
|
-
/**
|
2922
|
-
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
2923
|
-
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
2924
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
2925
|
-
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
2926
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
2927
|
-
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
2928
|
-
* @returns Undefined | 无返回值
|
2929
|
-
*/ async publish(params, options) {
|
2930
|
-
const apiUrl = '/v1/bot/publish';
|
2931
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2932
|
-
return result.data;
|
2933
|
-
}
|
2934
|
-
/**
|
2935
|
-
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
2936
|
-
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
2937
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
2938
|
-
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
2939
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
2940
|
-
* @returns Information about the bot. | Bot 的配置信息。
|
2941
|
-
*/ async retrieve(params, options) {
|
2942
|
-
const apiUrl = '/v1/bot/get_online_info';
|
2943
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2944
|
-
return result.data;
|
2945
|
-
}
|
2946
|
-
}
|
2947
|
-
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
2948
|
-
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
2949
|
-
try {
|
2950
|
-
return JSON.parse(jsonString);
|
2951
|
-
} catch (error) {
|
2952
|
-
return defaultValue;
|
2953
|
-
}
|
2954
|
-
}
|
2955
|
-
function sleep(ms) {
|
2956
|
-
return new Promise((resolve)=>{
|
2957
|
-
setTimeout(resolve, ms);
|
2958
|
-
});
|
2959
|
-
}
|
2960
|
-
function isBrowser() {
|
2961
|
-
return 'undefined' != typeof window;
|
2962
|
-
}
|
2963
|
-
function esm_isPlainObject(obj) {
|
2964
|
-
if ('object' != typeof obj || null === obj) return false;
|
2965
|
-
const proto = Object.getPrototypeOf(obj);
|
2966
|
-
if (null === proto) return true;
|
2967
|
-
let baseProto = proto;
|
2968
|
-
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
2969
|
-
return proto === baseProto;
|
2970
|
-
}
|
2971
|
-
function esm_mergeConfig() {
|
2972
|
-
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
2973
|
-
return objects.reduce((result, obj)=>{
|
2974
|
-
if (void 0 === obj) return result || {};
|
2975
|
-
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
2976
|
-
if (esm_isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = esm_mergeConfig(result[key] || {}, obj[key]);
|
2977
|
-
else result[key] = obj[key];
|
2978
|
-
}
|
2979
|
-
return result;
|
2980
|
-
}, {});
|
2981
|
-
}
|
2982
|
-
function isPersonalAccessToken(token) {
|
2983
|
-
return null == token ? void 0 : token.startsWith('pat_');
|
2984
|
-
}
|
2985
|
-
/* eslint-disable max-params */ class CozeError extends Error {
|
2986
|
-
}
|
2987
|
-
class APIError extends CozeError {
|
2988
|
-
static makeMessage(status, errorBody, message, headers) {
|
2989
|
-
if (!errorBody && message) return message;
|
2990
|
-
if (errorBody) {
|
2991
|
-
const list = [];
|
2992
|
-
const { code, msg, error } = errorBody;
|
2993
|
-
if (code) list.push(`code: ${code}`);
|
2994
|
-
if (msg) list.push(`msg: ${msg}`);
|
2995
|
-
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
2996
|
-
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
2997
|
-
if (logId) list.push(`logid: ${logId}`);
|
2998
|
-
const help_doc = null == error ? void 0 : error.help_doc;
|
2999
|
-
if (help_doc) list.push(`help doc: ${help_doc}`);
|
3000
|
-
return list.join(', ');
|
3001
|
-
}
|
3002
|
-
if (status) return `http status code: ${status} (no body)`;
|
3003
|
-
return '(no status code or body)';
|
3004
|
-
}
|
3005
|
-
static generate(status, errorResponse, message, headers) {
|
3006
|
-
if (!status) return new APIConnectionError({
|
3007
|
-
cause: castToError(errorResponse)
|
3008
|
-
});
|
3009
|
-
const error = errorResponse;
|
3010
|
-
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
3011
|
-
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
3012
|
-
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
3013
|
-
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
3014
|
-
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
3015
|
-
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
3016
|
-
if (408 === status) return new TimeoutError(status, error, message, headers);
|
3017
|
-
if (502 === status) return new GatewayError(status, error, message, headers);
|
3018
|
-
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
3019
|
-
return new APIError(status, error, message, headers);
|
3020
|
-
}
|
3021
|
-
constructor(status, error, message, headers){
|
3022
|
-
var _error_error, _error_error1;
|
3023
|
-
super(`${APIError.makeMessage(status, error, message, headers)}`);
|
3024
|
-
this.status = status;
|
3025
|
-
this.headers = headers;
|
3026
|
-
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
3027
|
-
// this.error = error;
|
3028
|
-
this.code = null == error ? void 0 : error.code;
|
3029
|
-
this.msg = null == error ? void 0 : error.msg;
|
3030
|
-
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
3031
|
-
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
3032
|
-
this.rawError = error;
|
3033
|
-
}
|
3034
|
-
}
|
3035
|
-
class APIConnectionError extends APIError {
|
3036
|
-
constructor({ message, cause }){
|
3037
|
-
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
3038
|
-
// if (cause) {
|
3039
|
-
// this.cause = cause;
|
3040
|
-
// }
|
3041
|
-
}
|
3042
|
-
}
|
3043
|
-
class APIUserAbortError extends APIError {
|
3044
|
-
constructor(message){
|
3045
|
-
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
3046
|
-
}
|
3047
|
-
}
|
3048
|
-
class BadRequestError extends APIError {
|
3049
|
-
constructor(...args){
|
3050
|
-
super(...args), this.name = 'BadRequestError', this.status = 400;
|
3051
|
-
}
|
3052
|
-
}
|
3053
|
-
class AuthenticationError extends APIError {
|
3054
|
-
constructor(...args){
|
3055
|
-
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
3056
|
-
}
|
3057
|
-
}
|
3058
|
-
class PermissionDeniedError extends APIError {
|
3059
|
-
constructor(...args){
|
3060
|
-
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
3061
|
-
}
|
3062
|
-
}
|
3063
|
-
class NotFoundError extends APIError {
|
3064
|
-
constructor(...args){
|
3065
|
-
super(...args), this.name = 'NotFoundError', this.status = 404;
|
3066
|
-
}
|
3067
|
-
}
|
3068
|
-
class TimeoutError extends APIError {
|
3069
|
-
constructor(...args){
|
3070
|
-
super(...args), this.name = 'TimeoutError', this.status = 408;
|
3071
|
-
}
|
3072
|
-
}
|
3073
|
-
class RateLimitError extends APIError {
|
3074
|
-
constructor(...args){
|
3075
|
-
super(...args), this.name = 'RateLimitError', this.status = 429;
|
3076
|
-
}
|
3077
|
-
}
|
3078
|
-
class InternalServerError extends APIError {
|
3079
|
-
constructor(...args){
|
3080
|
-
super(...args), this.name = 'InternalServerError', this.status = 500;
|
3081
|
-
}
|
3082
|
-
}
|
3083
|
-
class GatewayError extends APIError {
|
3084
|
-
constructor(...args){
|
3085
|
-
super(...args), this.name = 'GatewayError', this.status = 502;
|
3086
|
-
}
|
3087
|
-
}
|
3088
|
-
const castToError = (err)=>{
|
3089
|
-
if (err instanceof Error) return err;
|
3090
|
-
return new Error(err);
|
3091
|
-
};
|
3092
|
-
class Messages extends APIResource {
|
3093
|
-
/**
|
3094
|
-
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
3095
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
3096
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
3097
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3098
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3099
|
-
* @returns An array of chat messages. | 对话消息数组。
|
3100
|
-
*/ async list(conversation_id, chat_id, options) {
|
3101
|
-
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3102
|
-
const result = await this._client.get(apiUrl, void 0, false, options);
|
3103
|
-
return result.data;
|
3104
|
-
}
|
3105
|
-
}
|
3106
|
-
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
3107
|
-
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
3108
|
-
...i,
|
3109
|
-
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
3110
|
-
}));
|
3111
|
-
class Chat extends APIResource {
|
3112
|
-
/**
|
3113
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3114
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3115
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3116
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3117
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3118
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3119
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3120
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
3121
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3122
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3123
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3124
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3125
|
-
* @returns The data of the created chat. | 创建的对话数据。
|
3126
|
-
*/ async create(params, options) {
|
3127
|
-
if (!params.user_id) params.user_id = uuid();
|
3128
|
-
const { conversation_id, ...rest } = params;
|
3129
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3130
|
-
const payload = {
|
3131
|
-
...rest,
|
3132
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3133
|
-
stream: false
|
3134
|
-
};
|
3135
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3136
|
-
return result.data;
|
3137
|
-
}
|
3138
|
-
/**
|
3139
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3140
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3141
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3142
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3143
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3144
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3145
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3146
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3147
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3148
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3149
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3150
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3151
|
-
* @returns
|
3152
|
-
*/ async createAndPoll(params, options) {
|
3153
|
-
if (!params.user_id) params.user_id = uuid();
|
3154
|
-
const { conversation_id, ...rest } = params;
|
3155
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3156
|
-
const payload = {
|
3157
|
-
...rest,
|
3158
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3159
|
-
stream: false
|
3160
|
-
};
|
3161
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3162
|
-
const chatId = result.data.id;
|
3163
|
-
const conversationId = result.data.conversation_id;
|
3164
|
-
let chat;
|
3165
|
-
while(true){
|
3166
|
-
await sleep(100);
|
3167
|
-
chat = await this.retrieve(conversationId, chatId);
|
3168
|
-
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
3169
|
-
}
|
3170
|
-
const messageList = await this.messages.list(conversationId, chatId);
|
3171
|
-
return {
|
3172
|
-
chat,
|
3173
|
-
messages: messageList
|
3174
|
-
};
|
3175
|
-
}
|
3176
|
-
/**
|
3177
|
-
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
3178
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3179
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3180
|
-
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
3181
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3182
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3183
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3184
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3185
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3186
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3187
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3188
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3189
|
-
* @returns A stream of chat data. | 对话数据流。
|
3190
|
-
*/ async *stream(params, options) {
|
3191
|
-
if (!params.user_id) params.user_id = uuid();
|
3192
|
-
const { conversation_id, ...rest } = params;
|
3193
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3194
|
-
const payload = {
|
3195
|
-
...rest,
|
3196
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3197
|
-
stream: true
|
3198
|
-
};
|
3199
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
3200
|
-
for await (const message of result)if ("done" === message.event) {
|
3201
|
-
const ret = {
|
3202
|
-
event: message.event,
|
3203
|
-
data: '[DONE]'
|
3204
|
-
};
|
3205
|
-
yield ret;
|
3206
|
-
} else try {
|
3207
|
-
const ret = {
|
3208
|
-
event: message.event,
|
3209
|
-
data: JSON.parse(message.data)
|
3210
|
-
};
|
3211
|
-
yield ret;
|
3212
|
-
} catch (error) {
|
3213
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3214
|
-
}
|
3215
|
-
}
|
3216
|
-
/**
|
3217
|
-
* Get the detailed information of the chat. | 查看对话的详细信息。
|
3218
|
-
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
3219
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
3220
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3221
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3222
|
-
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
3223
|
-
*/ async retrieve(conversation_id, chat_id, options) {
|
3224
|
-
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3225
|
-
const result = await this._client.post(apiUrl, void 0, false, options);
|
3226
|
-
return result.data;
|
3227
|
-
}
|
3228
|
-
/**
|
3229
|
-
* Cancel a chat session. | 取消对话会话。
|
3230
|
-
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
3231
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
3232
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3233
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3234
|
-
* @returns The data of the canceled chat. | 取消的对话数据。
|
3235
|
-
*/ async cancel(conversation_id, chat_id, options) {
|
3236
|
-
const apiUrl = '/v3/chat/cancel';
|
3237
|
-
const payload = {
|
3238
|
-
conversation_id,
|
3239
|
-
chat_id
|
3240
|
-
};
|
3241
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3242
|
-
return result.data;
|
3243
|
-
}
|
3244
|
-
/**
|
3245
|
-
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
3246
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
3247
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
3248
|
-
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
3249
|
-
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
3250
|
-
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
3251
|
-
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
3252
|
-
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
3253
|
-
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
3254
|
-
*/ async *submitToolOutputs(params, options) {
|
3255
|
-
const { conversation_id, chat_id, ...rest } = params;
|
3256
|
-
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
3257
|
-
const payload = {
|
3258
|
-
...rest
|
3259
|
-
};
|
3260
|
-
if (false === params.stream) {
|
3261
|
-
const response = await this._client.post(apiUrl, payload, false, options);
|
3262
|
-
return response.data;
|
3114
|
+
dispatchRequest.bind(this),
|
3115
|
+
void 0
|
3116
|
+
];
|
3117
|
+
chain.unshift.apply(chain, requestInterceptorChain);
|
3118
|
+
chain.push.apply(chain, responseInterceptorChain);
|
3119
|
+
len = chain.length;
|
3120
|
+
promise = Promise.resolve(config);
|
3121
|
+
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
3122
|
+
return promise;
|
3263
3123
|
}
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
} else try {
|
3273
|
-
const ret = {
|
3274
|
-
event: message.event,
|
3275
|
-
data: JSON.parse(message.data)
|
3276
|
-
};
|
3277
|
-
yield ret;
|
3124
|
+
len = requestInterceptorChain.length;
|
3125
|
+
let newConfig = config;
|
3126
|
+
i = 0;
|
3127
|
+
while(i < len){
|
3128
|
+
const onFulfilled = requestInterceptorChain[i++];
|
3129
|
+
const onRejected = requestInterceptorChain[i++];
|
3130
|
+
try {
|
3131
|
+
newConfig = onFulfilled(newConfig);
|
3278
3132
|
} catch (error) {
|
3279
|
-
|
3133
|
+
onRejected.call(this, error);
|
3134
|
+
break;
|
3280
3135
|
}
|
3281
3136
|
}
|
3137
|
+
try {
|
3138
|
+
promise = dispatchRequest.call(this, newConfig);
|
3139
|
+
} catch (error) {
|
3140
|
+
return Promise.reject(error);
|
3141
|
+
}
|
3142
|
+
i = 0;
|
3143
|
+
len = responseInterceptorChain.length;
|
3144
|
+
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
3145
|
+
return promise;
|
3282
3146
|
}
|
3283
|
-
|
3284
|
-
|
3147
|
+
getUri(config) {
|
3148
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
3149
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
3150
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
3285
3151
|
}
|
3286
3152
|
}
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3293
|
-
|
3294
|
-
|
3295
|
-
|
3296
|
-
|
3297
|
-
|
3298
|
-
|
3299
|
-
}
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3305
|
-
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
|
3310
|
-
|
3311
|
-
|
3312
|
-
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
3319
|
-
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
3320
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
3321
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3322
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3323
|
-
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
3324
|
-
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
3325
|
-
* @param params.content - Optional The content of the message. | 消息的内容。
|
3326
|
-
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
3327
|
-
* @returns Information about the modified message. | 消息详情。
|
3328
|
-
*/ // eslint-disable-next-line max-params
|
3329
|
-
async update(conversation_id, message_id, params, options) {
|
3330
|
-
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3331
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3332
|
-
return response.message;
|
3333
|
-
}
|
3334
|
-
/**
|
3335
|
-
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
3336
|
-
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
3337
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
3338
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3339
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3340
|
-
* @returns Information about the message. | 消息详情。
|
3341
|
-
*/ async retrieve(conversation_id, message_id, options) {
|
3342
|
-
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3343
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3344
|
-
return response.data;
|
3153
|
+
// Provide aliases for supported request methods
|
3154
|
+
utils.forEach([
|
3155
|
+
'delete',
|
3156
|
+
'get',
|
3157
|
+
'head',
|
3158
|
+
'options'
|
3159
|
+
], function(method) {
|
3160
|
+
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
3161
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3162
|
+
method,
|
3163
|
+
url,
|
3164
|
+
data: (config || {}).data
|
3165
|
+
}));
|
3166
|
+
};
|
3167
|
+
});
|
3168
|
+
utils.forEach([
|
3169
|
+
'post',
|
3170
|
+
'put',
|
3171
|
+
'patch'
|
3172
|
+
], function(method) {
|
3173
|
+
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
3174
|
+
return function(url, data, config) {
|
3175
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3176
|
+
method,
|
3177
|
+
headers: isForm ? {
|
3178
|
+
'Content-Type': 'multipart/form-data'
|
3179
|
+
} : {},
|
3180
|
+
url,
|
3181
|
+
data
|
3182
|
+
}));
|
3183
|
+
};
|
3345
3184
|
}
|
3346
|
-
|
3347
|
-
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3185
|
+
Axios_Axios.prototype[method] = generateHTTPMethod();
|
3186
|
+
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
3187
|
+
});
|
3188
|
+
/* ESM default export */ const Axios = Axios_Axios;
|
3189
|
+
/**
|
3190
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
3191
|
+
*
|
3192
|
+
* @param {Function} executor The executor function.
|
3193
|
+
*
|
3194
|
+
* @returns {CancelToken}
|
3195
|
+
*/ class CancelToken_CancelToken {
|
3196
|
+
constructor(executor){
|
3197
|
+
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
3198
|
+
let resolvePromise;
|
3199
|
+
this.promise = new Promise(function(resolve) {
|
3200
|
+
resolvePromise = resolve;
|
3201
|
+
});
|
3202
|
+
const token = this;
|
3203
|
+
// eslint-disable-next-line func-names
|
3204
|
+
this.promise.then((cancel)=>{
|
3205
|
+
if (!token._listeners) return;
|
3206
|
+
let i = token._listeners.length;
|
3207
|
+
while(i-- > 0)token._listeners[i](cancel);
|
3208
|
+
token._listeners = null;
|
3209
|
+
});
|
3210
|
+
// eslint-disable-next-line func-names
|
3211
|
+
this.promise.then = (onfulfilled)=>{
|
3212
|
+
let _resolve;
|
3213
|
+
// eslint-disable-next-line func-names
|
3214
|
+
const promise = new Promise((resolve)=>{
|
3215
|
+
token.subscribe(resolve);
|
3216
|
+
_resolve = resolve;
|
3217
|
+
}).then(onfulfilled);
|
3218
|
+
promise.cancel = function() {
|
3219
|
+
token.unsubscribe(_resolve);
|
3220
|
+
};
|
3221
|
+
return promise;
|
3222
|
+
};
|
3223
|
+
executor(function(message, config, request) {
|
3224
|
+
if (token.reason) // Cancellation has already been requested
|
3225
|
+
return;
|
3226
|
+
token.reason = new CanceledError(message, config, request);
|
3227
|
+
resolvePromise(token.reason);
|
3228
|
+
});
|
3362
3229
|
}
|
3363
3230
|
/**
|
3364
|
-
*
|
3365
|
-
|
3366
|
-
|
3367
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3368
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3369
|
-
* @returns Details of the deleted message. | 已删除的消息详情。
|
3370
|
-
*/ async delete(conversation_id, message_id, options) {
|
3371
|
-
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3372
|
-
const response = await this._client.post(apiUrl, void 0, false, options);
|
3373
|
-
return response.data;
|
3231
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
3232
|
+
*/ throwIfRequested() {
|
3233
|
+
if (this.reason) throw this.reason;
|
3374
3234
|
}
|
3375
|
-
}
|
3376
|
-
class Conversations extends APIResource {
|
3377
3235
|
/**
|
3378
|
-
*
|
3379
|
-
|
3380
|
-
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3388
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3389
|
-
return response.data;
|
3236
|
+
* Subscribe to the cancel signal
|
3237
|
+
*/ subscribe(listener) {
|
3238
|
+
if (this.reason) {
|
3239
|
+
listener(this.reason);
|
3240
|
+
return;
|
3241
|
+
}
|
3242
|
+
if (this._listeners) this._listeners.push(listener);
|
3243
|
+
else this._listeners = [
|
3244
|
+
listener
|
3245
|
+
];
|
3390
3246
|
}
|
3391
3247
|
/**
|
3392
|
-
*
|
3393
|
-
|
3394
|
-
|
3395
|
-
|
3396
|
-
|
3397
|
-
*/ async retrieve(conversation_id, options) {
|
3398
|
-
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
3399
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3400
|
-
return response.data;
|
3248
|
+
* Unsubscribe from the cancel signal
|
3249
|
+
*/ unsubscribe(listener) {
|
3250
|
+
if (!this._listeners) return;
|
3251
|
+
const index = this._listeners.indexOf(listener);
|
3252
|
+
if (-1 !== index) this._listeners.splice(index, 1);
|
3401
3253
|
}
|
3402
|
-
|
3403
|
-
|
3404
|
-
|
3405
|
-
|
3406
|
-
|
3407
|
-
|
3408
|
-
|
3409
|
-
|
3410
|
-
const apiUrl = '/v1/conversations';
|
3411
|
-
const response = await this._client.get(apiUrl, params, false, options);
|
3412
|
-
return response.data;
|
3254
|
+
toAbortSignal() {
|
3255
|
+
const controller = new AbortController();
|
3256
|
+
const abort = (err)=>{
|
3257
|
+
controller.abort(err);
|
3258
|
+
};
|
3259
|
+
this.subscribe(abort);
|
3260
|
+
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
3261
|
+
return controller.signal;
|
3413
3262
|
}
|
3414
3263
|
/**
|
3415
|
-
*
|
3416
|
-
*
|
3417
|
-
|
3418
|
-
|
3419
|
-
const
|
3420
|
-
|
3421
|
-
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3264
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
3265
|
+
* cancels the `CancelToken`.
|
3266
|
+
*/ static source() {
|
3267
|
+
let cancel;
|
3268
|
+
const token = new CancelToken_CancelToken(function(c) {
|
3269
|
+
cancel = c;
|
3270
|
+
});
|
3271
|
+
return {
|
3272
|
+
token,
|
3273
|
+
cancel
|
3274
|
+
};
|
3425
3275
|
}
|
3426
3276
|
}
|
3277
|
+
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
3278
|
+
/**
|
3279
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
3280
|
+
*
|
3281
|
+
* Common use case would be to use `Function.prototype.apply`.
|
3282
|
+
*
|
3283
|
+
* ```js
|
3284
|
+
* function f(x, y, z) {}
|
3285
|
+
* var args = [1, 2, 3];
|
3286
|
+
* f.apply(null, args);
|
3287
|
+
* ```
|
3288
|
+
*
|
3289
|
+
* With `spread` this example can be re-written.
|
3290
|
+
*
|
3291
|
+
* ```js
|
3292
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
3293
|
+
* ```
|
3294
|
+
*
|
3295
|
+
* @param {Function} callback
|
3296
|
+
*
|
3297
|
+
* @returns {Function}
|
3298
|
+
*/ function spread(callback) {
|
3299
|
+
return function(arr) {
|
3300
|
+
return callback.apply(null, arr);
|
3301
|
+
};
|
3302
|
+
}
|
3303
|
+
/**
|
3304
|
+
* Determines whether the payload is an error thrown by Axios
|
3305
|
+
*
|
3306
|
+
* @param {*} payload The value to test
|
3307
|
+
*
|
3308
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
3309
|
+
*/ function isAxiosError(payload) {
|
3310
|
+
return utils.isObject(payload) && true === payload.isAxiosError;
|
3311
|
+
}
|
3312
|
+
const HttpStatusCode = {
|
3313
|
+
Continue: 100,
|
3314
|
+
SwitchingProtocols: 101,
|
3315
|
+
Processing: 102,
|
3316
|
+
EarlyHints: 103,
|
3317
|
+
Ok: 200,
|
3318
|
+
Created: 201,
|
3319
|
+
Accepted: 202,
|
3320
|
+
NonAuthoritativeInformation: 203,
|
3321
|
+
NoContent: 204,
|
3322
|
+
ResetContent: 205,
|
3323
|
+
PartialContent: 206,
|
3324
|
+
MultiStatus: 207,
|
3325
|
+
AlreadyReported: 208,
|
3326
|
+
ImUsed: 226,
|
3327
|
+
MultipleChoices: 300,
|
3328
|
+
MovedPermanently: 301,
|
3329
|
+
Found: 302,
|
3330
|
+
SeeOther: 303,
|
3331
|
+
NotModified: 304,
|
3332
|
+
UseProxy: 305,
|
3333
|
+
Unused: 306,
|
3334
|
+
TemporaryRedirect: 307,
|
3335
|
+
PermanentRedirect: 308,
|
3336
|
+
BadRequest: 400,
|
3337
|
+
Unauthorized: 401,
|
3338
|
+
PaymentRequired: 402,
|
3339
|
+
Forbidden: 403,
|
3340
|
+
NotFound: 404,
|
3341
|
+
MethodNotAllowed: 405,
|
3342
|
+
NotAcceptable: 406,
|
3343
|
+
ProxyAuthenticationRequired: 407,
|
3344
|
+
RequestTimeout: 408,
|
3345
|
+
Conflict: 409,
|
3346
|
+
Gone: 410,
|
3347
|
+
LengthRequired: 411,
|
3348
|
+
PreconditionFailed: 412,
|
3349
|
+
PayloadTooLarge: 413,
|
3350
|
+
UriTooLong: 414,
|
3351
|
+
UnsupportedMediaType: 415,
|
3352
|
+
RangeNotSatisfiable: 416,
|
3353
|
+
ExpectationFailed: 417,
|
3354
|
+
ImATeapot: 418,
|
3355
|
+
MisdirectedRequest: 421,
|
3356
|
+
UnprocessableEntity: 422,
|
3357
|
+
Locked: 423,
|
3358
|
+
FailedDependency: 424,
|
3359
|
+
TooEarly: 425,
|
3360
|
+
UpgradeRequired: 426,
|
3361
|
+
PreconditionRequired: 428,
|
3362
|
+
TooManyRequests: 429,
|
3363
|
+
RequestHeaderFieldsTooLarge: 431,
|
3364
|
+
UnavailableForLegalReasons: 451,
|
3365
|
+
InternalServerError: 500,
|
3366
|
+
NotImplemented: 501,
|
3367
|
+
BadGateway: 502,
|
3368
|
+
ServiceUnavailable: 503,
|
3369
|
+
GatewayTimeout: 504,
|
3370
|
+
HttpVersionNotSupported: 505,
|
3371
|
+
VariantAlsoNegotiates: 506,
|
3372
|
+
InsufficientStorage: 507,
|
3373
|
+
LoopDetected: 508,
|
3374
|
+
NotExtended: 510,
|
3375
|
+
NetworkAuthenticationRequired: 511
|
3376
|
+
};
|
3377
|
+
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
3378
|
+
HttpStatusCode[value] = key;
|
3379
|
+
});
|
3380
|
+
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
3381
|
+
/**
|
3382
|
+
* Create an instance of Axios
|
3383
|
+
*
|
3384
|
+
* @param {Object} defaultConfig The default config for the instance
|
3385
|
+
*
|
3386
|
+
* @returns {Axios} A new instance of Axios
|
3387
|
+
*/ function createInstance(defaultConfig) {
|
3388
|
+
const context = new Axios(defaultConfig);
|
3389
|
+
const instance = bind(Axios.prototype.request, context);
|
3390
|
+
// Copy axios.prototype to instance
|
3391
|
+
utils.extend(instance, Axios.prototype, context, {
|
3392
|
+
allOwnKeys: true
|
3393
|
+
});
|
3394
|
+
// Copy context to instance
|
3395
|
+
utils.extend(instance, context, null, {
|
3396
|
+
allOwnKeys: true
|
3397
|
+
});
|
3398
|
+
// Factory for creating new instances
|
3399
|
+
instance.create = function(instanceConfig) {
|
3400
|
+
return createInstance(mergeConfig_mergeConfig(defaultConfig, instanceConfig));
|
3401
|
+
};
|
3402
|
+
return instance;
|
3403
|
+
}
|
3404
|
+
// Create the default instance to be exported
|
3405
|
+
const axios = createInstance(defaults);
|
3406
|
+
// Expose Axios class to allow class inheritance
|
3407
|
+
axios.Axios = Axios;
|
3408
|
+
// Expose Cancel & CancelToken
|
3409
|
+
axios.CanceledError = CanceledError;
|
3410
|
+
axios.CancelToken = CancelToken;
|
3411
|
+
axios.isCancel = isCancel;
|
3412
|
+
axios.VERSION = VERSION;
|
3413
|
+
axios.toFormData = toFormData;
|
3414
|
+
// Expose AxiosError class
|
3415
|
+
axios.AxiosError = core_AxiosError;
|
3416
|
+
// alias for CanceledError for backward compatibility
|
3417
|
+
axios.Cancel = axios.CanceledError;
|
3418
|
+
// Expose all/spread
|
3419
|
+
axios.all = function(promises) {
|
3420
|
+
return Promise.all(promises);
|
3421
|
+
};
|
3422
|
+
axios.spread = spread;
|
3423
|
+
// Expose isAxiosError
|
3424
|
+
axios.isAxiosError = isAxiosError;
|
3425
|
+
// Expose mergeConfig
|
3426
|
+
axios.mergeConfig = mergeConfig_mergeConfig;
|
3427
|
+
axios.AxiosHeaders = AxiosHeaders;
|
3428
|
+
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
3429
|
+
axios.getAdapter = adapters_adapters.getAdapter;
|
3430
|
+
axios.HttpStatusCode = helpers_HttpStatusCode;
|
3431
|
+
axios.default = axios;
|
3432
|
+
// this module should only have a default export
|
3433
|
+
/* ESM default export */ const lib_axios = axios;
|
3434
|
+
// This module is intended to unwrap Axios default export as named.
|
3435
|
+
// Keep top-level export same with static properties
|
3436
|
+
// so that it can keep same with es module or cjs
|
3437
|
+
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;
|
3427
3438
|
class Files extends APIResource {
|
3428
3439
|
/**
|
3429
3440
|
* Upload files to Coze platform. | 调用接口上传文件到扣子。
|
@@ -3586,7 +3597,7 @@ class Documents extends APIResource {
|
|
3586
3597
|
* @returns ListDocumentData | 知识库文件列表
|
3587
3598
|
*/ list(params, options) {
|
3588
3599
|
const apiUrl = '/open_api/knowledge/document/list';
|
3589
|
-
const response = this._client.get(apiUrl, params, false,
|
3600
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3590
3601
|
headers: documents_headers
|
3591
3602
|
}));
|
3592
3603
|
return response;
|
@@ -3604,7 +3615,7 @@ class Documents extends APIResource {
|
|
3604
3615
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3605
3616
|
*/ async create(params, options) {
|
3606
3617
|
const apiUrl = '/open_api/knowledge/document/create';
|
3607
|
-
const response = await this._client.post(apiUrl, params, false,
|
3618
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3608
3619
|
headers: documents_headers
|
3609
3620
|
}));
|
3610
3621
|
return response.document_infos;
|
@@ -3620,7 +3631,7 @@ class Documents extends APIResource {
|
|
3620
3631
|
* @returns void | 无返回
|
3621
3632
|
*/ async delete(params, options) {
|
3622
3633
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3623
|
-
await this._client.post(apiUrl, params, false,
|
3634
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3624
3635
|
headers: documents_headers
|
3625
3636
|
}));
|
3626
3637
|
}
|
@@ -3636,7 +3647,7 @@ class Documents extends APIResource {
|
|
3636
3647
|
* @returns void | 无返回
|
3637
3648
|
*/ async update(params, options) {
|
3638
3649
|
const apiUrl = '/open_api/knowledge/document/update';
|
3639
|
-
await this._client.post(apiUrl, params, false,
|
3650
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3640
3651
|
headers: documents_headers
|
3641
3652
|
}));
|
3642
3653
|
}
|
@@ -3662,9 +3673,9 @@ class documents_Documents extends APIResource {
|
|
3662
3673
|
* @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
|
3663
3674
|
* @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
|
3664
3675
|
* @returns ListDocumentData | 知识库文件列表
|
3665
|
-
*/ list(params, options) {
|
3676
|
+
*/ async list(params, options) {
|
3666
3677
|
const apiUrl = '/open_api/knowledge/document/list';
|
3667
|
-
const response = this._client.get(apiUrl, params, false,
|
3678
|
+
const response = await this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3668
3679
|
headers: documents_documents_headers
|
3669
3680
|
}));
|
3670
3681
|
return response;
|
@@ -3680,7 +3691,7 @@ class documents_Documents extends APIResource {
|
|
3680
3691
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3681
3692
|
*/ async create(params, options) {
|
3682
3693
|
const apiUrl = '/open_api/knowledge/document/create';
|
3683
|
-
const response = await this._client.post(apiUrl, params, false,
|
3694
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3684
3695
|
headers: documents_documents_headers
|
3685
3696
|
}));
|
3686
3697
|
return response.document_infos;
|
@@ -3694,7 +3705,7 @@ class documents_Documents extends APIResource {
|
|
3694
3705
|
* @returns void | 无返回
|
3695
3706
|
*/ async delete(params, options) {
|
3696
3707
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3697
|
-
await this._client.post(apiUrl, params, false,
|
3708
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3698
3709
|
headers: documents_documents_headers
|
3699
3710
|
}));
|
3700
3711
|
}
|
@@ -3708,14 +3719,109 @@ class documents_Documents extends APIResource {
|
|
3708
3719
|
* @returns void | 无返回
|
3709
3720
|
*/ async update(params, options) {
|
3710
3721
|
const apiUrl = '/open_api/knowledge/document/update';
|
3711
|
-
await this._client.post(apiUrl, params, false,
|
3722
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3712
3723
|
headers: documents_documents_headers
|
3713
3724
|
}));
|
3714
3725
|
}
|
3715
3726
|
}
|
3727
|
+
class Images extends APIResource {
|
3728
|
+
/**
|
3729
|
+
* Update the description of an image in the knowledge base | 更新知识库中的图片描述
|
3730
|
+
* @docs en: https://www.coze.com/docs/developer_guides/developer_guides/update_image_caption?_lang=en
|
3731
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/update_image_caption?_lang=zh
|
3732
|
+
* @param datasetId - The ID of the dataset | 必选 知识库 ID
|
3733
|
+
* @param documentId - The ID of the document | 必选 知识库文件 ID
|
3734
|
+
* @param params - The parameters for updating the image
|
3735
|
+
* @param params.caption - Required. The description of the image | 必选 图片的描述信息
|
3736
|
+
* @returns undefined
|
3737
|
+
*/ // eslint-disable-next-line max-params
|
3738
|
+
async update(datasetId, documentId, params, options) {
|
3739
|
+
const apiUrl = `/v1/datasets/${datasetId}/images/${documentId}`;
|
3740
|
+
await this._client.put(apiUrl, params, false, options);
|
3741
|
+
}
|
3742
|
+
/**
|
3743
|
+
* List images in the knowledge base | 列出知识库中的图片
|
3744
|
+
* @docs en: https://www.coze.com/docs/developer_guides/developer_guides/get_images?_lang=en
|
3745
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/developer_guides/get_images?_lang=zh
|
3746
|
+
* @param datasetId - The ID of the dataset | 必选 知识库 ID
|
3747
|
+
* @param params - The parameters for listing images
|
3748
|
+
* @param params.page_num - Optional. Page number for pagination, minimum value is 1, defaults to 1 | 可选 分页查询时的页码。默认为 1。
|
3749
|
+
* @param params.page_size - Optional. Number of items per page, range 1-299, defaults to 10 | 可选 分页大小。默认为 10。
|
3750
|
+
* @param params.keyword - Optional. Search keyword for image descriptions | 可选 图片描述的搜索关键词。
|
3751
|
+
* @param params.has_caption - Optional. Filter for images with/without captions | 可选 是否过滤有/无描述的图片。
|
3752
|
+
*/ async list(datasetId, params, options) {
|
3753
|
+
const apiUrl = `/v1/datasets/${datasetId}/images`;
|
3754
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
3755
|
+
return response.data;
|
3756
|
+
}
|
3757
|
+
}
|
3716
3758
|
class Datasets extends APIResource {
|
3759
|
+
/**
|
3760
|
+
* Creates a new dataset | 创建数据集
|
3761
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_dataset?_lang=en
|
3762
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_dataset?_lang=zh
|
3763
|
+
* @param params - The parameters for creating a dataset
|
3764
|
+
* @param {string} params.name - Required. Dataset name, maximum length of 100 characters | 必选 数据集名称,最大长度为 100 个字符
|
3765
|
+
* @param {string} params.space_id - Required. Space ID where the dataset belongs | 必选 数据集所属的空间 ID
|
3766
|
+
* @param {number} params.format_type - Required. Dataset type (0: Text type, 2: Image type) | 必选 数据集类型 (0: 文本类型, 2: 图片类型)
|
3767
|
+
* @param {string} [params.description] - Optional. Dataset description | 可选 数据集描述
|
3768
|
+
* @param {string} [params.file_id] - Optional. Dataset icon file ID from file upload
|
3769
|
+
*/ async create(params, options) {
|
3770
|
+
const apiUrl = '/v1/datasets';
|
3771
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3772
|
+
return response.data;
|
3773
|
+
}
|
3774
|
+
/**
|
3775
|
+
* Lists all datasets in a space | 列出空间中的所有数据集
|
3776
|
+
* @docs en: https://www.coze.com/docs/developer_guides/list_dataset?_lang=en
|
3777
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/list_dataset?_lang=zh
|
3778
|
+
* @param params - The parameters for listing datasets | 列出数据集的参数
|
3779
|
+
* @param {string} params.space_id - Required. Space ID where the datasets belong | 必选 数据集所属的空间 ID
|
3780
|
+
* @param {string} [params.name] - Optional. Dataset name for fuzzy search | 可选 数据集名称用于模糊搜索
|
3781
|
+
* @param {number} [params.format_type] - Optional. Dataset type (0: Text type, 2: Image type) | 可选 数据集类型 (0: 文本类型, 2: 图片类型)
|
3782
|
+
* @param {number} [params.page_num] - Optional. Page number for pagination (default: 1) | 可选 分页查询时的页码。默认为 1。
|
3783
|
+
* @param {number} [params.page_size] - Optional. Number of items per page (default: 10) | 可选 分页大小。默认为 10。
|
3784
|
+
*/ async list(params, options) {
|
3785
|
+
const apiUrl = '/v1/datasets';
|
3786
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
3787
|
+
return response.data;
|
3788
|
+
}
|
3789
|
+
/**
|
3790
|
+
* Updates a dataset | 更新数据集
|
3791
|
+
* @docs en: https://www.coze.com/docs/developer_guides/update_dataset?_lang=en
|
3792
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/update_dataset?_lang=zh
|
3793
|
+
* @param dataset_id - Required. The ID of the dataset to update | 必选 数据集 ID
|
3794
|
+
* @param params - Required. The parameters for updating the dataset | 必选 更新数据集的参数
|
3795
|
+
* @param params.name - Required. Dataset name, maximum length of 100 characters. | 必选 数据集名称,最大长度为 100 个字符。
|
3796
|
+
* @param params.file_id - Optional. Dataset icon, should pass the file_id obtained from the file upload interface. | 可选 数据集图标,应传递从文件上传接口获取的 file_id。
|
3797
|
+
* @param params.description - Optional. Dataset description. | 可选 数据集描述。
|
3798
|
+
*/ async update(dataset_id, params, options) {
|
3799
|
+
const apiUrl = `/v1/datasets/${dataset_id}`;
|
3800
|
+
await this._client.put(apiUrl, params, false, options);
|
3801
|
+
}
|
3802
|
+
/**
|
3803
|
+
* Deletes a dataset | 删除数据集
|
3804
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_dataset?_lang=en
|
3805
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_dataset?_lang=zh
|
3806
|
+
* @param dataset_id - Required. The ID of the dataset to delete | 必选 数据集 ID
|
3807
|
+
*/ async delete(dataset_id, options) {
|
3808
|
+
const apiUrl = `/v1/datasets/${dataset_id}`;
|
3809
|
+
await this._client.delete(apiUrl, false, options);
|
3810
|
+
}
|
3811
|
+
/**
|
3812
|
+
* Views the progress of dataset upload | 查看数据集上传进度
|
3813
|
+
* @docs en: https://www.coze.com/docs/developer_guides/get_dataset_progress?_lang=en
|
3814
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/get_dataset_progress?_lang=zh
|
3815
|
+
* @param dataset_id - Required. The ID of the dataset to process | 必选 数据集 ID
|
3816
|
+
* @param params - Required. The parameters for processing the dataset | 必选 处理数据集的参数
|
3817
|
+
* @param params.dataset_ids - Required. List of dataset IDs | 必选 数据集 ID 列表
|
3818
|
+
*/ async process(dataset_id, params, options) {
|
3819
|
+
const apiUrl = `/v1/datasets/${dataset_id}/process`;
|
3820
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3821
|
+
return response.data;
|
3822
|
+
}
|
3717
3823
|
constructor(...args){
|
3718
|
-
super(...args), this.documents = new documents_Documents(this._client);
|
3824
|
+
super(...args), this.documents = new documents_Documents(this._client), this.images = new Images(this._client);
|
3719
3825
|
}
|
3720
3826
|
}
|
3721
3827
|
class Voices extends APIResource {
|
@@ -3772,7 +3878,10 @@ class Speech extends APIResource {
|
|
3772
3878
|
* @returns Speech synthesis data
|
3773
3879
|
*/ async create(params, options) {
|
3774
3880
|
const apiUrl = '/v1/audio/speech';
|
3775
|
-
const response = await this._client.post(apiUrl,
|
3881
|
+
const response = await this._client.post(apiUrl, {
|
3882
|
+
...params,
|
3883
|
+
sample_rate: params.sample_rate || 24000
|
3884
|
+
}, false, mergeConfig(options, {
|
3776
3885
|
responseType: 'arraybuffer'
|
3777
3886
|
}));
|
3778
3887
|
return response;
|
@@ -3785,23 +3894,40 @@ class Rooms extends APIResource {
|
|
3785
3894
|
return response.data;
|
3786
3895
|
}
|
3787
3896
|
}
|
3788
|
-
class
|
3897
|
+
class audio_Audio extends APIResource {
|
3789
3898
|
constructor(...args){
|
3790
3899
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3791
3900
|
}
|
3792
3901
|
}
|
3793
|
-
|
3794
|
-
|
3902
|
+
class Templates extends APIResource {
|
3903
|
+
/**
|
3904
|
+
* Duplicate a template. | 复制一个模板。
|
3905
|
+
* @param templateId - Required. The ID of the template to duplicate. | 要复制的模板的 ID。
|
3906
|
+
* @param params - Optional. The parameters for the duplicate operation. | 可选参数,用于复制操作。
|
3907
|
+
* @param params.workspace_id - Required. The ID of the workspace to duplicate the template into. | 要复制到的目标工作空间的 ID。
|
3908
|
+
* @param params.name - Optional. The name of the new template. | 新模板的名称。
|
3909
|
+
* @returns TemplateDuplicateRes | 复制模板结果
|
3910
|
+
*/ async duplicate(templateId, params, options) {
|
3911
|
+
const apiUrl = `/v1/templates/${templateId}/duplicate`;
|
3912
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
3913
|
+
return response.data;
|
3914
|
+
}
|
3915
|
+
}
|
3916
|
+
// EXTERNAL MODULE: os (ignored)
|
3917
|
+
var os_ignored_ = __webpack_require__("?9050");
|
3918
|
+
var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
|
3919
|
+
var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16-alpha.2d8e39","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","exports":{".":"./src/index.ts"},"main":"src/index.ts","module":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.md","README.zh-CN.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"botPublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
|
3920
|
+
const { version: version_version } = package_namespaceObject;
|
3795
3921
|
const getEnv = ()=>{
|
3796
3922
|
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
3797
3923
|
const { platform } = process;
|
3798
3924
|
let osName = platform.toLowerCase();
|
3799
|
-
let osVersion =
|
3925
|
+
let osVersion = os_ignored_default().release();
|
3800
3926
|
if ('darwin' === platform) {
|
3801
3927
|
osName = 'macos';
|
3802
3928
|
// Try to parse the macOS version
|
3803
3929
|
try {
|
3804
|
-
const darwinVersion =
|
3930
|
+
const darwinVersion = os_ignored_default().release().split('.');
|
3805
3931
|
if (darwinVersion.length >= 2) {
|
3806
3932
|
const majorVersion = parseInt(darwinVersion[0], 10);
|
3807
3933
|
if (!isNaN(majorVersion) && majorVersion >= 9) {
|
@@ -3814,10 +3940,10 @@ const getEnv = ()=>{
|
|
3814
3940
|
}
|
3815
3941
|
} else if ('win32' === platform) {
|
3816
3942
|
osName = 'windows';
|
3817
|
-
osVersion =
|
3943
|
+
osVersion = os_ignored_default().release();
|
3818
3944
|
} else if ('linux' === platform) {
|
3819
3945
|
osName = 'linux';
|
3820
|
-
osVersion =
|
3946
|
+
osVersion = os_ignored_default().release();
|
3821
3947
|
}
|
3822
3948
|
return {
|
3823
3949
|
osName,
|
@@ -3827,12 +3953,12 @@ const getEnv = ()=>{
|
|
3827
3953
|
};
|
3828
3954
|
const getUserAgent = ()=>{
|
3829
3955
|
const { nodeVersion, osName, osVersion } = getEnv();
|
3830
|
-
return `coze-js/${
|
3956
|
+
return `coze-js/${version_version} node/${nodeVersion} ${osName}/${osVersion}`.toLowerCase();
|
3831
3957
|
};
|
3832
3958
|
const getNodeClientUserAgent = ()=>{
|
3833
3959
|
const { osVersion, nodeVersion, osName } = getEnv();
|
3834
3960
|
const ua = {
|
3835
|
-
version:
|
3961
|
+
version: version_version,
|
3836
3962
|
lang: 'node',
|
3837
3963
|
lang_version: nodeVersion,
|
3838
3964
|
os_name: osName,
|
@@ -3840,15 +3966,66 @@ const getNodeClientUserAgent = ()=>{
|
|
3840
3966
|
};
|
3841
3967
|
return JSON.stringify(ua);
|
3842
3968
|
};
|
3843
|
-
|
3969
|
+
const getBrowserClientUserAgent = ()=>{
|
3970
|
+
const browserInfo = {
|
3971
|
+
name: 'unknown',
|
3972
|
+
version: 'unknown'
|
3973
|
+
};
|
3974
|
+
const osInfo = {
|
3975
|
+
name: 'unknown',
|
3976
|
+
version: 'unknown'
|
3977
|
+
};
|
3978
|
+
const { userAgent } = navigator;
|
3979
|
+
// 检测操作系统及版本
|
3980
|
+
if (userAgent.indexOf('Windows') > -1) {
|
3981
|
+
var _userAgent_match;
|
3982
|
+
osInfo.name = 'windows';
|
3983
|
+
const windowsVersion = (null === (_userAgent_match = userAgent.match(/Windows NT ([0-9.]+)/)) || void 0 === _userAgent_match ? void 0 : _userAgent_match[1]) || 'unknown';
|
3984
|
+
osInfo.version = windowsVersion;
|
3985
|
+
} else if (userAgent.indexOf('Mac OS X') > -1) {
|
3986
|
+
var _userAgent_match1;
|
3987
|
+
osInfo.name = 'macos';
|
3988
|
+
// 将 10_15_7 格式转换为 10.15.7
|
3989
|
+
osInfo.version = ((null === (_userAgent_match1 = userAgent.match(/Mac OS X ([0-9_]+)/)) || void 0 === _userAgent_match1 ? void 0 : _userAgent_match1[1]) || 'unknown').replace(/_/g, '.');
|
3990
|
+
} else if (userAgent.indexOf('Linux') > -1) {
|
3991
|
+
var _userAgent_match2;
|
3992
|
+
osInfo.name = 'linux';
|
3993
|
+
osInfo.version = (null === (_userAgent_match2 = userAgent.match(/Linux ([0-9.]+)/)) || void 0 === _userAgent_match2 ? void 0 : _userAgent_match2[1]) || 'unknown';
|
3994
|
+
}
|
3995
|
+
// 检测浏览器及版本
|
3996
|
+
if (userAgent.indexOf('Chrome') > -1) {
|
3997
|
+
var _userAgent_match3;
|
3998
|
+
browserInfo.name = 'chrome';
|
3999
|
+
browserInfo.version = (null === (_userAgent_match3 = userAgent.match(/Chrome\/([0-9.]+)/)) || void 0 === _userAgent_match3 ? void 0 : _userAgent_match3[1]) || 'unknown';
|
4000
|
+
} else if (userAgent.indexOf('Firefox') > -1) {
|
4001
|
+
var _userAgent_match4;
|
4002
|
+
browserInfo.name = 'firefox';
|
4003
|
+
browserInfo.version = (null === (_userAgent_match4 = userAgent.match(/Firefox\/([0-9.]+)/)) || void 0 === _userAgent_match4 ? void 0 : _userAgent_match4[1]) || 'unknown';
|
4004
|
+
} else if (userAgent.indexOf('Safari') > -1) {
|
4005
|
+
var _userAgent_match5;
|
4006
|
+
browserInfo.name = 'safari';
|
4007
|
+
browserInfo.version = (null === (_userAgent_match5 = userAgent.match(/Version\/([0-9.]+)/)) || void 0 === _userAgent_match5 ? void 0 : _userAgent_match5[1]) || 'unknown';
|
4008
|
+
}
|
4009
|
+
const ua = {
|
4010
|
+
version: version_version,
|
4011
|
+
browser: browserInfo.name,
|
4012
|
+
browser_version: browserInfo.version,
|
4013
|
+
os_name: osInfo.name,
|
4014
|
+
os_version: osInfo.version
|
4015
|
+
};
|
4016
|
+
return JSON.stringify(ua);
|
4017
|
+
};
|
4018
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
|
3844
4019
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3845
4020
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
3846
4021
|
var _error_response;
|
3847
4022
|
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);
|
3848
4023
|
}
|
3849
4024
|
if ('ERR_CANCELED' === error.code) return new APIUserAbortError(error.message);
|
3850
|
-
|
3851
|
-
|
4025
|
+
else {
|
4026
|
+
var _error_response1, _error_response2, _error_response3;
|
4027
|
+
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);
|
4028
|
+
}
|
3852
4029
|
};
|
3853
4030
|
async function fetchAPI(url) {
|
3854
4031
|
let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
|
@@ -3864,7 +4041,7 @@ async function fetchAPI(url) {
|
|
3864
4041
|
adapter: options.isStreaming ? 'fetch' : void 0,
|
3865
4042
|
...options
|
3866
4043
|
}).catch((error)=>{
|
3867
|
-
throw
|
4044
|
+
throw fetcher_handleError(error);
|
3868
4045
|
});
|
3869
4046
|
return {
|
3870
4047
|
async *stream () {
|
@@ -3902,7 +4079,7 @@ async function fetchAPI(url) {
|
|
3902
4079
|
buffer = lines[lines.length - 1]; // Keep the last incomplete line in the buffer
|
3903
4080
|
}
|
3904
4081
|
} catch (error) {
|
3905
|
-
|
4082
|
+
fetcher_handleError(error);
|
3906
4083
|
}
|
3907
4084
|
},
|
3908
4085
|
json: ()=>response.data,
|
@@ -3926,8 +4103,8 @@ function isAxiosStatic(instance) {
|
|
3926
4103
|
}
|
3927
4104
|
/**
|
3928
4105
|
* default coze base URL is api.coze.com
|
3929
|
-
*/ const
|
3930
|
-
/* eslint-disable max-params */ class
|
4106
|
+
*/ const constant_COZE_COM_BASE_URL = 'https://api.coze.com';
|
4107
|
+
/* eslint-disable max-params */ class core_APIClient {
|
3931
4108
|
async getToken() {
|
3932
4109
|
if ('function' == typeof this.token) return await this.token();
|
3933
4110
|
return this.token;
|
@@ -3937,11 +4114,12 @@ function isAxiosStatic(instance) {
|
|
3937
4114
|
const headers = {
|
3938
4115
|
authorization: `Bearer ${token}`
|
3939
4116
|
};
|
3940
|
-
if (
|
4117
|
+
if (utils_isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
|
4118
|
+
else {
|
3941
4119
|
headers['User-Agent'] = getUserAgent();
|
3942
4120
|
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
3943
4121
|
}
|
3944
|
-
const config =
|
4122
|
+
const config = mergeConfig(this.axiosOptions, options, {
|
3945
4123
|
headers
|
3946
4124
|
});
|
3947
4125
|
config.method = method;
|
@@ -3965,7 +4143,7 @@ function isAxiosStatic(instance) {
|
|
3965
4143
|
if (contentType && contentType.includes('application/json')) {
|
3966
4144
|
const result = await json();
|
3967
4145
|
const { code, msg } = result;
|
3968
|
-
if (0 !== code && void 0 !== code) throw
|
4146
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3969
4147
|
}
|
3970
4148
|
return stream();
|
3971
4149
|
}
|
@@ -3973,7 +4151,7 @@ function isAxiosStatic(instance) {
|
|
3973
4151
|
{
|
3974
4152
|
const result = await json();
|
3975
4153
|
const { code, msg } = result;
|
3976
|
-
if (0 !== code && void 0 !== code) throw
|
4154
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3977
4155
|
return result;
|
3978
4156
|
}
|
3979
4157
|
}
|
@@ -4005,31 +4183,35 @@ function isAxiosStatic(instance) {
|
|
4005
4183
|
}
|
4006
4184
|
constructor(config){
|
4007
4185
|
this._config = config;
|
4008
|
-
this.baseURL = config.baseURL ||
|
4186
|
+
this.baseURL = config.baseURL || constant_COZE_COM_BASE_URL;
|
4009
4187
|
this.token = config.token;
|
4010
4188
|
this.axiosOptions = config.axiosOptions || {};
|
4011
4189
|
this.axiosInstance = config.axiosInstance;
|
4012
4190
|
this.debug = config.debug || false;
|
4013
4191
|
this.allowPersonalAccessTokenInBrowser = config.allowPersonalAccessTokenInBrowser || false;
|
4014
4192
|
this.headers = config.headers;
|
4015
|
-
if (
|
4016
|
-
}
|
4017
|
-
}
|
4018
|
-
|
4019
|
-
|
4020
|
-
|
4021
|
-
|
4022
|
-
|
4023
|
-
|
4024
|
-
|
4025
|
-
|
4026
|
-
|
4027
|
-
|
4028
|
-
|
4193
|
+
if (utils_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');
|
4194
|
+
}
|
4195
|
+
}
|
4196
|
+
core_APIClient.APIError = error_APIError;
|
4197
|
+
core_APIClient.BadRequestError = BadRequestError;
|
4198
|
+
core_APIClient.AuthenticationError = AuthenticationError;
|
4199
|
+
core_APIClient.PermissionDeniedError = PermissionDeniedError;
|
4200
|
+
core_APIClient.NotFoundError = NotFoundError;
|
4201
|
+
core_APIClient.RateLimitError = RateLimitError;
|
4202
|
+
core_APIClient.InternalServerError = InternalServerError;
|
4203
|
+
core_APIClient.GatewayError = GatewayError;
|
4204
|
+
core_APIClient.TimeoutError = TimeoutError;
|
4205
|
+
core_APIClient.UserAbortError = APIUserAbortError;
|
4206
|
+
// EXTERNAL MODULE: crypto (ignored)
|
4207
|
+
__webpack_require__("?666e");
|
4208
|
+
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
4209
|
+
__webpack_require__("?79fd");
|
4210
|
+
class CozeAPI extends core_APIClient {
|
4029
4211
|
constructor(...args){
|
4030
4212
|
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4031
4213
|
* @deprecated
|
4032
|
-
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new
|
4214
|
+
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new audio_Audio(this), this.templates = new Templates(this);
|
4033
4215
|
}
|
4034
4216
|
}
|
4035
4217
|
/**
|
@@ -9261,7 +9443,7 @@ var setPrototypeOf = setPrototypeOf$2, _Object$setPrototypeOf = getDefaultExport
|
|
9261
9443
|
}, stringPad = {
|
9262
9444
|
start: createMethod(!1),
|
9263
9445
|
end: createMethod(!0)
|
9264
|
-
},
|
9446
|
+
}, index_esm_min_userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(index_esm_min_userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
|
9265
9447
|
$$F({
|
9266
9448
|
target: "String",
|
9267
9449
|
proto: !0,
|
@@ -38414,7 +38596,7 @@ var VERTC = _createClass(function e() {
|
|
38414
38596
|
+ * @param milliseconds The time to sleep in milliseconds
|
38415
38597
|
+ * @throws {Error} If milliseconds is negative
|
38416
38598
|
+ * @returns Promise that resolves after the specified duration
|
38417
|
-
+ */ const
|
38599
|
+
+ */ const src_utils_sleep = (milliseconds)=>{
|
38418
38600
|
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
38419
38601
|
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
38420
38602
|
};
|
@@ -38434,7 +38616,11 @@ var VERTC = _createClass(function e() {
|
|
38434
38616
|
return false;
|
38435
38617
|
}
|
38436
38618
|
};
|
38437
|
-
|
38619
|
+
/**
|
38620
|
+
* Checks device permissions for audio and video
|
38621
|
+
* @param checkVideo Whether to check video permissions (default: false)
|
38622
|
+
* @returns Promise that resolves with the device permission status
|
38623
|
+
*/ const checkDevicePermission = async function() {
|
38438
38624
|
let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
|
38439
38625
|
return await index_esm_min_index.enableDevices({
|
38440
38626
|
audio: true,
|
@@ -38447,7 +38633,16 @@ const checkDevicePermission = async function() {
|
|
38447
38633
|
*/ const getAudioDevices = async function() {
|
38448
38634
|
let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
38449
38635
|
let devices = [];
|
38450
|
-
|
38636
|
+
if (video) {
|
38637
|
+
devices = await index_esm_min_index.enumerateDevices();
|
38638
|
+
if (isScreenShareSupported()) // @ts-expect-error - add screenShare device to devices
|
38639
|
+
devices.push({
|
38640
|
+
deviceId: 'screenShare',
|
38641
|
+
kind: 'videoinput',
|
38642
|
+
label: 'Screen Share',
|
38643
|
+
groupId: 'screenShare'
|
38644
|
+
});
|
38645
|
+
} else devices = await [
|
38451
38646
|
...await index_esm_min_index.enumerateAudioCaptureDevices(),
|
38452
38647
|
...await index_esm_min_index.enumerateAudioPlaybackDevices()
|
38453
38648
|
];
|
@@ -38462,6 +38657,14 @@ const checkDevicePermission = async function() {
|
|
38462
38657
|
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
38463
38658
|
};
|
38464
38659
|
};
|
38660
|
+
const isScreenShareDevice = (deviceId)=>'screenShare' === deviceId;
|
38661
|
+
/**
|
38662
|
+
* Check if browser supports screen sharing
|
38663
|
+
* 检查浏览器是否支持屏幕共享
|
38664
|
+
*/ function isScreenShareSupported() {
|
38665
|
+
var _navigator_mediaDevices, _navigator;
|
38666
|
+
return !!(null === (_navigator = navigator) || void 0 === _navigator ? void 0 : null === (_navigator_mediaDevices = _navigator.mediaDevices) || void 0 === _navigator_mediaDevices ? void 0 : _navigator_mediaDevices.getDisplayMedia);
|
38667
|
+
}
|
38465
38668
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
38466
38669
|
RealtimeError["DEVICE_ACCESS_ERROR"] = "DEVICE_ACCESS_ERROR";
|
38467
38670
|
RealtimeError["STREAM_CREATION_ERROR"] = "STREAM_CREATION_ERROR";
|
@@ -38555,6 +38758,10 @@ var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
|
|
38555
38758
|
* zh: 音频输出设备改变
|
38556
38759
|
*/ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
38557
38760
|
/**
|
38761
|
+
* en: Video input device changed
|
38762
|
+
* zh: 视频输入设备改变
|
38763
|
+
*/ EventNames["VIDEO_INPUT_DEVICE_CHANGED"] = "client.video.input.device.changed";
|
38764
|
+
/**
|
38558
38765
|
* en: Bot joined
|
38559
38766
|
* zh: Bot 加入
|
38560
38767
|
*/ EventNames["BOT_JOIN"] = "server.bot.join";
|
@@ -41972,23 +42179,47 @@ class EngineClient extends RealtimeEventHandler {
|
|
41972
42179
|
if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
|
41973
42180
|
await this.engine.setAudioPlaybackDevice(deviceId);
|
41974
42181
|
}
|
42182
|
+
async setVideoInputDevice(deviceId) {
|
42183
|
+
let isAutoCapture = !(arguments.length > 1) || void 0 === arguments[1] || arguments[1];
|
42184
|
+
var _this__videoConfig;
|
42185
|
+
const devices = await getAudioDevices({
|
42186
|
+
video: true
|
42187
|
+
});
|
42188
|
+
if (-1 === devices.videoInputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Video input device not found: ${deviceId}`);
|
42189
|
+
await this.changeVideoState(false);
|
42190
|
+
if (isScreenShareDevice(deviceId)) {
|
42191
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN);
|
42192
|
+
if (isAutoCapture) {
|
42193
|
+
var _this__videoConfig1;
|
42194
|
+
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42195
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
|
42196
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42197
|
+
}
|
42198
|
+
this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
|
42199
|
+
} else {
|
42200
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_SCREEN) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_SCREEN);
|
42201
|
+
if (isAutoCapture) await this.engine.startVideoCapture(deviceId);
|
42202
|
+
this._streamIndex = StreamIndex$1.STREAM_INDEX_MAIN;
|
42203
|
+
}
|
42204
|
+
this.engine.setLocalVideoPlayer(this._streamIndex, {
|
42205
|
+
renderDom: (null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.renderDom) || 'local-player',
|
42206
|
+
userId: this._roomUserId
|
42207
|
+
});
|
42208
|
+
}
|
41975
42209
|
async createLocalStream(userId, videoConfig) {
|
42210
|
+
this._roomUserId = userId;
|
41976
42211
|
const devices = await getAudioDevices({
|
41977
42212
|
video: this._isSupportVideo
|
41978
42213
|
});
|
41979
42214
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
41980
42215
|
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
41981
42216
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
41982
|
-
if (this._isSupportVideo
|
41983
|
-
if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
|
41984
|
-
renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
|
41985
|
-
userId
|
41986
|
-
});
|
42217
|
+
if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
41987
42218
|
}
|
41988
42219
|
async disconnect() {
|
41989
42220
|
try {
|
41990
|
-
if (this._isSupportVideo) await this.
|
41991
|
-
await this.
|
42221
|
+
if (this._isSupportVideo) await this.changeVideoState(false);
|
42222
|
+
await this.changeAudioState(false);
|
41992
42223
|
await this.engine.unpublishStream(MediaType$1.AUDIO);
|
41993
42224
|
await this.engine.leaveRoom();
|
41994
42225
|
this.removeEventListener();
|
@@ -42008,8 +42239,19 @@ class EngineClient extends RealtimeEventHandler {
|
|
42008
42239
|
}
|
42009
42240
|
async changeVideoState(isVideoOn) {
|
42010
42241
|
try {
|
42011
|
-
if (isVideoOn)
|
42012
|
-
|
42242
|
+
if (isVideoOn) {
|
42243
|
+
if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.startVideoCapture();
|
42244
|
+
else {
|
42245
|
+
var _this__videoConfig;
|
42246
|
+
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42247
|
+
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
42248
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42249
|
+
}
|
42250
|
+
} else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
42251
|
+
else {
|
42252
|
+
await this.engine.stopScreenCapture();
|
42253
|
+
await this.engine.unpublishScreen(MediaType$1.VIDEO);
|
42254
|
+
}
|
42013
42255
|
} catch (e) {
|
42014
42256
|
this.dispatch(event_handler_EventNames.ERROR, e);
|
42015
42257
|
throw e;
|
@@ -42087,7 +42329,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42087
42329
|
}
|
42088
42330
|
}
|
42089
42331
|
// eslint-disable-next-line max-params
|
42090
|
-
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
|
42332
|
+
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false, videoConfig){
|
42091
42333
|
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
42092
42334
|
if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
42093
42335
|
'rtc-test.bytedance.com'
|
@@ -42102,6 +42344,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42102
42344
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
42103
42345
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
42104
42346
|
this._isSupportVideo = isSupportVideo;
|
42347
|
+
this._videoConfig = videoConfig;
|
42105
42348
|
}
|
42106
42349
|
}
|
42107
42350
|
class RealtimeClient extends RealtimeEventHandler {
|
@@ -42126,7 +42369,7 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42126
42369
|
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
42127
42370
|
}
|
42128
42371
|
// Step2 create engine
|
42129
|
-
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
|
42372
|
+
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo, this._config.videoConfig);
|
42130
42373
|
// Step3 bind engine events
|
42131
42374
|
this._client.bindEngineEvents();
|
42132
42375
|
this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
|
@@ -42262,6 +42505,13 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42262
42505
|
deviceId
|
42263
42506
|
});
|
42264
42507
|
}
|
42508
|
+
async setVideoInputDevice(deviceId) {
|
42509
|
+
var _this__client;
|
42510
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.setVideoInputDevice(deviceId));
|
42511
|
+
this.dispatch(event_handler_EventNames.VIDEO_INPUT_DEVICE_CHANGED, {
|
42512
|
+
deviceId
|
42513
|
+
});
|
42514
|
+
}
|
42265
42515
|
/**
|
42266
42516
|
* Constructor for initializing a RealtimeClient instance.
|
42267
42517
|
*
|
@@ -42292,6 +42542,16 @@ class RealtimeClient extends RealtimeEventHandler {
|
|
42292
42542
|
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
42293
42543
|
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
42294
42544
|
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
42545
|
+
* @param config.videoConfig - Optional, Video configuration. |
|
42546
|
+
* 可选,视频配置。
|
42547
|
+
* @param config.videoConfig.videoOnDefault - Optional, Whether to turn on video by default, defaults to true. |
|
42548
|
+
* 可选,默认是否开启视频,默认值为 true。
|
42549
|
+
* @param config.videoConfig.renderDom - Optional, The DOM element to render the video stream to. |
|
42550
|
+
* 可选,渲染视频流的 DOM 元素。
|
42551
|
+
* @param config.videoConfig.videoInputDeviceId - Optional, The device ID of the video input device to use. |
|
42552
|
+
* 可选,视频输入设备的设备 ID。
|
42553
|
+
* @param config.videoConfig.screenConfig - Optional, Screen share configuration if videoInputDeviceId is 'screenShare' see https://www.volcengine.com/docs/6348/104481#screenconfig for more details. |
|
42554
|
+
* 可选,屏幕共享配置,如果 videoInputDeviceId 是 'screenShare',请参考 https://www.volcengine.com/docs/6348/104481#screenconfig 了解更多详情。
|
42295
42555
|
*/ constructor(config){
|
42296
42556
|
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
42297
42557
|
this._config = config;
|