@coze/realtime-api 1.0.3-beta.7 → 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/dist/cjs/index.cjs +1503 -1418
- package/dist/esm/index.js +1503 -1418
- package/dist/umd/index.js +1503 -1418
- package/package.json +15 -8
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, {
|
@@ -92,480 +107,1041 @@ __webpack_require__.d(src_utils_namespaceObject, {
|
|
92
107
|
getAudioDevices: ()=>getAudioDevices,
|
93
108
|
isScreenShareDevice: ()=>isScreenShareDevice,
|
94
109
|
isScreenShareSupported: ()=>isScreenShareSupported,
|
95
|
-
sleep: ()=>
|
110
|
+
sleep: ()=>src_utils_sleep
|
96
111
|
});
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
112
|
+
class APIResource {
|
113
|
+
constructor(client){
|
114
|
+
this._client = client;
|
115
|
+
}
|
101
116
|
}
|
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
|
-
|
134
|
-
|
135
|
-
|
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
|
+
}
|
136
192
|
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
/**
|
145
|
-
* Determine if a value is a view on an ArrayBuffer
|
146
|
-
*
|
147
|
-
* @param {*} val The value to test
|
148
|
-
*
|
149
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
150
|
-
*/ function isArrayBufferView(val) {
|
151
|
-
let result;
|
152
|
-
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
153
|
-
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
|
+
}
|
154
200
|
}
|
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
|
-
|
201
|
-
*
|
202
|
-
* @param {*} val The value to test
|
203
|
-
*
|
204
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
205
|
-
*/ const isDate = kindOfTest('Date');
|
206
|
-
/**
|
207
|
-
* Determine if a value is a File
|
208
|
-
*
|
209
|
-
* @param {*} val The value to test
|
210
|
-
*
|
211
|
-
* @returns {boolean} True if value is a File, otherwise false
|
212
|
-
*/ const isFile = kindOfTest('File');
|
213
|
-
/**
|
214
|
-
* Determine if a value is a Blob
|
215
|
-
*
|
216
|
-
* @param {*} val The value to test
|
217
|
-
*
|
218
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
219
|
-
*/ const isBlob = kindOfTest('Blob');
|
220
|
-
/**
|
221
|
-
* Determine if a value is a FileList
|
222
|
-
*
|
223
|
-
* @param {*} val The value to test
|
224
|
-
*
|
225
|
-
* @returns {boolean} True if value is a File, otherwise false
|
226
|
-
*/ const utils_isFileList = kindOfTest('FileList');
|
227
|
-
/**
|
228
|
-
* Determine if a value is a Stream
|
229
|
-
*
|
230
|
-
* @param {*} val The value to test
|
231
|
-
*
|
232
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
233
|
-
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
234
|
-
/**
|
235
|
-
* Determine if a value is a FormData
|
236
|
-
*
|
237
|
-
* @param {*} thing The value to test
|
238
|
-
*
|
239
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
240
|
-
*/ const utils_isFormData = (thing)=>{
|
241
|
-
let kind;
|
242
|
-
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
243
|
-
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
244
|
-
};
|
245
|
-
/**
|
246
|
-
* Determine if a value is a URLSearchParams object
|
247
|
-
*
|
248
|
-
* @param {*} val The value to test
|
249
|
-
*
|
250
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
251
|
-
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
252
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
253
|
-
'ReadableStream',
|
254
|
-
'Request',
|
255
|
-
'Response',
|
256
|
-
'Headers'
|
257
|
-
].map(kindOfTest);
|
258
|
-
/**
|
259
|
-
* Trim excess whitespace off the beginning and end of a string
|
260
|
-
*
|
261
|
-
* @param {String} str The String to trim
|
262
|
-
*
|
263
|
-
* @returns {String} The String freed of excess whitespace
|
264
|
-
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
265
|
-
/**
|
266
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
267
|
-
*
|
268
|
-
* If `obj` is an Array callback will be called passing
|
269
|
-
* the value, index, and complete array for each item.
|
270
|
-
*
|
271
|
-
* If 'obj' is an Object callback will be called passing
|
272
|
-
* the value, key, and complete object for each property.
|
273
|
-
*
|
274
|
-
* @param {Object|Array} obj The object to iterate
|
275
|
-
* @param {Function} fn The callback to invoke for each item
|
276
|
-
*
|
277
|
-
* @param {Boolean} [allOwnKeys = false]
|
278
|
-
* @returns {any}
|
279
|
-
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
280
|
-
// Don't bother if no value provided
|
281
|
-
if (null == obj) return;
|
282
|
-
let i;
|
283
|
-
let l;
|
284
|
-
// Force an array if not already something iterable
|
285
|
-
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
286
|
-
obj
|
287
|
-
];
|
288
|
-
if (isArray(obj)) // Iterate over array values
|
289
|
-
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
290
|
-
else {
|
291
|
-
// Iterate over object keys
|
292
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
293
|
-
const len = keys.length;
|
294
|
-
let key;
|
295
|
-
for(i = 0; i < len; i++){
|
296
|
-
key = keys[i];
|
297
|
-
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(', ');
|
298
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;
|
299
279
|
}
|
300
280
|
}
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
_key = keys[i];
|
308
|
-
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
|
+
// }
|
309
287
|
}
|
310
|
-
return null;
|
311
288
|
}
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
}
|
316
|
-
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
317
|
-
/**
|
318
|
-
* Accepts varargs expecting each argument to be an object, then
|
319
|
-
* immutably merges the properties of each object and returns result.
|
320
|
-
*
|
321
|
-
* When multiple objects contain the same key the later object in
|
322
|
-
* the arguments list will take precedence.
|
323
|
-
*
|
324
|
-
* Example:
|
325
|
-
*
|
326
|
-
* ```js
|
327
|
-
* var result = merge({foo: 123}, {foo: 456});
|
328
|
-
* console.log(result.foo); // outputs 456
|
329
|
-
* ```
|
330
|
-
*
|
331
|
-
* @param {Object} obj1 Object to merge
|
332
|
-
*
|
333
|
-
* @returns {Object} Result of all merge properties
|
334
|
-
*/ function utils_merge() {
|
335
|
-
const { caseless } = isContextDefined(this) && this || {};
|
336
|
-
const result = {};
|
337
|
-
const assignValue = (val, key)=>{
|
338
|
-
const targetKey = caseless && findKey(result, key) || key;
|
339
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
340
|
-
else if (isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
341
|
-
else if (isArray(val)) result[targetKey] = val.slice();
|
342
|
-
else result[targetKey] = val;
|
343
|
-
};
|
344
|
-
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
345
|
-
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
|
+
}
|
346
293
|
}
|
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
|
-
|
388
|
-
|
389
|
-
|
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);
|
390
337
|
};
|
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
|
-
|
418
|
-
|
419
|
-
|
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;
|
420
688
|
};
|
689
|
+
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
421
690
|
/**
|
422
|
-
*
|
691
|
+
* Determine if a value is an Array
|
423
692
|
*
|
424
|
-
* @param {
|
425
|
-
* @param {String} searchString
|
426
|
-
* @param {Number} [position= 0]
|
693
|
+
* @param {Object} val The value to test
|
427
694
|
*
|
428
|
-
* @returns {boolean}
|
429
|
-
*/ const
|
430
|
-
str = String(str);
|
431
|
-
if (void 0 === position || position > str.length) position = str.length;
|
432
|
-
position -= searchString.length;
|
433
|
-
const lastIndex = str.indexOf(searchString, position);
|
434
|
-
return -1 !== lastIndex && lastIndex === position;
|
435
|
-
};
|
695
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
696
|
+
*/ const { isArray } = Array;
|
436
697
|
/**
|
437
|
-
*
|
698
|
+
* Determine if a value is undefined
|
438
699
|
*
|
439
|
-
* @param {*}
|
700
|
+
* @param {*} val The value to test
|
440
701
|
*
|
441
|
-
* @returns {
|
442
|
-
*/ const
|
443
|
-
if (!thing) return null;
|
444
|
-
if (isArray(thing)) return thing;
|
445
|
-
let i = thing.length;
|
446
|
-
if (!isNumber(i)) return null;
|
447
|
-
const arr = new Array(i);
|
448
|
-
while(i-- > 0)arr[i] = thing[i];
|
449
|
-
return arr;
|
450
|
-
};
|
702
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
703
|
+
*/ const isUndefined = typeOfTest('undefined');
|
451
704
|
/**
|
452
|
-
*
|
453
|
-
* thing passed in is an instance of Uint8Array
|
705
|
+
* Determine if a value is a Buffer
|
454
706
|
*
|
455
|
-
* @param {
|
707
|
+
* @param {*} val The value to test
|
456
708
|
*
|
457
|
-
* @returns {
|
458
|
-
*/
|
459
|
-
|
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
|
+
}
|
460
713
|
/**
|
461
|
-
*
|
714
|
+
* Determine if a value is an ArrayBuffer
|
462
715
|
*
|
463
|
-
* @param {
|
464
|
-
* @param {Function} fn - The function to call for each entry.
|
716
|
+
* @param {*} val The value to test
|
465
717
|
*
|
466
|
-
* @returns {
|
467
|
-
*/ const
|
468
|
-
const generator = obj && obj[Symbol.iterator];
|
469
|
-
const iterator = generator.call(obj);
|
470
|
-
let result;
|
471
|
-
while((result = iterator.next()) && !result.done){
|
472
|
-
const pair = result.value;
|
473
|
-
fn.call(obj, pair[0], pair[1]);
|
474
|
-
}
|
475
|
-
};
|
718
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
719
|
+
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
476
720
|
/**
|
477
|
-
*
|
721
|
+
* Determine if a value is a view on an ArrayBuffer
|
478
722
|
*
|
479
|
-
* @param {
|
480
|
-
* @param {string} str - The string to search.
|
723
|
+
* @param {*} val The value to test
|
481
724
|
*
|
482
|
-
* @returns {
|
483
|
-
*/
|
484
|
-
let
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
};
|
489
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
490
|
-
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
491
|
-
return p1.toUpperCase() + p2;
|
492
|
-
});
|
493
|
-
/* 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
|
+
}
|
494
731
|
/**
|
495
|
-
* Determine if a value is a
|
732
|
+
* Determine if a value is a String
|
496
733
|
*
|
497
734
|
* @param {*} val The value to test
|
498
735
|
*
|
499
|
-
* @returns {boolean} True if value is a
|
500
|
-
*/ const
|
501
|
-
const reduceDescriptors = (obj, reducer)=>{
|
502
|
-
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
503
|
-
const reducedDescriptors = {};
|
504
|
-
forEach(descriptors, (descriptor, name)=>{
|
505
|
-
let ret;
|
506
|
-
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
507
|
-
});
|
508
|
-
Object.defineProperties(obj, reducedDescriptors);
|
509
|
-
};
|
736
|
+
* @returns {boolean} True if value is a String, otherwise false
|
737
|
+
*/ const isString = typeOfTest('string');
|
510
738
|
/**
|
511
|
-
*
|
512
|
-
*
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
if (isFunction(obj) && -1 !== [
|
517
|
-
'arguments',
|
518
|
-
'caller',
|
519
|
-
'callee'
|
520
|
-
].indexOf(name)) return false;
|
521
|
-
const value = obj[name];
|
522
|
-
if (!isFunction(value)) return;
|
523
|
-
descriptor.enumerable = false;
|
524
|
-
if ('writable' in descriptor) {
|
525
|
-
descriptor.writable = false;
|
526
|
-
return;
|
527
|
-
}
|
528
|
-
if (!descriptor.set) descriptor.set = ()=>{
|
529
|
-
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
530
|
-
};
|
531
|
-
});
|
532
|
-
};
|
533
|
-
const toObjectSet = (arrayOrString, delimiter)=>{
|
534
|
-
const obj = {};
|
535
|
-
const define = (arr)=>{
|
536
|
-
arr.forEach((value)=>{
|
537
|
-
obj[value] = true;
|
538
|
-
});
|
539
|
-
};
|
540
|
-
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
541
|
-
return obj;
|
542
|
-
};
|
543
|
-
const noop = ()=>{};
|
544
|
-
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
545
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
546
|
-
const DIGIT = '0123456789';
|
547
|
-
const ALPHABET = {
|
548
|
-
DIGIT,
|
549
|
-
ALPHA,
|
550
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
551
|
-
};
|
552
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
553
|
-
let str = '';
|
554
|
-
const { length } = alphabet;
|
555
|
-
while(size--)str += alphabet[Math.random() * length | 0];
|
556
|
-
return str;
|
557
|
-
};
|
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');
|
558
744
|
/**
|
559
|
-
*
|
745
|
+
* Determine if a value is a Number
|
560
746
|
*
|
561
|
-
* @param {
|
747
|
+
* @param {*} val The value to test
|
562
748
|
*
|
563
|
-
* @returns {boolean}
|
564
|
-
*/
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
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);
|
569
1145
|
const visit = (source, i)=>{
|
570
1146
|
if (isObject(source)) {
|
571
1147
|
if (stack.indexOf(source) >= 0) return;
|
@@ -612,7 +1188,7 @@ const asap = 'undefined' != typeof queueMicrotask ? queueMicrotask.bind(_global)
|
|
612
1188
|
isNumber,
|
613
1189
|
isBoolean,
|
614
1190
|
isObject,
|
615
|
-
isPlainObject,
|
1191
|
+
isPlainObject: utils_isPlainObject,
|
616
1192
|
isReadableStream,
|
617
1193
|
isRequest,
|
618
1194
|
isResponse,
|
@@ -1810,7 +2386,7 @@ const headersToObject = (thing)=>thing instanceof AxiosHeaders ? {
|
|
1810
2386
|
* @param {Object} config2
|
1811
2387
|
*
|
1812
2388
|
* @returns {Object} New object resulting from merging config2 to config1
|
1813
|
-
*/ function
|
2389
|
+
*/ function mergeConfig_mergeConfig(config1, config2) {
|
1814
2390
|
// eslint-disable-next-line no-param-reassign
|
1815
2391
|
config2 = config2 || {};
|
1816
2392
|
const config = {};
|
@@ -1880,7 +2456,7 @@ const headersToObject = (thing)=>thing instanceof AxiosHeaders ? {
|
|
1880
2456
|
return config;
|
1881
2457
|
}
|
1882
2458
|
/* ESM default export */ const resolveConfig = (config)=>{
|
1883
|
-
const newConfig =
|
2459
|
+
const newConfig = mergeConfig_mergeConfig({}, config);
|
1884
2460
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
1885
2461
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
1886
2462
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
@@ -2486,946 +3062,379 @@ const Axios_validators = helpers_validator.validators;
|
|
2486
3062
|
config = config || {};
|
2487
3063
|
config.url = configOrUrl;
|
2488
3064
|
} else config = configOrUrl || {};
|
2489
|
-
config =
|
2490
|
-
const { transitional, paramsSerializer, headers } = config;
|
2491
|
-
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
2492
|
-
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
2493
|
-
forcedJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
2494
|
-
clarifyTimeoutError: Axios_validators.transitional(Axios_validators.boolean)
|
2495
|
-
}, false);
|
2496
|
-
if (null != paramsSerializer) {
|
2497
|
-
if (utils.isFunction(paramsSerializer)) config.paramsSerializer = {
|
2498
|
-
serialize: paramsSerializer
|
2499
|
-
};
|
2500
|
-
else helpers_validator.assertOptions(paramsSerializer, {
|
2501
|
-
encode: Axios_validators.function,
|
2502
|
-
serialize: Axios_validators.function
|
2503
|
-
}, true);
|
2504
|
-
}
|
2505
|
-
// Set config.method
|
2506
|
-
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
2507
|
-
// Flatten headers
|
2508
|
-
let contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
|
2509
|
-
headers && utils.forEach([
|
2510
|
-
'delete',
|
2511
|
-
'get',
|
2512
|
-
'head',
|
2513
|
-
'post',
|
2514
|
-
'put',
|
2515
|
-
'patch',
|
2516
|
-
'common'
|
2517
|
-
], (method)=>{
|
2518
|
-
delete headers[method];
|
2519
|
-
});
|
2520
|
-
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
2521
|
-
// filter out skipped interceptors
|
2522
|
-
const requestInterceptorChain = [];
|
2523
|
-
let synchronousRequestInterceptors = true;
|
2524
|
-
this.interceptors.request.forEach(function(interceptor) {
|
2525
|
-
if ('function' == typeof interceptor.runWhen && false === interceptor.runWhen(config)) return;
|
2526
|
-
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
2527
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
2528
|
-
});
|
2529
|
-
const responseInterceptorChain = [];
|
2530
|
-
this.interceptors.response.forEach(function(interceptor) {
|
2531
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
2532
|
-
});
|
2533
|
-
let promise;
|
2534
|
-
let i = 0;
|
2535
|
-
let len;
|
2536
|
-
if (!synchronousRequestInterceptors) {
|
2537
|
-
const chain = [
|
2538
|
-
dispatchRequest.bind(this),
|
2539
|
-
void 0
|
2540
|
-
];
|
2541
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
2542
|
-
chain.push.apply(chain, responseInterceptorChain);
|
2543
|
-
len = chain.length;
|
2544
|
-
promise = Promise.resolve(config);
|
2545
|
-
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
2546
|
-
return promise;
|
2547
|
-
}
|
2548
|
-
len = requestInterceptorChain.length;
|
2549
|
-
let newConfig = config;
|
2550
|
-
i = 0;
|
2551
|
-
while(i < len){
|
2552
|
-
const onFulfilled = requestInterceptorChain[i++];
|
2553
|
-
const onRejected = requestInterceptorChain[i++];
|
2554
|
-
try {
|
2555
|
-
newConfig = onFulfilled(newConfig);
|
2556
|
-
} catch (error) {
|
2557
|
-
onRejected.call(this, error);
|
2558
|
-
break;
|
2559
|
-
}
|
2560
|
-
}
|
2561
|
-
try {
|
2562
|
-
promise = dispatchRequest.call(this, newConfig);
|
2563
|
-
} catch (error) {
|
2564
|
-
return Promise.reject(error);
|
2565
|
-
}
|
2566
|
-
i = 0;
|
2567
|
-
len = responseInterceptorChain.length;
|
2568
|
-
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
2569
|
-
return promise;
|
2570
|
-
}
|
2571
|
-
getUri(config) {
|
2572
|
-
config = mergeConfig(this.defaults, config);
|
2573
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2574
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2575
|
-
}
|
2576
|
-
}
|
2577
|
-
// Provide aliases for supported request methods
|
2578
|
-
utils.forEach([
|
2579
|
-
'delete',
|
2580
|
-
'get',
|
2581
|
-
'head',
|
2582
|
-
'options'
|
2583
|
-
], function(method) {
|
2584
|
-
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
2585
|
-
return this.request(mergeConfig(config || {}, {
|
2586
|
-
method,
|
2587
|
-
url,
|
2588
|
-
data: (config || {}).data
|
2589
|
-
}));
|
2590
|
-
};
|
2591
|
-
});
|
2592
|
-
utils.forEach([
|
2593
|
-
'post',
|
2594
|
-
'put',
|
2595
|
-
'patch'
|
2596
|
-
], function(method) {
|
2597
|
-
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
2598
|
-
return function(url, data, config) {
|
2599
|
-
return this.request(mergeConfig(config || {}, {
|
2600
|
-
method,
|
2601
|
-
headers: isForm ? {
|
2602
|
-
'Content-Type': 'multipart/form-data'
|
2603
|
-
} : {},
|
2604
|
-
url,
|
2605
|
-
data
|
2606
|
-
}));
|
2607
|
-
};
|
2608
|
-
}
|
2609
|
-
Axios_Axios.prototype[method] = generateHTTPMethod();
|
2610
|
-
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2611
|
-
});
|
2612
|
-
/* ESM default export */ const Axios = Axios_Axios;
|
2613
|
-
/**
|
2614
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2615
|
-
*
|
2616
|
-
* @param {Function} executor The executor function.
|
2617
|
-
*
|
2618
|
-
* @returns {CancelToken}
|
2619
|
-
*/ class CancelToken_CancelToken {
|
2620
|
-
constructor(executor){
|
2621
|
-
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
2622
|
-
let resolvePromise;
|
2623
|
-
this.promise = new Promise(function(resolve) {
|
2624
|
-
resolvePromise = resolve;
|
2625
|
-
});
|
2626
|
-
const token = this;
|
2627
|
-
// eslint-disable-next-line func-names
|
2628
|
-
this.promise.then((cancel)=>{
|
2629
|
-
if (!token._listeners) return;
|
2630
|
-
let i = token._listeners.length;
|
2631
|
-
while(i-- > 0)token._listeners[i](cancel);
|
2632
|
-
token._listeners = null;
|
2633
|
-
});
|
2634
|
-
// eslint-disable-next-line func-names
|
2635
|
-
this.promise.then = (onfulfilled)=>{
|
2636
|
-
let _resolve;
|
2637
|
-
// eslint-disable-next-line func-names
|
2638
|
-
const promise = new Promise((resolve)=>{
|
2639
|
-
token.subscribe(resolve);
|
2640
|
-
_resolve = resolve;
|
2641
|
-
}).then(onfulfilled);
|
2642
|
-
promise.cancel = function() {
|
2643
|
-
token.unsubscribe(_resolve);
|
2644
|
-
};
|
2645
|
-
return promise;
|
2646
|
-
};
|
2647
|
-
executor(function(message, config, request) {
|
2648
|
-
if (token.reason) // Cancellation has already been requested
|
2649
|
-
return;
|
2650
|
-
token.reason = new CanceledError(message, config, request);
|
2651
|
-
resolvePromise(token.reason);
|
2652
|
-
});
|
2653
|
-
}
|
2654
|
-
/**
|
2655
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2656
|
-
*/ throwIfRequested() {
|
2657
|
-
if (this.reason) throw this.reason;
|
2658
|
-
}
|
2659
|
-
/**
|
2660
|
-
* Subscribe to the cancel signal
|
2661
|
-
*/ subscribe(listener) {
|
2662
|
-
if (this.reason) {
|
2663
|
-
listener(this.reason);
|
2664
|
-
return;
|
2665
|
-
}
|
2666
|
-
if (this._listeners) this._listeners.push(listener);
|
2667
|
-
else this._listeners = [
|
2668
|
-
listener
|
2669
|
-
];
|
2670
|
-
}
|
2671
|
-
/**
|
2672
|
-
* Unsubscribe from the cancel signal
|
2673
|
-
*/ unsubscribe(listener) {
|
2674
|
-
if (!this._listeners) return;
|
2675
|
-
const index = this._listeners.indexOf(listener);
|
2676
|
-
if (-1 !== index) this._listeners.splice(index, 1);
|
2677
|
-
}
|
2678
|
-
toAbortSignal() {
|
2679
|
-
const controller = new AbortController();
|
2680
|
-
const abort = (err)=>{
|
2681
|
-
controller.abort(err);
|
2682
|
-
};
|
2683
|
-
this.subscribe(abort);
|
2684
|
-
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
2685
|
-
return controller.signal;
|
2686
|
-
}
|
2687
|
-
/**
|
2688
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2689
|
-
* cancels the `CancelToken`.
|
2690
|
-
*/ static source() {
|
2691
|
-
let cancel;
|
2692
|
-
const token = new CancelToken_CancelToken(function(c) {
|
2693
|
-
cancel = c;
|
2694
|
-
});
|
2695
|
-
return {
|
2696
|
-
token,
|
2697
|
-
cancel
|
2698
|
-
};
|
2699
|
-
}
|
2700
|
-
}
|
2701
|
-
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
2702
|
-
/**
|
2703
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2704
|
-
*
|
2705
|
-
* Common use case would be to use `Function.prototype.apply`.
|
2706
|
-
*
|
2707
|
-
* ```js
|
2708
|
-
* function f(x, y, z) {}
|
2709
|
-
* var args = [1, 2, 3];
|
2710
|
-
* f.apply(null, args);
|
2711
|
-
* ```
|
2712
|
-
*
|
2713
|
-
* With `spread` this example can be re-written.
|
2714
|
-
*
|
2715
|
-
* ```js
|
2716
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
2717
|
-
* ```
|
2718
|
-
*
|
2719
|
-
* @param {Function} callback
|
2720
|
-
*
|
2721
|
-
* @returns {Function}
|
2722
|
-
*/ function spread(callback) {
|
2723
|
-
return function(arr) {
|
2724
|
-
return callback.apply(null, arr);
|
2725
|
-
};
|
2726
|
-
}
|
2727
|
-
/**
|
2728
|
-
* Determines whether the payload is an error thrown by Axios
|
2729
|
-
*
|
2730
|
-
* @param {*} payload The value to test
|
2731
|
-
*
|
2732
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2733
|
-
*/ function isAxiosError(payload) {
|
2734
|
-
return utils.isObject(payload) && true === payload.isAxiosError;
|
2735
|
-
}
|
2736
|
-
const HttpStatusCode = {
|
2737
|
-
Continue: 100,
|
2738
|
-
SwitchingProtocols: 101,
|
2739
|
-
Processing: 102,
|
2740
|
-
EarlyHints: 103,
|
2741
|
-
Ok: 200,
|
2742
|
-
Created: 201,
|
2743
|
-
Accepted: 202,
|
2744
|
-
NonAuthoritativeInformation: 203,
|
2745
|
-
NoContent: 204,
|
2746
|
-
ResetContent: 205,
|
2747
|
-
PartialContent: 206,
|
2748
|
-
MultiStatus: 207,
|
2749
|
-
AlreadyReported: 208,
|
2750
|
-
ImUsed: 226,
|
2751
|
-
MultipleChoices: 300,
|
2752
|
-
MovedPermanently: 301,
|
2753
|
-
Found: 302,
|
2754
|
-
SeeOther: 303,
|
2755
|
-
NotModified: 304,
|
2756
|
-
UseProxy: 305,
|
2757
|
-
Unused: 306,
|
2758
|
-
TemporaryRedirect: 307,
|
2759
|
-
PermanentRedirect: 308,
|
2760
|
-
BadRequest: 400,
|
2761
|
-
Unauthorized: 401,
|
2762
|
-
PaymentRequired: 402,
|
2763
|
-
Forbidden: 403,
|
2764
|
-
NotFound: 404,
|
2765
|
-
MethodNotAllowed: 405,
|
2766
|
-
NotAcceptable: 406,
|
2767
|
-
ProxyAuthenticationRequired: 407,
|
2768
|
-
RequestTimeout: 408,
|
2769
|
-
Conflict: 409,
|
2770
|
-
Gone: 410,
|
2771
|
-
LengthRequired: 411,
|
2772
|
-
PreconditionFailed: 412,
|
2773
|
-
PayloadTooLarge: 413,
|
2774
|
-
UriTooLong: 414,
|
2775
|
-
UnsupportedMediaType: 415,
|
2776
|
-
RangeNotSatisfiable: 416,
|
2777
|
-
ExpectationFailed: 417,
|
2778
|
-
ImATeapot: 418,
|
2779
|
-
MisdirectedRequest: 421,
|
2780
|
-
UnprocessableEntity: 422,
|
2781
|
-
Locked: 423,
|
2782
|
-
FailedDependency: 424,
|
2783
|
-
TooEarly: 425,
|
2784
|
-
UpgradeRequired: 426,
|
2785
|
-
PreconditionRequired: 428,
|
2786
|
-
TooManyRequests: 429,
|
2787
|
-
RequestHeaderFieldsTooLarge: 431,
|
2788
|
-
UnavailableForLegalReasons: 451,
|
2789
|
-
InternalServerError: 500,
|
2790
|
-
NotImplemented: 501,
|
2791
|
-
BadGateway: 502,
|
2792
|
-
ServiceUnavailable: 503,
|
2793
|
-
GatewayTimeout: 504,
|
2794
|
-
HttpVersionNotSupported: 505,
|
2795
|
-
VariantAlsoNegotiates: 506,
|
2796
|
-
InsufficientStorage: 507,
|
2797
|
-
LoopDetected: 508,
|
2798
|
-
NotExtended: 510,
|
2799
|
-
NetworkAuthenticationRequired: 511
|
2800
|
-
};
|
2801
|
-
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
2802
|
-
HttpStatusCode[value] = key;
|
2803
|
-
});
|
2804
|
-
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
2805
|
-
/**
|
2806
|
-
* Create an instance of Axios
|
2807
|
-
*
|
2808
|
-
* @param {Object} defaultConfig The default config for the instance
|
2809
|
-
*
|
2810
|
-
* @returns {Axios} A new instance of Axios
|
2811
|
-
*/ function createInstance(defaultConfig) {
|
2812
|
-
const context = new Axios(defaultConfig);
|
2813
|
-
const instance = bind(Axios.prototype.request, context);
|
2814
|
-
// Copy axios.prototype to instance
|
2815
|
-
utils.extend(instance, Axios.prototype, context, {
|
2816
|
-
allOwnKeys: true
|
2817
|
-
});
|
2818
|
-
// Copy context to instance
|
2819
|
-
utils.extend(instance, context, null, {
|
2820
|
-
allOwnKeys: true
|
2821
|
-
});
|
2822
|
-
// Factory for creating new instances
|
2823
|
-
instance.create = function(instanceConfig) {
|
2824
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2825
|
-
};
|
2826
|
-
return instance;
|
2827
|
-
}
|
2828
|
-
// Create the default instance to be exported
|
2829
|
-
const axios = createInstance(defaults);
|
2830
|
-
// Expose Axios class to allow class inheritance
|
2831
|
-
axios.Axios = Axios;
|
2832
|
-
// Expose Cancel & CancelToken
|
2833
|
-
axios.CanceledError = CanceledError;
|
2834
|
-
axios.CancelToken = CancelToken;
|
2835
|
-
axios.isCancel = isCancel;
|
2836
|
-
axios.VERSION = VERSION;
|
2837
|
-
axios.toFormData = toFormData;
|
2838
|
-
// Expose AxiosError class
|
2839
|
-
axios.AxiosError = core_AxiosError;
|
2840
|
-
// alias for CanceledError for backward compatibility
|
2841
|
-
axios.Cancel = axios.CanceledError;
|
2842
|
-
// Expose all/spread
|
2843
|
-
axios.all = function(promises) {
|
2844
|
-
return Promise.all(promises);
|
2845
|
-
};
|
2846
|
-
axios.spread = spread;
|
2847
|
-
// Expose isAxiosError
|
2848
|
-
axios.isAxiosError = isAxiosError;
|
2849
|
-
// Expose mergeConfig
|
2850
|
-
axios.mergeConfig = mergeConfig;
|
2851
|
-
axios.AxiosHeaders = AxiosHeaders;
|
2852
|
-
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2853
|
-
axios.getAdapter = adapters_adapters.getAdapter;
|
2854
|
-
axios.HttpStatusCode = helpers_HttpStatusCode;
|
2855
|
-
axios.default = axios;
|
2856
|
-
// this module should only have a default export
|
2857
|
-
/* ESM default export */ const lib_axios = axios;
|
2858
|
-
// This module is intended to unwrap Axios default export as named.
|
2859
|
-
// Keep top-level export same with static properties
|
2860
|
-
// so that it can keep same with es module or cjs
|
2861
|
-
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;
|
2862
|
-
// EXTERNAL MODULE: os (ignored)
|
2863
|
-
var os_ignored_ = __webpack_require__("?9caf");
|
2864
|
-
// EXTERNAL MODULE: crypto (ignored)
|
2865
|
-
__webpack_require__("?e272");
|
2866
|
-
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
2867
|
-
__webpack_require__("?5742");
|
2868
|
-
class APIResource {
|
2869
|
-
constructor(client){
|
2870
|
-
this._client = client;
|
2871
|
-
}
|
2872
|
-
}
|
2873
|
-
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
2874
|
-
/**
|
2875
|
-
* Create a new agent. | 调用接口创建一个新的智能体。
|
2876
|
-
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
2877
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
2878
|
-
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
2879
|
-
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
2880
|
-
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
2881
|
-
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
2882
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2883
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2884
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2885
|
-
* @returns Information about the created bot. | 创建的 Bot 信息。
|
2886
|
-
*/ async create(params, options) {
|
2887
|
-
const apiUrl = '/v1/bot/create';
|
2888
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2889
|
-
return result.data;
|
2890
|
-
}
|
2891
|
-
/**
|
2892
|
-
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
2893
|
-
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
2894
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
2895
|
-
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
2896
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
2897
|
-
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
2898
|
-
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
2899
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2900
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2901
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2902
|
-
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
2903
|
-
* @returns Undefined | 无返回值
|
2904
|
-
*/ async update(params, options) {
|
2905
|
-
const apiUrl = '/v1/bot/update';
|
2906
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2907
|
-
return result.data;
|
2908
|
-
}
|
2909
|
-
/**
|
2910
|
-
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
2911
|
-
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
2912
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
2913
|
-
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
2914
|
-
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
2915
|
-
* @param params.page_size - Optional Pagination size. | 分页大小。
|
2916
|
-
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
2917
|
-
* @returns List of published bots. | 已发布的 Bot 列表。
|
2918
|
-
*/ async list(params, options) {
|
2919
|
-
const apiUrl = '/v1/space/published_bots_list';
|
2920
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2921
|
-
return result.data;
|
2922
|
-
}
|
2923
|
-
/**
|
2924
|
-
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
2925
|
-
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
2926
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
2927
|
-
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
2928
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
2929
|
-
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
2930
|
-
* @returns Undefined | 无返回值
|
2931
|
-
*/ async publish(params, options) {
|
2932
|
-
const apiUrl = '/v1/bot/publish';
|
2933
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2934
|
-
return result.data;
|
2935
|
-
}
|
2936
|
-
/**
|
2937
|
-
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
2938
|
-
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
2939
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
2940
|
-
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
2941
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
2942
|
-
* @returns Information about the bot. | Bot 的配置信息。
|
2943
|
-
*/ async retrieve(params, options) {
|
2944
|
-
const apiUrl = '/v1/bot/get_online_info';
|
2945
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2946
|
-
return result.data;
|
2947
|
-
}
|
2948
|
-
}
|
2949
|
-
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
2950
|
-
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
2951
|
-
try {
|
2952
|
-
return JSON.parse(jsonString);
|
2953
|
-
} catch (error) {
|
2954
|
-
return defaultValue;
|
2955
|
-
}
|
2956
|
-
}
|
2957
|
-
function sleep(ms) {
|
2958
|
-
return new Promise((resolve)=>{
|
2959
|
-
setTimeout(resolve, ms);
|
2960
|
-
});
|
2961
|
-
}
|
2962
|
-
function isBrowser() {
|
2963
|
-
return 'undefined' != typeof window;
|
2964
|
-
}
|
2965
|
-
function esm_isPlainObject(obj) {
|
2966
|
-
if ('object' != typeof obj || null === obj) return false;
|
2967
|
-
const proto = Object.getPrototypeOf(obj);
|
2968
|
-
if (null === proto) return true;
|
2969
|
-
let baseProto = proto;
|
2970
|
-
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
2971
|
-
return proto === baseProto;
|
2972
|
-
}
|
2973
|
-
function esm_mergeConfig() {
|
2974
|
-
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
2975
|
-
return objects.reduce((result, obj)=>{
|
2976
|
-
if (void 0 === obj) return result || {};
|
2977
|
-
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
2978
|
-
if (esm_isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = esm_mergeConfig(result[key] || {}, obj[key]);
|
2979
|
-
else result[key] = obj[key];
|
2980
|
-
}
|
2981
|
-
return result;
|
2982
|
-
}, {});
|
2983
|
-
}
|
2984
|
-
function isPersonalAccessToken(token) {
|
2985
|
-
return null == token ? void 0 : token.startsWith('pat_');
|
2986
|
-
}
|
2987
|
-
/* eslint-disable max-params */ class CozeError extends Error {
|
2988
|
-
}
|
2989
|
-
class APIError extends CozeError {
|
2990
|
-
static makeMessage(status, errorBody, message, headers) {
|
2991
|
-
if (!errorBody && message) return message;
|
2992
|
-
if (errorBody) {
|
2993
|
-
const list = [];
|
2994
|
-
const { code, msg, error } = errorBody;
|
2995
|
-
if (code) list.push(`code: ${code}`);
|
2996
|
-
if (msg) list.push(`msg: ${msg}`);
|
2997
|
-
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
2998
|
-
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
2999
|
-
if (logId) list.push(`logid: ${logId}`);
|
3000
|
-
const help_doc = null == error ? void 0 : error.help_doc;
|
3001
|
-
if (help_doc) list.push(`help doc: ${help_doc}`);
|
3002
|
-
return list.join(', ');
|
3003
|
-
}
|
3004
|
-
if (status) return `http status code: ${status} (no body)`;
|
3005
|
-
return '(no status code or body)';
|
3006
|
-
}
|
3007
|
-
static generate(status, errorResponse, message, headers) {
|
3008
|
-
if (!status) return new APIConnectionError({
|
3009
|
-
cause: castToError(errorResponse)
|
3010
|
-
});
|
3011
|
-
const error = errorResponse;
|
3012
|
-
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
3013
|
-
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
3014
|
-
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
3015
|
-
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
3016
|
-
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
3017
|
-
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
3018
|
-
if (408 === status) return new TimeoutError(status, error, message, headers);
|
3019
|
-
if (502 === status) return new GatewayError(status, error, message, headers);
|
3020
|
-
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
3021
|
-
return new APIError(status, error, message, headers);
|
3022
|
-
}
|
3023
|
-
constructor(status, error, message, headers){
|
3024
|
-
var _error_error, _error_error1;
|
3025
|
-
super(`${APIError.makeMessage(status, error, message, headers)}`);
|
3026
|
-
this.status = status;
|
3027
|
-
this.headers = headers;
|
3028
|
-
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
3029
|
-
// this.error = error;
|
3030
|
-
this.code = null == error ? void 0 : error.code;
|
3031
|
-
this.msg = null == error ? void 0 : error.msg;
|
3032
|
-
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
3033
|
-
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
3034
|
-
this.rawError = error;
|
3035
|
-
}
|
3036
|
-
}
|
3037
|
-
class APIConnectionError extends APIError {
|
3038
|
-
constructor({ message, cause }){
|
3039
|
-
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
3040
|
-
// if (cause) {
|
3041
|
-
// this.cause = cause;
|
3042
|
-
// }
|
3043
|
-
}
|
3044
|
-
}
|
3045
|
-
class APIUserAbortError extends APIError {
|
3046
|
-
constructor(message){
|
3047
|
-
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
3048
|
-
}
|
3049
|
-
}
|
3050
|
-
class BadRequestError extends APIError {
|
3051
|
-
constructor(...args){
|
3052
|
-
super(...args), this.name = 'BadRequestError', this.status = 400;
|
3053
|
-
}
|
3054
|
-
}
|
3055
|
-
class AuthenticationError extends APIError {
|
3056
|
-
constructor(...args){
|
3057
|
-
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
3058
|
-
}
|
3059
|
-
}
|
3060
|
-
class PermissionDeniedError extends APIError {
|
3061
|
-
constructor(...args){
|
3062
|
-
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
3063
|
-
}
|
3064
|
-
}
|
3065
|
-
class NotFoundError extends APIError {
|
3066
|
-
constructor(...args){
|
3067
|
-
super(...args), this.name = 'NotFoundError', this.status = 404;
|
3068
|
-
}
|
3069
|
-
}
|
3070
|
-
class TimeoutError extends APIError {
|
3071
|
-
constructor(...args){
|
3072
|
-
super(...args), this.name = 'TimeoutError', this.status = 408;
|
3073
|
-
}
|
3074
|
-
}
|
3075
|
-
class RateLimitError extends APIError {
|
3076
|
-
constructor(...args){
|
3077
|
-
super(...args), this.name = 'RateLimitError', this.status = 429;
|
3078
|
-
}
|
3079
|
-
}
|
3080
|
-
class InternalServerError extends APIError {
|
3081
|
-
constructor(...args){
|
3082
|
-
super(...args), this.name = 'InternalServerError', this.status = 500;
|
3083
|
-
}
|
3084
|
-
}
|
3085
|
-
class GatewayError extends APIError {
|
3086
|
-
constructor(...args){
|
3087
|
-
super(...args), this.name = 'GatewayError', this.status = 502;
|
3088
|
-
}
|
3089
|
-
}
|
3090
|
-
const castToError = (err)=>{
|
3091
|
-
if (err instanceof Error) return err;
|
3092
|
-
return new Error(err);
|
3093
|
-
};
|
3094
|
-
class Messages extends APIResource {
|
3095
|
-
/**
|
3096
|
-
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
3097
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
3098
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
3099
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3100
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3101
|
-
* @returns An array of chat messages. | 对话消息数组。
|
3102
|
-
*/ async list(conversation_id, chat_id, options) {
|
3103
|
-
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3104
|
-
const result = await this._client.get(apiUrl, void 0, false, options);
|
3105
|
-
return result.data;
|
3106
|
-
}
|
3107
|
-
}
|
3108
|
-
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
3109
|
-
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
3110
|
-
...i,
|
3111
|
-
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
3112
|
-
}));
|
3113
|
-
class Chat extends APIResource {
|
3114
|
-
/**
|
3115
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3116
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3117
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3118
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3119
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3120
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3121
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3122
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
3123
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3124
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3125
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3126
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3127
|
-
* @returns The data of the created chat. | 创建的对话数据。
|
3128
|
-
*/ async create(params, options) {
|
3129
|
-
if (!params.user_id) params.user_id = uuid();
|
3130
|
-
const { conversation_id, ...rest } = params;
|
3131
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3132
|
-
const payload = {
|
3133
|
-
...rest,
|
3134
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3135
|
-
stream: false
|
3136
|
-
};
|
3137
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3138
|
-
return result.data;
|
3139
|
-
}
|
3140
|
-
/**
|
3141
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3142
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3143
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3144
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3145
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3146
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3147
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3148
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3149
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3150
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3151
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3152
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3153
|
-
* @returns
|
3154
|
-
*/ async createAndPoll(params, options) {
|
3155
|
-
if (!params.user_id) params.user_id = uuid();
|
3156
|
-
const { conversation_id, ...rest } = params;
|
3157
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3158
|
-
const payload = {
|
3159
|
-
...rest,
|
3160
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3161
|
-
stream: false
|
3162
|
-
};
|
3163
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3164
|
-
const chatId = result.data.id;
|
3165
|
-
const conversationId = result.data.conversation_id;
|
3166
|
-
let chat;
|
3167
|
-
while(true){
|
3168
|
-
await sleep(100);
|
3169
|
-
chat = await this.retrieve(conversationId, chatId);
|
3170
|
-
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
3171
|
-
}
|
3172
|
-
const messageList = await this.messages.list(conversationId, chatId);
|
3173
|
-
return {
|
3174
|
-
chat,
|
3175
|
-
messages: messageList
|
3176
|
-
};
|
3177
|
-
}
|
3178
|
-
/**
|
3179
|
-
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
3180
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3181
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3182
|
-
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
3183
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3184
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3185
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3186
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3187
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3188
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3189
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3190
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3191
|
-
* @returns A stream of chat data. | 对话数据流。
|
3192
|
-
*/ async *stream(params, options) {
|
3193
|
-
if (!params.user_id) params.user_id = uuid();
|
3194
|
-
const { conversation_id, ...rest } = params;
|
3195
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3196
|
-
const payload = {
|
3197
|
-
...rest,
|
3198
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3199
|
-
stream: true
|
3200
|
-
};
|
3201
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
3202
|
-
for await (const message of result)if ("done" === message.event) {
|
3203
|
-
const ret = {
|
3204
|
-
event: message.event,
|
3205
|
-
data: '[DONE]'
|
3206
|
-
};
|
3207
|
-
yield ret;
|
3208
|
-
} else try {
|
3209
|
-
const ret = {
|
3210
|
-
event: message.event,
|
3211
|
-
data: JSON.parse(message.data)
|
3212
|
-
};
|
3213
|
-
yield ret;
|
3214
|
-
} catch (error) {
|
3215
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3216
|
-
}
|
3217
|
-
}
|
3218
|
-
/**
|
3219
|
-
* Get the detailed information of the chat. | 查看对话的详细信息。
|
3220
|
-
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
3221
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
3222
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3223
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3224
|
-
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
3225
|
-
*/ async retrieve(conversation_id, chat_id, options) {
|
3226
|
-
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3227
|
-
const result = await this._client.post(apiUrl, void 0, false, options);
|
3228
|
-
return result.data;
|
3229
|
-
}
|
3230
|
-
/**
|
3231
|
-
* Cancel a chat session. | 取消对话会话。
|
3232
|
-
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
3233
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
3234
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3235
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3236
|
-
* @returns The data of the canceled chat. | 取消的对话数据。
|
3237
|
-
*/ async cancel(conversation_id, chat_id, options) {
|
3238
|
-
const apiUrl = '/v3/chat/cancel';
|
3239
|
-
const payload = {
|
3240
|
-
conversation_id,
|
3241
|
-
chat_id
|
3242
|
-
};
|
3243
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3244
|
-
return result.data;
|
3245
|
-
}
|
3246
|
-
/**
|
3247
|
-
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
3248
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
3249
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
3250
|
-
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
3251
|
-
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
3252
|
-
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
3253
|
-
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
3254
|
-
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
3255
|
-
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
3256
|
-
*/ async *submitToolOutputs(params, options) {
|
3257
|
-
const { conversation_id, chat_id, ...rest } = params;
|
3258
|
-
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
3259
|
-
const payload = {
|
3260
|
-
...rest
|
3261
|
-
};
|
3262
|
-
if (false === params.stream) {
|
3263
|
-
const response = await this._client.post(apiUrl, payload, false, options);
|
3264
|
-
return response.data;
|
3065
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
3066
|
+
const { transitional, paramsSerializer, headers } = config;
|
3067
|
+
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
3068
|
+
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
3069
|
+
forcedJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
3070
|
+
clarifyTimeoutError: Axios_validators.transitional(Axios_validators.boolean)
|
3071
|
+
}, false);
|
3072
|
+
if (null != paramsSerializer) {
|
3073
|
+
if (utils.isFunction(paramsSerializer)) config.paramsSerializer = {
|
3074
|
+
serialize: paramsSerializer
|
3075
|
+
};
|
3076
|
+
else helpers_validator.assertOptions(paramsSerializer, {
|
3077
|
+
encode: Axios_validators.function,
|
3078
|
+
serialize: Axios_validators.function
|
3079
|
+
}, true);
|
3265
3080
|
}
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3269
|
-
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3081
|
+
// Set config.method
|
3082
|
+
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
3083
|
+
// Flatten headers
|
3084
|
+
let contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
|
3085
|
+
headers && utils.forEach([
|
3086
|
+
'delete',
|
3087
|
+
'get',
|
3088
|
+
'head',
|
3089
|
+
'post',
|
3090
|
+
'put',
|
3091
|
+
'patch',
|
3092
|
+
'common'
|
3093
|
+
], (method)=>{
|
3094
|
+
delete headers[method];
|
3095
|
+
});
|
3096
|
+
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
3097
|
+
// filter out skipped interceptors
|
3098
|
+
const requestInterceptorChain = [];
|
3099
|
+
let synchronousRequestInterceptors = true;
|
3100
|
+
this.interceptors.request.forEach(function(interceptor) {
|
3101
|
+
if ('function' == typeof interceptor.runWhen && false === interceptor.runWhen(config)) return;
|
3102
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
3103
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
3104
|
+
});
|
3105
|
+
const responseInterceptorChain = [];
|
3106
|
+
this.interceptors.response.forEach(function(interceptor) {
|
3107
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
3108
|
+
});
|
3109
|
+
let promise;
|
3110
|
+
let i = 0;
|
3111
|
+
let len;
|
3112
|
+
if (!synchronousRequestInterceptors) {
|
3113
|
+
const chain = [
|
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;
|
3123
|
+
}
|
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);
|
3280
3132
|
} catch (error) {
|
3281
|
-
|
3133
|
+
onRejected.call(this, error);
|
3134
|
+
break;
|
3282
3135
|
}
|
3283
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;
|
3284
3146
|
}
|
3285
|
-
|
3286
|
-
|
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);
|
3287
3151
|
}
|
3288
3152
|
}
|
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
|
-
|
3319
|
-
|
3320
|
-
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
3321
|
-
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
3322
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
3323
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3324
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3325
|
-
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
3326
|
-
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
3327
|
-
* @param params.content - Optional The content of the message. | 消息的内容。
|
3328
|
-
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
3329
|
-
* @returns Information about the modified message. | 消息详情。
|
3330
|
-
*/ // eslint-disable-next-line max-params
|
3331
|
-
async update(conversation_id, message_id, params, options) {
|
3332
|
-
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3333
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3334
|
-
return response.message;
|
3335
|
-
}
|
3336
|
-
/**
|
3337
|
-
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
3338
|
-
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
3339
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
3340
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3341
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3342
|
-
* @returns Information about the message. | 消息详情。
|
3343
|
-
*/ async retrieve(conversation_id, message_id, options) {
|
3344
|
-
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3345
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3346
|
-
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
|
+
};
|
3347
3184
|
}
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
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
|
+
});
|
3364
3229
|
}
|
3365
3230
|
/**
|
3366
|
-
*
|
3367
|
-
|
3368
|
-
|
3369
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3370
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3371
|
-
* @returns Details of the deleted message. | 已删除的消息详情。
|
3372
|
-
*/ async delete(conversation_id, message_id, options) {
|
3373
|
-
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3374
|
-
const response = await this._client.post(apiUrl, void 0, false, options);
|
3375
|
-
return response.data;
|
3231
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
3232
|
+
*/ throwIfRequested() {
|
3233
|
+
if (this.reason) throw this.reason;
|
3376
3234
|
}
|
3377
|
-
}
|
3378
|
-
class Conversations extends APIResource {
|
3379
3235
|
/**
|
3380
|
-
*
|
3381
|
-
|
3382
|
-
|
3383
|
-
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3388
|
-
|
3389
|
-
|
3390
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3391
|
-
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
|
+
];
|
3392
3246
|
}
|
3393
3247
|
/**
|
3394
|
-
*
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
*/ async retrieve(conversation_id, options) {
|
3400
|
-
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
3401
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3402
|
-
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);
|
3403
3253
|
}
|
3404
|
-
|
3405
|
-
|
3406
|
-
|
3407
|
-
|
3408
|
-
|
3409
|
-
|
3410
|
-
|
3411
|
-
|
3412
|
-
const apiUrl = '/v1/conversations';
|
3413
|
-
const response = await this._client.get(apiUrl, params, false, options);
|
3414
|
-
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;
|
3415
3262
|
}
|
3416
3263
|
/**
|
3417
|
-
*
|
3418
|
-
*
|
3419
|
-
|
3420
|
-
|
3421
|
-
const
|
3422
|
-
|
3423
|
-
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
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
|
+
};
|
3427
3275
|
}
|
3428
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;
|
3429
3438
|
class Files extends APIResource {
|
3430
3439
|
/**
|
3431
3440
|
* Upload files to Coze platform. | 调用接口上传文件到扣子。
|
@@ -3588,7 +3597,7 @@ class Documents extends APIResource {
|
|
3588
3597
|
* @returns ListDocumentData | 知识库文件列表
|
3589
3598
|
*/ list(params, options) {
|
3590
3599
|
const apiUrl = '/open_api/knowledge/document/list';
|
3591
|
-
const response = this._client.get(apiUrl, params, false,
|
3600
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3592
3601
|
headers: documents_headers
|
3593
3602
|
}));
|
3594
3603
|
return response;
|
@@ -3606,7 +3615,7 @@ class Documents extends APIResource {
|
|
3606
3615
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3607
3616
|
*/ async create(params, options) {
|
3608
3617
|
const apiUrl = '/open_api/knowledge/document/create';
|
3609
|
-
const response = await this._client.post(apiUrl, params, false,
|
3618
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3610
3619
|
headers: documents_headers
|
3611
3620
|
}));
|
3612
3621
|
return response.document_infos;
|
@@ -3622,7 +3631,7 @@ class Documents extends APIResource {
|
|
3622
3631
|
* @returns void | 无返回
|
3623
3632
|
*/ async delete(params, options) {
|
3624
3633
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3625
|
-
await this._client.post(apiUrl, params, false,
|
3634
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3626
3635
|
headers: documents_headers
|
3627
3636
|
}));
|
3628
3637
|
}
|
@@ -3638,7 +3647,7 @@ class Documents extends APIResource {
|
|
3638
3647
|
* @returns void | 无返回
|
3639
3648
|
*/ async update(params, options) {
|
3640
3649
|
const apiUrl = '/open_api/knowledge/document/update';
|
3641
|
-
await this._client.post(apiUrl, params, false,
|
3650
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3642
3651
|
headers: documents_headers
|
3643
3652
|
}));
|
3644
3653
|
}
|
@@ -3666,7 +3675,7 @@ class documents_Documents extends APIResource {
|
|
3666
3675
|
* @returns ListDocumentData | 知识库文件列表
|
3667
3676
|
*/ async list(params, options) {
|
3668
3677
|
const apiUrl = '/open_api/knowledge/document/list';
|
3669
|
-
const response = await this._client.get(apiUrl, params, false,
|
3678
|
+
const response = await this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3670
3679
|
headers: documents_documents_headers
|
3671
3680
|
}));
|
3672
3681
|
return response;
|
@@ -3682,7 +3691,7 @@ class documents_Documents extends APIResource {
|
|
3682
3691
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3683
3692
|
*/ async create(params, options) {
|
3684
3693
|
const apiUrl = '/open_api/knowledge/document/create';
|
3685
|
-
const response = await this._client.post(apiUrl, params, false,
|
3694
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3686
3695
|
headers: documents_documents_headers
|
3687
3696
|
}));
|
3688
3697
|
return response.document_infos;
|
@@ -3696,7 +3705,7 @@ class documents_Documents extends APIResource {
|
|
3696
3705
|
* @returns void | 无返回
|
3697
3706
|
*/ async delete(params, options) {
|
3698
3707
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3699
|
-
await this._client.post(apiUrl, params, false,
|
3708
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3700
3709
|
headers: documents_documents_headers
|
3701
3710
|
}));
|
3702
3711
|
}
|
@@ -3710,7 +3719,7 @@ class documents_Documents extends APIResource {
|
|
3710
3719
|
* @returns void | 无返回
|
3711
3720
|
*/ async update(params, options) {
|
3712
3721
|
const apiUrl = '/open_api/knowledge/document/update';
|
3713
|
-
await this._client.post(apiUrl, params, false,
|
3722
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3714
3723
|
headers: documents_documents_headers
|
3715
3724
|
}));
|
3716
3725
|
}
|
@@ -3869,7 +3878,10 @@ class Speech extends APIResource {
|
|
3869
3878
|
* @returns Speech synthesis data
|
3870
3879
|
*/ async create(params, options) {
|
3871
3880
|
const apiUrl = '/v1/audio/speech';
|
3872
|
-
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, {
|
3873
3885
|
responseType: 'arraybuffer'
|
3874
3886
|
}));
|
3875
3887
|
return response;
|
@@ -3882,23 +3894,40 @@ class Rooms extends APIResource {
|
|
3882
3894
|
return response.data;
|
3883
3895
|
}
|
3884
3896
|
}
|
3885
|
-
class
|
3897
|
+
class audio_Audio extends APIResource {
|
3886
3898
|
constructor(...args){
|
3887
3899
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3888
3900
|
}
|
3889
3901
|
}
|
3890
|
-
|
3891
|
-
|
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;
|
3892
3921
|
const getEnv = ()=>{
|
3893
3922
|
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
3894
3923
|
const { platform } = process;
|
3895
3924
|
let osName = platform.toLowerCase();
|
3896
|
-
let osVersion =
|
3925
|
+
let osVersion = os_ignored_default().release();
|
3897
3926
|
if ('darwin' === platform) {
|
3898
3927
|
osName = 'macos';
|
3899
3928
|
// Try to parse the macOS version
|
3900
3929
|
try {
|
3901
|
-
const darwinVersion =
|
3930
|
+
const darwinVersion = os_ignored_default().release().split('.');
|
3902
3931
|
if (darwinVersion.length >= 2) {
|
3903
3932
|
const majorVersion = parseInt(darwinVersion[0], 10);
|
3904
3933
|
if (!isNaN(majorVersion) && majorVersion >= 9) {
|
@@ -3911,10 +3940,10 @@ const getEnv = ()=>{
|
|
3911
3940
|
}
|
3912
3941
|
} else if ('win32' === platform) {
|
3913
3942
|
osName = 'windows';
|
3914
|
-
osVersion =
|
3943
|
+
osVersion = os_ignored_default().release();
|
3915
3944
|
} else if ('linux' === platform) {
|
3916
3945
|
osName = 'linux';
|
3917
|
-
osVersion =
|
3946
|
+
osVersion = os_ignored_default().release();
|
3918
3947
|
}
|
3919
3948
|
return {
|
3920
3949
|
osName,
|
@@ -3924,12 +3953,12 @@ const getEnv = ()=>{
|
|
3924
3953
|
};
|
3925
3954
|
const getUserAgent = ()=>{
|
3926
3955
|
const { nodeVersion, osName, osVersion } = getEnv();
|
3927
|
-
return `coze-js/${
|
3956
|
+
return `coze-js/${version_version} node/${nodeVersion} ${osName}/${osVersion}`.toLowerCase();
|
3928
3957
|
};
|
3929
3958
|
const getNodeClientUserAgent = ()=>{
|
3930
3959
|
const { osVersion, nodeVersion, osName } = getEnv();
|
3931
3960
|
const ua = {
|
3932
|
-
version:
|
3961
|
+
version: version_version,
|
3933
3962
|
lang: 'node',
|
3934
3963
|
lang_version: nodeVersion,
|
3935
3964
|
os_name: osName,
|
@@ -3937,15 +3966,66 @@ const getNodeClientUserAgent = ()=>{
|
|
3937
3966
|
};
|
3938
3967
|
return JSON.stringify(ua);
|
3939
3968
|
};
|
3940
|
-
|
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)=>{
|
3941
4019
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3942
4020
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
3943
4021
|
var _error_response;
|
3944
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);
|
3945
4023
|
}
|
3946
4024
|
if ('ERR_CANCELED' === error.code) return new APIUserAbortError(error.message);
|
3947
|
-
|
3948
|
-
|
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
|
+
}
|
3949
4029
|
};
|
3950
4030
|
async function fetchAPI(url) {
|
3951
4031
|
let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
|
@@ -3961,7 +4041,7 @@ async function fetchAPI(url) {
|
|
3961
4041
|
adapter: options.isStreaming ? 'fetch' : void 0,
|
3962
4042
|
...options
|
3963
4043
|
}).catch((error)=>{
|
3964
|
-
throw
|
4044
|
+
throw fetcher_handleError(error);
|
3965
4045
|
});
|
3966
4046
|
return {
|
3967
4047
|
async *stream () {
|
@@ -3999,7 +4079,7 @@ async function fetchAPI(url) {
|
|
3999
4079
|
buffer = lines[lines.length - 1]; // Keep the last incomplete line in the buffer
|
4000
4080
|
}
|
4001
4081
|
} catch (error) {
|
4002
|
-
|
4082
|
+
fetcher_handleError(error);
|
4003
4083
|
}
|
4004
4084
|
},
|
4005
4085
|
json: ()=>response.data,
|
@@ -4023,8 +4103,8 @@ function isAxiosStatic(instance) {
|
|
4023
4103
|
}
|
4024
4104
|
/**
|
4025
4105
|
* default coze base URL is api.coze.com
|
4026
|
-
*/ const
|
4027
|
-
/* eslint-disable max-params */ class
|
4106
|
+
*/ const constant_COZE_COM_BASE_URL = 'https://api.coze.com';
|
4107
|
+
/* eslint-disable max-params */ class core_APIClient {
|
4028
4108
|
async getToken() {
|
4029
4109
|
if ('function' == typeof this.token) return await this.token();
|
4030
4110
|
return this.token;
|
@@ -4034,11 +4114,12 @@ function isAxiosStatic(instance) {
|
|
4034
4114
|
const headers = {
|
4035
4115
|
authorization: `Bearer ${token}`
|
4036
4116
|
};
|
4037
|
-
if (
|
4117
|
+
if (utils_isBrowser()) headers['X-Coze-Client-User-Agent'] = getBrowserClientUserAgent();
|
4118
|
+
else {
|
4038
4119
|
headers['User-Agent'] = getUserAgent();
|
4039
4120
|
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
4040
4121
|
}
|
4041
|
-
const config =
|
4122
|
+
const config = mergeConfig(this.axiosOptions, options, {
|
4042
4123
|
headers
|
4043
4124
|
});
|
4044
4125
|
config.method = method;
|
@@ -4062,7 +4143,7 @@ function isAxiosStatic(instance) {
|
|
4062
4143
|
if (contentType && contentType.includes('application/json')) {
|
4063
4144
|
const result = await json();
|
4064
4145
|
const { code, msg } = result;
|
4065
|
-
if (0 !== code && void 0 !== code) throw
|
4146
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
4066
4147
|
}
|
4067
4148
|
return stream();
|
4068
4149
|
}
|
@@ -4070,7 +4151,7 @@ function isAxiosStatic(instance) {
|
|
4070
4151
|
{
|
4071
4152
|
const result = await json();
|
4072
4153
|
const { code, msg } = result;
|
4073
|
-
if (0 !== code && void 0 !== code) throw
|
4154
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
4074
4155
|
return result;
|
4075
4156
|
}
|
4076
4157
|
}
|
@@ -4102,31 +4183,35 @@ function isAxiosStatic(instance) {
|
|
4102
4183
|
}
|
4103
4184
|
constructor(config){
|
4104
4185
|
this._config = config;
|
4105
|
-
this.baseURL = config.baseURL ||
|
4186
|
+
this.baseURL = config.baseURL || constant_COZE_COM_BASE_URL;
|
4106
4187
|
this.token = config.token;
|
4107
4188
|
this.axiosOptions = config.axiosOptions || {};
|
4108
4189
|
this.axiosInstance = config.axiosInstance;
|
4109
4190
|
this.debug = config.debug || false;
|
4110
4191
|
this.allowPersonalAccessTokenInBrowser = config.allowPersonalAccessTokenInBrowser || false;
|
4111
4192
|
this.headers = config.headers;
|
4112
|
-
if (
|
4113
|
-
}
|
4114
|
-
}
|
4115
|
-
|
4116
|
-
|
4117
|
-
|
4118
|
-
|
4119
|
-
|
4120
|
-
|
4121
|
-
|
4122
|
-
|
4123
|
-
|
4124
|
-
|
4125
|
-
|
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 {
|
4126
4211
|
constructor(...args){
|
4127
4212
|
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4128
4213
|
* @deprecated
|
4129
|
-
*/ 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);
|
4130
4215
|
}
|
4131
4216
|
}
|
4132
4217
|
/**
|
@@ -9358,7 +9443,7 @@ var setPrototypeOf = setPrototypeOf$2, _Object$setPrototypeOf = getDefaultExport
|
|
9358
9443
|
}, stringPad = {
|
9359
9444
|
start: createMethod(!1),
|
9360
9445
|
end: createMethod(!0)
|
9361
|
-
},
|
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;
|
9362
9447
|
$$F({
|
9363
9448
|
target: "String",
|
9364
9449
|
proto: !0,
|
@@ -38511,7 +38596,7 @@ var VERTC = _createClass(function e() {
|
|
38511
38596
|
+ * @param milliseconds The time to sleep in milliseconds
|
38512
38597
|
+ * @throws {Error} If milliseconds is negative
|
38513
38598
|
+ * @returns Promise that resolves after the specified duration
|
38514
|
-
+ */ const
|
38599
|
+
+ */ const src_utils_sleep = (milliseconds)=>{
|
38515
38600
|
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
38516
38601
|
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
38517
38602
|
};
|
@@ -42108,7 +42193,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42108
42193
|
var _this__videoConfig1;
|
42109
42194
|
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42110
42195
|
await this.engine.startScreenCapture(null === (_this__videoConfig1 = this._videoConfig) || void 0 === _this__videoConfig1 ? void 0 : _this__videoConfig1.screenConfig);
|
42111
|
-
await this.engine.publishScreen(MediaType$1.
|
42196
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42112
42197
|
}
|
42113
42198
|
this._streamIndex = StreamIndex$1.STREAM_INDEX_SCREEN;
|
42114
42199
|
} else {
|
@@ -42127,7 +42212,7 @@ class EngineClient extends RealtimeEventHandler {
|
|
42127
42212
|
video: this._isSupportVideo
|
42128
42213
|
});
|
42129
42214
|
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
42130
|
-
if (!devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
42215
|
+
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
42131
42216
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
42132
42217
|
if (this._isSupportVideo) this.setVideoInputDevice((null == videoConfig ? void 0 : videoConfig.videoInputDeviceId) || devices.videoInputs[0].deviceId, null == videoConfig ? void 0 : videoConfig.videoOnDefault);
|
42133
42218
|
}
|
@@ -42160,12 +42245,12 @@ class EngineClient extends RealtimeEventHandler {
|
|
42160
42245
|
var _this__videoConfig;
|
42161
42246
|
this.engine.setVideoSourceType(StreamIndex$1.STREAM_INDEX_SCREEN, VideoSourceType.VIDEO_SOURCE_TYPE_INTERNAL);
|
42162
42247
|
await this.engine.startScreenCapture(null === (_this__videoConfig = this._videoConfig) || void 0 === _this__videoConfig ? void 0 : _this__videoConfig.screenConfig);
|
42163
|
-
await this.engine.publishScreen(MediaType$1.
|
42248
|
+
await this.engine.publishScreen(MediaType$1.VIDEO);
|
42164
42249
|
}
|
42165
42250
|
} else if (this._streamIndex === StreamIndex$1.STREAM_INDEX_MAIN) await this.engine.stopVideoCapture();
|
42166
42251
|
else {
|
42167
42252
|
await this.engine.stopScreenCapture();
|
42168
|
-
await this.engine.unpublishScreen(MediaType$1.
|
42253
|
+
await this.engine.unpublishScreen(MediaType$1.VIDEO);
|
42169
42254
|
}
|
42170
42255
|
} catch (e) {
|
42171
42256
|
this.dispatch(event_handler_EventNames.ERROR, e);
|