@coze/realtime-api 1.0.3 → 1.0.4-beta.1
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 → index.js} +1447 -1429
- package/dist/esm/{index.js → index.mjs} +1447 -1429
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/umd/index.js +1446 -1428
- package/package.json +27 -19
- package/assets/api-overview.png +0 -0
- /package/dist/{esm → cjs}/index.js.LICENSE.txt +0 -0
- /package/dist/{cjs/index.cjs.LICENSE.txt → esm/index.mjs.LICENSE.txt} +0 -0
package/dist/umd/index.js
CHANGED
@@ -7,11 +7,11 @@
|
|
7
7
|
})(self, ()=>(()=>{
|
8
8
|
"use strict";
|
9
9
|
var __webpack_modules__ = {
|
10
|
-
"?
|
10
|
+
"?666e": function() {
|
11
11
|
/* (ignored) */ },
|
12
|
-
"?
|
12
|
+
"?79fd": function() {
|
13
13
|
/* (ignored) */ },
|
14
|
-
"?
|
14
|
+
"?9050": function() {
|
15
15
|
/* (ignored) */ }
|
16
16
|
};
|
17
17
|
/************************************************************************/ // The module cache
|
@@ -30,7 +30,22 @@
|
|
30
30
|
// Return the exports of the module
|
31
31
|
return module1.exports;
|
32
32
|
}
|
33
|
-
/************************************************************************/ // webpack/runtime/
|
33
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
34
|
+
(()=>{
|
35
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
36
|
+
__webpack_require__.n = function(module1) {
|
37
|
+
var getter = module1 && module1.__esModule ? function() {
|
38
|
+
return module1['default'];
|
39
|
+
} : function() {
|
40
|
+
return module1;
|
41
|
+
};
|
42
|
+
__webpack_require__.d(getter, {
|
43
|
+
a: getter
|
44
|
+
});
|
45
|
+
return getter;
|
46
|
+
};
|
47
|
+
})();
|
48
|
+
// webpack/runtime/define_property_getters
|
34
49
|
(()=>{
|
35
50
|
__webpack_require__.d = function(exports1, definition) {
|
36
51
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
@@ -96,480 +111,1041 @@
|
|
96
111
|
checkDevicePermission: ()=>checkDevicePermission,
|
97
112
|
checkPermission: ()=>checkPermission,
|
98
113
|
getAudioDevices: ()=>getAudioDevices,
|
99
|
-
sleep: ()=>
|
114
|
+
sleep: ()=>src_utils_sleep
|
100
115
|
});
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
116
|
+
class APIResource {
|
117
|
+
constructor(client){
|
118
|
+
this._client = client;
|
119
|
+
}
|
105
120
|
}
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
121
|
+
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
122
|
+
/**
|
123
|
+
* Create a new agent. | 调用接口创建一个新的智能体。
|
124
|
+
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
125
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
126
|
+
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
127
|
+
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
128
|
+
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
129
|
+
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
130
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
131
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
132
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
133
|
+
* @returns Information about the created bot. | 创建的 Bot 信息。
|
134
|
+
*/ async create(params, options) {
|
135
|
+
const apiUrl = '/v1/bot/create';
|
136
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
137
|
+
return result.data;
|
138
|
+
}
|
139
|
+
/**
|
140
|
+
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
141
|
+
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
142
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
143
|
+
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
144
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
145
|
+
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
146
|
+
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
147
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
148
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
149
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
150
|
+
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
151
|
+
* @returns Undefined | 无返回值
|
152
|
+
*/ async update(params, options) {
|
153
|
+
const apiUrl = '/v1/bot/update';
|
154
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
155
|
+
return result.data;
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
159
|
+
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
160
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
161
|
+
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
162
|
+
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
163
|
+
* @param params.page_size - Optional Pagination size. | 分页大小。
|
164
|
+
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
165
|
+
* @returns List of published bots. | 已发布的 Bot 列表。
|
166
|
+
*/ async list(params, options) {
|
167
|
+
const apiUrl = '/v1/space/published_bots_list';
|
168
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
169
|
+
return result.data;
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
173
|
+
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
174
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
175
|
+
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
176
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
177
|
+
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
178
|
+
* @returns Undefined | 无返回值
|
179
|
+
*/ async publish(params, options) {
|
180
|
+
const apiUrl = '/v1/bot/publish';
|
181
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
182
|
+
return result.data;
|
183
|
+
}
|
184
|
+
/**
|
185
|
+
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
186
|
+
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
187
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
188
|
+
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
189
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
190
|
+
* @returns Information about the bot. | Bot 的配置信息。
|
191
|
+
*/ async retrieve(params, options) {
|
192
|
+
const apiUrl = '/v1/bot/get_online_info';
|
193
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
194
|
+
return result.data;
|
195
|
+
}
|
140
196
|
}
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
/**
|
149
|
-
* Determine if a value is a view on an ArrayBuffer
|
150
|
-
*
|
151
|
-
* @param {*} val The value to test
|
152
|
-
*
|
153
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
154
|
-
*/ function isArrayBufferView(val) {
|
155
|
-
let result;
|
156
|
-
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
157
|
-
return result;
|
197
|
+
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
198
|
+
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
199
|
+
try {
|
200
|
+
return JSON.parse(jsonString);
|
201
|
+
} catch (error) {
|
202
|
+
return defaultValue;
|
203
|
+
}
|
158
204
|
}
|
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
|
-
|
203
|
-
|
204
|
-
|
205
|
-
*
|
206
|
-
* @param {*} val The value to test
|
207
|
-
*
|
208
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
209
|
-
*/ const isDate = kindOfTest('Date');
|
210
|
-
/**
|
211
|
-
* Determine if a value is a File
|
212
|
-
*
|
213
|
-
* @param {*} val The value to test
|
214
|
-
*
|
215
|
-
* @returns {boolean} True if value is a File, otherwise false
|
216
|
-
*/ const isFile = kindOfTest('File');
|
217
|
-
/**
|
218
|
-
* Determine if a value is a Blob
|
219
|
-
*
|
220
|
-
* @param {*} val The value to test
|
221
|
-
*
|
222
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
223
|
-
*/ const isBlob = kindOfTest('Blob');
|
224
|
-
/**
|
225
|
-
* Determine if a value is a FileList
|
226
|
-
*
|
227
|
-
* @param {*} val The value to test
|
228
|
-
*
|
229
|
-
* @returns {boolean} True if value is a File, otherwise false
|
230
|
-
*/ const utils_isFileList = kindOfTest('FileList');
|
231
|
-
/**
|
232
|
-
* Determine if a value is a Stream
|
233
|
-
*
|
234
|
-
* @param {*} val The value to test
|
235
|
-
*
|
236
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
237
|
-
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
238
|
-
/**
|
239
|
-
* Determine if a value is a FormData
|
240
|
-
*
|
241
|
-
* @param {*} thing The value to test
|
242
|
-
*
|
243
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
244
|
-
*/ const utils_isFormData = (thing)=>{
|
245
|
-
let kind;
|
246
|
-
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
247
|
-
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
248
|
-
};
|
249
|
-
/**
|
250
|
-
* Determine if a value is a URLSearchParams object
|
251
|
-
*
|
252
|
-
* @param {*} val The value to test
|
253
|
-
*
|
254
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
255
|
-
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
256
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
257
|
-
'ReadableStream',
|
258
|
-
'Request',
|
259
|
-
'Response',
|
260
|
-
'Headers'
|
261
|
-
].map(kindOfTest);
|
262
|
-
/**
|
263
|
-
* Trim excess whitespace off the beginning and end of a string
|
264
|
-
*
|
265
|
-
* @param {String} str The String to trim
|
266
|
-
*
|
267
|
-
* @returns {String} The String freed of excess whitespace
|
268
|
-
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
269
|
-
/**
|
270
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
271
|
-
*
|
272
|
-
* If `obj` is an Array callback will be called passing
|
273
|
-
* the value, index, and complete array for each item.
|
274
|
-
*
|
275
|
-
* If 'obj' is an Object callback will be called passing
|
276
|
-
* the value, key, and complete object for each property.
|
277
|
-
*
|
278
|
-
* @param {Object|Array} obj The object to iterate
|
279
|
-
* @param {Function} fn The callback to invoke for each item
|
280
|
-
*
|
281
|
-
* @param {Boolean} [allOwnKeys = false]
|
282
|
-
* @returns {any}
|
283
|
-
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
284
|
-
// Don't bother if no value provided
|
285
|
-
if (null == obj) return;
|
286
|
-
let i;
|
287
|
-
let l;
|
288
|
-
// Force an array if not already something iterable
|
289
|
-
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
290
|
-
obj
|
291
|
-
];
|
292
|
-
if (isArray(obj)) // Iterate over array values
|
293
|
-
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
294
|
-
else {
|
295
|
-
// Iterate over object keys
|
296
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
297
|
-
const len = keys.length;
|
298
|
-
let key;
|
299
|
-
for(i = 0; i < len; i++){
|
300
|
-
key = keys[i];
|
301
|
-
fn.call(null, obj[key], key, obj);
|
205
|
+
function utils_sleep(ms) {
|
206
|
+
return new Promise((resolve)=>{
|
207
|
+
setTimeout(resolve, ms);
|
208
|
+
});
|
209
|
+
}
|
210
|
+
function utils_isBrowser() {
|
211
|
+
return 'undefined' != typeof window;
|
212
|
+
}
|
213
|
+
function isPlainObject(obj) {
|
214
|
+
if ('object' != typeof obj || null === obj) return false;
|
215
|
+
const proto = Object.getPrototypeOf(obj);
|
216
|
+
if (null === proto) return true;
|
217
|
+
let baseProto = proto;
|
218
|
+
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
219
|
+
return proto === baseProto;
|
220
|
+
}
|
221
|
+
function mergeConfig() {
|
222
|
+
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
223
|
+
return objects.reduce((result, obj)=>{
|
224
|
+
if (void 0 === obj) return result || {};
|
225
|
+
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
226
|
+
if (isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = mergeConfig(result[key] || {}, obj[key]);
|
227
|
+
else result[key] = obj[key];
|
228
|
+
}
|
229
|
+
return result;
|
230
|
+
}, {});
|
231
|
+
}
|
232
|
+
function isPersonalAccessToken(token) {
|
233
|
+
return null == token ? void 0 : token.startsWith('pat_');
|
234
|
+
}
|
235
|
+
/* eslint-disable max-params */ class CozeError extends Error {
|
236
|
+
}
|
237
|
+
class error_APIError extends CozeError {
|
238
|
+
static makeMessage(status, errorBody, message, headers) {
|
239
|
+
if (!errorBody && message) return message;
|
240
|
+
if (errorBody) {
|
241
|
+
const list = [];
|
242
|
+
const { code, msg, error } = errorBody;
|
243
|
+
if (code) list.push(`code: ${code}`);
|
244
|
+
if (msg) list.push(`msg: ${msg}`);
|
245
|
+
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
246
|
+
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
247
|
+
if (logId) list.push(`logid: ${logId}`);
|
248
|
+
const help_doc = null == error ? void 0 : error.help_doc;
|
249
|
+
if (help_doc) list.push(`help doc: ${help_doc}`);
|
250
|
+
return list.join(', ');
|
302
251
|
}
|
252
|
+
if (status) return `http status code: ${status} (no body)`;
|
253
|
+
return '(no status code or body)';
|
254
|
+
}
|
255
|
+
static generate(status, errorResponse, message, headers) {
|
256
|
+
if (!status) return new APIConnectionError({
|
257
|
+
cause: castToError(errorResponse)
|
258
|
+
});
|
259
|
+
const error = errorResponse;
|
260
|
+
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
261
|
+
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
262
|
+
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
263
|
+
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
264
|
+
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
265
|
+
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
266
|
+
if (408 === status) return new TimeoutError(status, error, message, headers);
|
267
|
+
if (502 === status) return new GatewayError(status, error, message, headers);
|
268
|
+
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
269
|
+
return new error_APIError(status, error, message, headers);
|
270
|
+
}
|
271
|
+
constructor(status, error, message, headers){
|
272
|
+
var _error_error, _error_error1;
|
273
|
+
super(`${error_APIError.makeMessage(status, error, message, headers)}`);
|
274
|
+
this.status = status;
|
275
|
+
this.headers = headers;
|
276
|
+
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
277
|
+
// this.error = error;
|
278
|
+
this.code = null == error ? void 0 : error.code;
|
279
|
+
this.msg = null == error ? void 0 : error.msg;
|
280
|
+
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
281
|
+
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
282
|
+
this.rawError = error;
|
303
283
|
}
|
304
284
|
}
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
_key = keys[i];
|
312
|
-
if (key === _key.toLowerCase()) return _key;
|
285
|
+
class APIConnectionError extends error_APIError {
|
286
|
+
constructor({ message, cause }){
|
287
|
+
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
288
|
+
// if (cause) {
|
289
|
+
// this.cause = cause;
|
290
|
+
// }
|
313
291
|
}
|
314
|
-
return null;
|
315
292
|
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
321
|
-
/**
|
322
|
-
* Accepts varargs expecting each argument to be an object, then
|
323
|
-
* immutably merges the properties of each object and returns result.
|
324
|
-
*
|
325
|
-
* When multiple objects contain the same key the later object in
|
326
|
-
* the arguments list will take precedence.
|
327
|
-
*
|
328
|
-
* Example:
|
329
|
-
*
|
330
|
-
* ```js
|
331
|
-
* var result = merge({foo: 123}, {foo: 456});
|
332
|
-
* console.log(result.foo); // outputs 456
|
333
|
-
* ```
|
334
|
-
*
|
335
|
-
* @param {Object} obj1 Object to merge
|
336
|
-
*
|
337
|
-
* @returns {Object} Result of all merge properties
|
338
|
-
*/ function utils_merge() {
|
339
|
-
const { caseless } = isContextDefined(this) && this || {};
|
340
|
-
const result = {};
|
341
|
-
const assignValue = (val, key)=>{
|
342
|
-
const targetKey = caseless && findKey(result, key) || key;
|
343
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
344
|
-
else if (isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
345
|
-
else if (isArray(val)) result[targetKey] = val.slice();
|
346
|
-
else result[targetKey] = val;
|
347
|
-
};
|
348
|
-
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
349
|
-
return result;
|
293
|
+
class APIUserAbortError extends error_APIError {
|
294
|
+
constructor(message){
|
295
|
+
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
296
|
+
}
|
350
297
|
}
|
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
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
298
|
+
class BadRequestError extends error_APIError {
|
299
|
+
constructor(...args){
|
300
|
+
super(...args), this.name = 'BadRequestError', this.status = 400;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
class AuthenticationError extends error_APIError {
|
304
|
+
constructor(...args){
|
305
|
+
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
class PermissionDeniedError extends error_APIError {
|
309
|
+
constructor(...args){
|
310
|
+
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
class NotFoundError extends error_APIError {
|
314
|
+
constructor(...args){
|
315
|
+
super(...args), this.name = 'NotFoundError', this.status = 404;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
class TimeoutError extends error_APIError {
|
319
|
+
constructor(...args){
|
320
|
+
super(...args), this.name = 'TimeoutError', this.status = 408;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
class RateLimitError extends error_APIError {
|
324
|
+
constructor(...args){
|
325
|
+
super(...args), this.name = 'RateLimitError', this.status = 429;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
class InternalServerError extends error_APIError {
|
329
|
+
constructor(...args){
|
330
|
+
super(...args), this.name = 'InternalServerError', this.status = 500;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
class GatewayError extends error_APIError {
|
334
|
+
constructor(...args){
|
335
|
+
super(...args), this.name = 'GatewayError', this.status = 502;
|
336
|
+
}
|
337
|
+
}
|
338
|
+
const castToError = (err)=>{
|
339
|
+
if (err instanceof Error) return err;
|
340
|
+
return new Error(err);
|
394
341
|
};
|
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
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
342
|
+
class Messages extends APIResource {
|
343
|
+
/**
|
344
|
+
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
345
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
346
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
347
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
348
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
349
|
+
* @returns An array of chat messages. | 对话消息数组。
|
350
|
+
*/ async list(conversation_id, chat_id, options) {
|
351
|
+
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
352
|
+
const result = await this._client.get(apiUrl, void 0, false, options);
|
353
|
+
return result.data;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
357
|
+
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
358
|
+
...i,
|
359
|
+
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
360
|
+
}));
|
361
|
+
class Chat extends APIResource {
|
362
|
+
/**
|
363
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
364
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
365
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
366
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
367
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
368
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
369
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
370
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
371
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
372
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
373
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
374
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
375
|
+
* @returns The data of the created chat. | 创建的对话数据。
|
376
|
+
*/ async create(params, options) {
|
377
|
+
if (!params.user_id) params.user_id = uuid();
|
378
|
+
const { conversation_id, ...rest } = params;
|
379
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
380
|
+
const payload = {
|
381
|
+
...rest,
|
382
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
383
|
+
stream: false
|
384
|
+
};
|
385
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
386
|
+
return result.data;
|
387
|
+
}
|
388
|
+
/**
|
389
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
390
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
391
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
392
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
393
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
394
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
395
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
396
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
397
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
398
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
399
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
400
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
401
|
+
* @returns
|
402
|
+
*/ async createAndPoll(params, options) {
|
403
|
+
if (!params.user_id) params.user_id = uuid();
|
404
|
+
const { conversation_id, ...rest } = params;
|
405
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
406
|
+
const payload = {
|
407
|
+
...rest,
|
408
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
409
|
+
stream: false
|
410
|
+
};
|
411
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
412
|
+
const chatId = result.data.id;
|
413
|
+
const conversationId = result.data.conversation_id;
|
414
|
+
let chat;
|
415
|
+
while(true){
|
416
|
+
await utils_sleep(100);
|
417
|
+
chat = await this.retrieve(conversationId, chatId);
|
418
|
+
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
419
|
+
}
|
420
|
+
const messageList = await this.messages.list(conversationId, chatId);
|
421
|
+
return {
|
422
|
+
chat,
|
423
|
+
messages: messageList
|
424
|
+
};
|
425
|
+
}
|
426
|
+
/**
|
427
|
+
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
428
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
429
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
430
|
+
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
431
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
432
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
433
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
434
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
435
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
436
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
437
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
438
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
439
|
+
* @returns A stream of chat data. | 对话数据流。
|
440
|
+
*/ async *stream(params, options) {
|
441
|
+
if (!params.user_id) params.user_id = uuid();
|
442
|
+
const { conversation_id, ...rest } = params;
|
443
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
444
|
+
const payload = {
|
445
|
+
...rest,
|
446
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
447
|
+
stream: true
|
448
|
+
};
|
449
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
450
|
+
for await (const message of result)if ("done" === message.event) {
|
451
|
+
const ret = {
|
452
|
+
event: message.event,
|
453
|
+
data: '[DONE]'
|
454
|
+
};
|
455
|
+
yield ret;
|
456
|
+
} else try {
|
457
|
+
const ret = {
|
458
|
+
event: message.event,
|
459
|
+
data: JSON.parse(message.data)
|
460
|
+
};
|
461
|
+
yield ret;
|
462
|
+
} catch (error) {
|
463
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
464
|
+
}
|
465
|
+
}
|
466
|
+
/**
|
467
|
+
* Get the detailed information of the chat. | 查看对话的详细信息。
|
468
|
+
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
469
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
470
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
471
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
472
|
+
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
473
|
+
*/ async retrieve(conversation_id, chat_id, options) {
|
474
|
+
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
475
|
+
const result = await this._client.post(apiUrl, void 0, false, options);
|
476
|
+
return result.data;
|
477
|
+
}
|
478
|
+
/**
|
479
|
+
* Cancel a chat session. | 取消对话会话。
|
480
|
+
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
481
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
482
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
483
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
484
|
+
* @returns The data of the canceled chat. | 取消的对话数据。
|
485
|
+
*/ async cancel(conversation_id, chat_id, options) {
|
486
|
+
const apiUrl = '/v3/chat/cancel';
|
487
|
+
const payload = {
|
488
|
+
conversation_id,
|
489
|
+
chat_id
|
490
|
+
};
|
491
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
492
|
+
return result.data;
|
493
|
+
}
|
494
|
+
/**
|
495
|
+
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
496
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
497
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
498
|
+
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
499
|
+
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
500
|
+
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
501
|
+
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
502
|
+
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
503
|
+
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
504
|
+
*/ async *submitToolOutputs(params, options) {
|
505
|
+
const { conversation_id, chat_id, ...rest } = params;
|
506
|
+
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
507
|
+
const payload = {
|
508
|
+
...rest
|
509
|
+
};
|
510
|
+
if (false === params.stream) {
|
511
|
+
const response = await this._client.post(apiUrl, payload, false, options);
|
512
|
+
return response.data;
|
513
|
+
}
|
514
|
+
{
|
515
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
516
|
+
for await (const message of result)if ("done" === message.event) {
|
517
|
+
const ret = {
|
518
|
+
event: message.event,
|
519
|
+
data: '[DONE]'
|
520
|
+
};
|
521
|
+
yield ret;
|
522
|
+
} else try {
|
523
|
+
const ret = {
|
524
|
+
event: message.event,
|
525
|
+
data: JSON.parse(message.data)
|
526
|
+
};
|
527
|
+
yield ret;
|
528
|
+
} catch (error) {
|
529
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
530
|
+
}
|
531
|
+
}
|
532
|
+
}
|
533
|
+
constructor(...args){
|
534
|
+
super(...args), this.messages = new Messages(this._client);
|
535
|
+
}
|
536
|
+
}
|
537
|
+
var chat_ChatEventType = /*#__PURE__*/ function(ChatEventType) {
|
538
|
+
ChatEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
|
539
|
+
ChatEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
|
540
|
+
ChatEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
|
541
|
+
ChatEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
|
542
|
+
ChatEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
|
543
|
+
ChatEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
|
544
|
+
ChatEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
|
545
|
+
ChatEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
|
546
|
+
ChatEventType["DONE"] = "done";
|
547
|
+
ChatEventType["ERROR"] = "error";
|
548
|
+
return ChatEventType;
|
549
|
+
}({});
|
550
|
+
class messages_Messages extends APIResource {
|
551
|
+
/**
|
552
|
+
* Create a message and add it to the specified conversation. | 创建一条消息,并将其添加到指定的会话中。
|
553
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_message?_lang=en
|
554
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_message?_lang=zh
|
555
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
556
|
+
* @param params - Required The parameters for creating a message | 创建消息所需的参数
|
557
|
+
* @param params.role - Required The entity that sent this message. Possible values: user, assistant. | 发送这条消息的实体。取值:user, assistant。
|
558
|
+
* @param params.content - Required The content of the message. | 消息的内容。
|
559
|
+
* @param params.content_type - Required The type of the message content. | 消息内容的类型。
|
560
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
561
|
+
* @returns Information about the new message. | 消息详情。
|
562
|
+
*/ async create(conversation_id, params, options) {
|
563
|
+
const apiUrl = `/v1/conversation/message/create?conversation_id=${conversation_id}`;
|
564
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
565
|
+
return response.data;
|
566
|
+
}
|
567
|
+
/**
|
568
|
+
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
569
|
+
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
570
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
571
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
572
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
573
|
+
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
574
|
+
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
575
|
+
* @param params.content - Optional The content of the message. | 消息的内容。
|
576
|
+
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
577
|
+
* @returns Information about the modified message. | 消息详情。
|
578
|
+
*/ // eslint-disable-next-line max-params
|
579
|
+
async update(conversation_id, message_id, params, options) {
|
580
|
+
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
581
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
582
|
+
return response.message;
|
583
|
+
}
|
584
|
+
/**
|
585
|
+
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
586
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
587
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
588
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
589
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
590
|
+
* @returns Information about the message. | 消息详情。
|
591
|
+
*/ async retrieve(conversation_id, message_id, options) {
|
592
|
+
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
593
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
594
|
+
return response.data;
|
595
|
+
}
|
596
|
+
/**
|
597
|
+
* List messages in a conversation. | 列出会话中的消息。
|
598
|
+
* @docs en: https://www.coze.com/docs/developer_guides/message_list?_lang=en
|
599
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/message_list?_lang=zh
|
600
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
601
|
+
* @param params - Optional The parameters for listing messages | 列出消息所需的参数
|
602
|
+
* @param params.order - Optional The order of the messages. | 消息的顺序。
|
603
|
+
* @param params.chat_id - Optional The ID of the chat. | 聊天 ID。
|
604
|
+
* @param params.before_id - Optional The ID of the message before which to list. | 列出此消息之前的消息 ID。
|
605
|
+
* @param params.after_id - Optional The ID of the message after which to list. | 列出此消息之后的消息 ID。
|
606
|
+
* @param params.limit - Optional The maximum number of messages to return. | 返回的最大消息数。
|
607
|
+
* @returns A list of messages. | 消息列表。
|
608
|
+
*/ async list(conversation_id, params, options) {
|
609
|
+
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
610
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
611
|
+
return response;
|
612
|
+
}
|
613
|
+
/**
|
614
|
+
* Call the API to delete a message within a specified conversation. | 调用接口在指定会话中删除消息。
|
615
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_message?_lang=en
|
616
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_message?_lang=zh
|
617
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
618
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
619
|
+
* @returns Details of the deleted message. | 已删除的消息详情。
|
620
|
+
*/ async delete(conversation_id, message_id, options) {
|
621
|
+
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
622
|
+
const response = await this._client.post(apiUrl, void 0, false, options);
|
623
|
+
return response.data;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
class Conversations extends APIResource {
|
627
|
+
/**
|
628
|
+
* Create a conversation. Conversation is an interaction between an agent and a user, including one or more messages. | 调用接口创建一个会话。
|
629
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_conversation?_lang=en
|
630
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_conversation?_lang=zh
|
631
|
+
* @param params - Required The parameters for creating a conversation | 创建会话所需的参数
|
632
|
+
* @param params.messages - Optional Messages in the conversation. | 会话中的消息内容。
|
633
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
634
|
+
* @param params.bot_id - Optional Bind and isolate conversation on different bots. | 绑定和隔离不同Bot的会话。
|
635
|
+
* @returns Information about the created conversation. | 会话的基础信息。
|
636
|
+
*/ async create(params, options) {
|
637
|
+
const apiUrl = '/v1/conversation/create';
|
638
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
639
|
+
return response.data;
|
640
|
+
}
|
641
|
+
/**
|
642
|
+
* Get the information of specific conversation. | 通过会话 ID 查看会话信息。
|
643
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_conversation?_lang=en
|
644
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_conversation?_lang=zh
|
645
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
646
|
+
* @returns Information about the conversation. | 会话的基础信息。
|
647
|
+
*/ async retrieve(conversation_id, options) {
|
648
|
+
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
649
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
650
|
+
return response.data;
|
651
|
+
}
|
652
|
+
/**
|
653
|
+
* List all conversations. | 列出 Bot 下所有会话。
|
654
|
+
* @param params
|
655
|
+
* @param params.bot_id - Required Bot ID. | Bot ID。
|
656
|
+
* @param params.page_num - Optional The page number. | 页码,默认值为 1。
|
657
|
+
* @param params.page_size - Optional The number of conversations per page. | 每页的会话数量,默认值为 50。
|
658
|
+
* @returns Information about the conversations. | 会话的信息。
|
659
|
+
*/ async list(params, options) {
|
660
|
+
const apiUrl = '/v1/conversations';
|
661
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
662
|
+
return response.data;
|
663
|
+
}
|
664
|
+
/**
|
665
|
+
* Clear a conversation. | 清空会话。
|
666
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
667
|
+
* @returns Information about the conversation session. | 会话的会话 ID。
|
668
|
+
*/ async clear(conversation_id, options) {
|
669
|
+
const apiUrl = `/v1/conversations/${conversation_id}/clear`;
|
670
|
+
const response = await this._client.post(apiUrl, null, false, options);
|
671
|
+
return response.data;
|
672
|
+
}
|
673
|
+
constructor(...args){
|
674
|
+
super(...args), this.messages = new messages_Messages(this._client);
|
675
|
+
}
|
676
|
+
}
|
677
|
+
function bind(fn, thisArg) {
|
678
|
+
return function() {
|
679
|
+
return fn.apply(thisArg, arguments);
|
680
|
+
};
|
681
|
+
}
|
682
|
+
// utils is a library of generic helper functions non-specific to axios
|
683
|
+
const { toString: utils_toString } = Object.prototype;
|
684
|
+
const { getPrototypeOf } = Object;
|
685
|
+
const kindOf = ((cache)=>(thing)=>{
|
686
|
+
const str = utils_toString.call(thing);
|
687
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
688
|
+
})(Object.create(null));
|
689
|
+
const kindOfTest = (type)=>{
|
690
|
+
type = type.toLowerCase();
|
691
|
+
return (thing)=>kindOf(thing) === type;
|
424
692
|
};
|
693
|
+
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
425
694
|
/**
|
426
|
-
*
|
695
|
+
* Determine if a value is an Array
|
427
696
|
*
|
428
|
-
* @param {
|
429
|
-
* @param {String} searchString
|
430
|
-
* @param {Number} [position= 0]
|
697
|
+
* @param {Object} val The value to test
|
431
698
|
*
|
432
|
-
* @returns {boolean}
|
433
|
-
*/ const
|
434
|
-
str = String(str);
|
435
|
-
if (void 0 === position || position > str.length) position = str.length;
|
436
|
-
position -= searchString.length;
|
437
|
-
const lastIndex = str.indexOf(searchString, position);
|
438
|
-
return -1 !== lastIndex && lastIndex === position;
|
439
|
-
};
|
699
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
700
|
+
*/ const { isArray } = Array;
|
440
701
|
/**
|
441
|
-
*
|
702
|
+
* Determine if a value is undefined
|
442
703
|
*
|
443
|
-
* @param {*}
|
704
|
+
* @param {*} val The value to test
|
444
705
|
*
|
445
|
-
* @returns {
|
446
|
-
*/ const
|
447
|
-
if (!thing) return null;
|
448
|
-
if (isArray(thing)) return thing;
|
449
|
-
let i = thing.length;
|
450
|
-
if (!isNumber(i)) return null;
|
451
|
-
const arr = new Array(i);
|
452
|
-
while(i-- > 0)arr[i] = thing[i];
|
453
|
-
return arr;
|
454
|
-
};
|
706
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
707
|
+
*/ const isUndefined = typeOfTest('undefined');
|
455
708
|
/**
|
456
|
-
*
|
457
|
-
* thing passed in is an instance of Uint8Array
|
709
|
+
* Determine if a value is a Buffer
|
458
710
|
*
|
459
|
-
* @param {
|
711
|
+
* @param {*} val The value to test
|
460
712
|
*
|
461
|
-
* @returns {
|
462
|
-
*/
|
463
|
-
|
713
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
714
|
+
*/ function isBuffer(val) {
|
715
|
+
return null !== val && !isUndefined(val) && null !== val.constructor && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
716
|
+
}
|
464
717
|
/**
|
465
|
-
*
|
718
|
+
* Determine if a value is an ArrayBuffer
|
466
719
|
*
|
467
|
-
* @param {
|
468
|
-
* @param {Function} fn - The function to call for each entry.
|
720
|
+
* @param {*} val The value to test
|
469
721
|
*
|
470
|
-
* @returns {
|
471
|
-
*/ const
|
472
|
-
const generator = obj && obj[Symbol.iterator];
|
473
|
-
const iterator = generator.call(obj);
|
474
|
-
let result;
|
475
|
-
while((result = iterator.next()) && !result.done){
|
476
|
-
const pair = result.value;
|
477
|
-
fn.call(obj, pair[0], pair[1]);
|
478
|
-
}
|
479
|
-
};
|
722
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
723
|
+
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
480
724
|
/**
|
481
|
-
*
|
725
|
+
* Determine if a value is a view on an ArrayBuffer
|
482
726
|
*
|
483
|
-
* @param {
|
484
|
-
* @param {string} str - The string to search.
|
727
|
+
* @param {*} val The value to test
|
485
728
|
*
|
486
|
-
* @returns {
|
487
|
-
*/
|
488
|
-
let
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
};
|
493
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
494
|
-
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
495
|
-
return p1.toUpperCase() + p2;
|
496
|
-
});
|
497
|
-
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
729
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
730
|
+
*/ function isArrayBufferView(val) {
|
731
|
+
let result;
|
732
|
+
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
733
|
+
return result;
|
734
|
+
}
|
498
735
|
/**
|
499
|
-
* Determine if a value is a
|
736
|
+
* Determine if a value is a String
|
500
737
|
*
|
501
738
|
* @param {*} val The value to test
|
502
739
|
*
|
503
|
-
* @returns {boolean} True if value is a
|
504
|
-
*/ const
|
505
|
-
const reduceDescriptors = (obj, reducer)=>{
|
506
|
-
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
507
|
-
const reducedDescriptors = {};
|
508
|
-
forEach(descriptors, (descriptor, name)=>{
|
509
|
-
let ret;
|
510
|
-
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
511
|
-
});
|
512
|
-
Object.defineProperties(obj, reducedDescriptors);
|
513
|
-
};
|
740
|
+
* @returns {boolean} True if value is a String, otherwise false
|
741
|
+
*/ const isString = typeOfTest('string');
|
514
742
|
/**
|
515
|
-
*
|
516
|
-
*
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
if (isFunction(obj) && -1 !== [
|
521
|
-
'arguments',
|
522
|
-
'caller',
|
523
|
-
'callee'
|
524
|
-
].indexOf(name)) return false;
|
525
|
-
const value = obj[name];
|
526
|
-
if (!isFunction(value)) return;
|
527
|
-
descriptor.enumerable = false;
|
528
|
-
if ('writable' in descriptor) {
|
529
|
-
descriptor.writable = false;
|
530
|
-
return;
|
531
|
-
}
|
532
|
-
if (!descriptor.set) descriptor.set = ()=>{
|
533
|
-
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
534
|
-
};
|
535
|
-
});
|
536
|
-
};
|
537
|
-
const toObjectSet = (arrayOrString, delimiter)=>{
|
538
|
-
const obj = {};
|
539
|
-
const define1 = (arr)=>{
|
540
|
-
arr.forEach((value)=>{
|
541
|
-
obj[value] = true;
|
542
|
-
});
|
543
|
-
};
|
544
|
-
isArray(arrayOrString) ? define1(arrayOrString) : define1(String(arrayOrString).split(delimiter));
|
545
|
-
return obj;
|
546
|
-
};
|
547
|
-
const noop = ()=>{};
|
548
|
-
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
549
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
550
|
-
const DIGIT = '0123456789';
|
551
|
-
const ALPHABET = {
|
552
|
-
DIGIT,
|
553
|
-
ALPHA,
|
554
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
555
|
-
};
|
556
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
557
|
-
let str = '';
|
558
|
-
const { length } = alphabet;
|
559
|
-
while(size--)str += alphabet[Math.random() * length | 0];
|
560
|
-
return str;
|
561
|
-
};
|
743
|
+
* Determine if a value is a Function
|
744
|
+
*
|
745
|
+
* @param {*} val The value to test
|
746
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
747
|
+
*/ const isFunction = typeOfTest('function');
|
562
748
|
/**
|
563
|
-
*
|
749
|
+
* Determine if a value is a Number
|
564
750
|
*
|
565
|
-
* @param {
|
751
|
+
* @param {*} val The value to test
|
566
752
|
*
|
567
|
-
* @returns {boolean}
|
568
|
-
*/
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
753
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
754
|
+
*/ const isNumber = typeOfTest('number');
|
755
|
+
/**
|
756
|
+
* Determine if a value is an Object
|
757
|
+
*
|
758
|
+
* @param {*} thing The value to test
|
759
|
+
*
|
760
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
761
|
+
*/ const isObject = (thing)=>null !== thing && 'object' == typeof thing;
|
762
|
+
/**
|
763
|
+
* Determine if a value is a Boolean
|
764
|
+
*
|
765
|
+
* @param {*} thing The value to test
|
766
|
+
* @returns {boolean} True if value is a Boolean, otherwise false
|
767
|
+
*/ const isBoolean = (thing)=>true === thing || false === thing;
|
768
|
+
/**
|
769
|
+
* Determine if a value is a plain Object
|
770
|
+
*
|
771
|
+
* @param {*} val The value to test
|
772
|
+
*
|
773
|
+
* @returns {boolean} True if value is a plain Object, otherwise false
|
774
|
+
*/ const utils_isPlainObject = (val)=>{
|
775
|
+
if ('object' !== kindOf(val)) return false;
|
776
|
+
const prototype = getPrototypeOf(val);
|
777
|
+
return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
778
|
+
};
|
779
|
+
/**
|
780
|
+
* Determine if a value is a Date
|
781
|
+
*
|
782
|
+
* @param {*} val The value to test
|
783
|
+
*
|
784
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
785
|
+
*/ const isDate = kindOfTest('Date');
|
786
|
+
/**
|
787
|
+
* Determine if a value is a File
|
788
|
+
*
|
789
|
+
* @param {*} val The value to test
|
790
|
+
*
|
791
|
+
* @returns {boolean} True if value is a File, otherwise false
|
792
|
+
*/ const isFile = kindOfTest('File');
|
793
|
+
/**
|
794
|
+
* Determine if a value is a Blob
|
795
|
+
*
|
796
|
+
* @param {*} val The value to test
|
797
|
+
*
|
798
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
799
|
+
*/ const isBlob = kindOfTest('Blob');
|
800
|
+
/**
|
801
|
+
* Determine if a value is a FileList
|
802
|
+
*
|
803
|
+
* @param {*} val The value to test
|
804
|
+
*
|
805
|
+
* @returns {boolean} True if value is a File, otherwise false
|
806
|
+
*/ const utils_isFileList = kindOfTest('FileList');
|
807
|
+
/**
|
808
|
+
* Determine if a value is a Stream
|
809
|
+
*
|
810
|
+
* @param {*} val The value to test
|
811
|
+
*
|
812
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
813
|
+
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
814
|
+
/**
|
815
|
+
* Determine if a value is a FormData
|
816
|
+
*
|
817
|
+
* @param {*} thing The value to test
|
818
|
+
*
|
819
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
820
|
+
*/ const utils_isFormData = (thing)=>{
|
821
|
+
let kind;
|
822
|
+
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
823
|
+
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
824
|
+
};
|
825
|
+
/**
|
826
|
+
* Determine if a value is a URLSearchParams object
|
827
|
+
*
|
828
|
+
* @param {*} val The value to test
|
829
|
+
*
|
830
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
831
|
+
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
832
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
833
|
+
'ReadableStream',
|
834
|
+
'Request',
|
835
|
+
'Response',
|
836
|
+
'Headers'
|
837
|
+
].map(kindOfTest);
|
838
|
+
/**
|
839
|
+
* Trim excess whitespace off the beginning and end of a string
|
840
|
+
*
|
841
|
+
* @param {String} str The String to trim
|
842
|
+
*
|
843
|
+
* @returns {String} The String freed of excess whitespace
|
844
|
+
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
845
|
+
/**
|
846
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
847
|
+
*
|
848
|
+
* If `obj` is an Array callback will be called passing
|
849
|
+
* the value, index, and complete array for each item.
|
850
|
+
*
|
851
|
+
* If 'obj' is an Object callback will be called passing
|
852
|
+
* the value, key, and complete object for each property.
|
853
|
+
*
|
854
|
+
* @param {Object|Array} obj The object to iterate
|
855
|
+
* @param {Function} fn The callback to invoke for each item
|
856
|
+
*
|
857
|
+
* @param {Boolean} [allOwnKeys = false]
|
858
|
+
* @returns {any}
|
859
|
+
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
860
|
+
// Don't bother if no value provided
|
861
|
+
if (null == obj) return;
|
862
|
+
let i;
|
863
|
+
let l;
|
864
|
+
// Force an array if not already something iterable
|
865
|
+
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
866
|
+
obj
|
867
|
+
];
|
868
|
+
if (isArray(obj)) // Iterate over array values
|
869
|
+
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
870
|
+
else {
|
871
|
+
// Iterate over object keys
|
872
|
+
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
873
|
+
const len = keys.length;
|
874
|
+
let key;
|
875
|
+
for(i = 0; i < len; i++){
|
876
|
+
key = keys[i];
|
877
|
+
fn.call(null, obj[key], key, obj);
|
878
|
+
}
|
879
|
+
}
|
880
|
+
}
|
881
|
+
function findKey(obj, key) {
|
882
|
+
key = key.toLowerCase();
|
883
|
+
const keys = Object.keys(obj);
|
884
|
+
let i = keys.length;
|
885
|
+
let _key;
|
886
|
+
while(i-- > 0){
|
887
|
+
_key = keys[i];
|
888
|
+
if (key === _key.toLowerCase()) return _key;
|
889
|
+
}
|
890
|
+
return null;
|
891
|
+
}
|
892
|
+
const _global = (()=>{
|
893
|
+
/*eslint no-undef:0*/ if ("undefined" != typeof globalThis) return globalThis;
|
894
|
+
return "undefined" != typeof self ? self : 'undefined' != typeof window ? window : global;
|
895
|
+
})();
|
896
|
+
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
897
|
+
/**
|
898
|
+
* Accepts varargs expecting each argument to be an object, then
|
899
|
+
* immutably merges the properties of each object and returns result.
|
900
|
+
*
|
901
|
+
* When multiple objects contain the same key the later object in
|
902
|
+
* the arguments list will take precedence.
|
903
|
+
*
|
904
|
+
* Example:
|
905
|
+
*
|
906
|
+
* ```js
|
907
|
+
* var result = merge({foo: 123}, {foo: 456});
|
908
|
+
* console.log(result.foo); // outputs 456
|
909
|
+
* ```
|
910
|
+
*
|
911
|
+
* @param {Object} obj1 Object to merge
|
912
|
+
*
|
913
|
+
* @returns {Object} Result of all merge properties
|
914
|
+
*/ function utils_merge() {
|
915
|
+
const { caseless } = isContextDefined(this) && this || {};
|
916
|
+
const result = {};
|
917
|
+
const assignValue = (val, key)=>{
|
918
|
+
const targetKey = caseless && findKey(result, key) || key;
|
919
|
+
if (utils_isPlainObject(result[targetKey]) && utils_isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
920
|
+
else if (utils_isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
921
|
+
else if (isArray(val)) result[targetKey] = val.slice();
|
922
|
+
else result[targetKey] = val;
|
923
|
+
};
|
924
|
+
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
925
|
+
return result;
|
926
|
+
}
|
927
|
+
/**
|
928
|
+
* Extends object a by mutably adding to it the properties of object b.
|
929
|
+
*
|
930
|
+
* @param {Object} a The object to be extended
|
931
|
+
* @param {Object} b The object to copy properties from
|
932
|
+
* @param {Object} thisArg The object to bind function to
|
933
|
+
*
|
934
|
+
* @param {Boolean} [allOwnKeys]
|
935
|
+
* @returns {Object} The resulting value of object a
|
936
|
+
*/ const extend = (a, b, thisArg, { allOwnKeys } = {})=>{
|
937
|
+
forEach(b, (val, key)=>{
|
938
|
+
if (thisArg && isFunction(val)) a[key] = bind(val, thisArg);
|
939
|
+
else a[key] = val;
|
940
|
+
}, {
|
941
|
+
allOwnKeys
|
942
|
+
});
|
943
|
+
return a;
|
944
|
+
};
|
945
|
+
/**
|
946
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
947
|
+
*
|
948
|
+
* @param {string} content with BOM
|
949
|
+
*
|
950
|
+
* @returns {string} content value without BOM
|
951
|
+
*/ const stripBOM = (content)=>{
|
952
|
+
if (0xFEFF === content.charCodeAt(0)) content = content.slice(1);
|
953
|
+
return content;
|
954
|
+
};
|
955
|
+
/**
|
956
|
+
* Inherit the prototype methods from one constructor into another
|
957
|
+
* @param {function} constructor
|
958
|
+
* @param {function} superConstructor
|
959
|
+
* @param {object} [props]
|
960
|
+
* @param {object} [descriptors]
|
961
|
+
*
|
962
|
+
* @returns {void}
|
963
|
+
*/ const inherits = (constructor, superConstructor, props, descriptors)=>{
|
964
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
965
|
+
constructor.prototype.constructor = constructor;
|
966
|
+
Object.defineProperty(constructor, 'super', {
|
967
|
+
value: superConstructor.prototype
|
968
|
+
});
|
969
|
+
props && Object.assign(constructor.prototype, props);
|
970
|
+
};
|
971
|
+
/**
|
972
|
+
* Resolve object with deep prototype chain to a flat object
|
973
|
+
* @param {Object} sourceObj source object
|
974
|
+
* @param {Object} [destObj]
|
975
|
+
* @param {Function|Boolean} [filter]
|
976
|
+
* @param {Function} [propFilter]
|
977
|
+
*
|
978
|
+
* @returns {Object}
|
979
|
+
*/ const toFlatObject = (sourceObj, destObj, filter, propFilter)=>{
|
980
|
+
let props;
|
981
|
+
let i;
|
982
|
+
let prop;
|
983
|
+
const merged = {};
|
984
|
+
destObj = destObj || {};
|
985
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
986
|
+
if (null == sourceObj) return destObj;
|
987
|
+
do {
|
988
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
989
|
+
i = props.length;
|
990
|
+
while(i-- > 0){
|
991
|
+
prop = props[i];
|
992
|
+
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
993
|
+
destObj[prop] = sourceObj[prop];
|
994
|
+
merged[prop] = true;
|
995
|
+
}
|
996
|
+
}
|
997
|
+
sourceObj = false !== filter && getPrototypeOf(sourceObj);
|
998
|
+
}while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
999
|
+
return destObj;
|
1000
|
+
};
|
1001
|
+
/**
|
1002
|
+
* Determines whether a string ends with the characters of a specified string
|
1003
|
+
*
|
1004
|
+
* @param {String} str
|
1005
|
+
* @param {String} searchString
|
1006
|
+
* @param {Number} [position= 0]
|
1007
|
+
*
|
1008
|
+
* @returns {boolean}
|
1009
|
+
*/ const endsWith = (str, searchString, position)=>{
|
1010
|
+
str = String(str);
|
1011
|
+
if (void 0 === position || position > str.length) position = str.length;
|
1012
|
+
position -= searchString.length;
|
1013
|
+
const lastIndex = str.indexOf(searchString, position);
|
1014
|
+
return -1 !== lastIndex && lastIndex === position;
|
1015
|
+
};
|
1016
|
+
/**
|
1017
|
+
* Returns new array from array like object or null if failed
|
1018
|
+
*
|
1019
|
+
* @param {*} [thing]
|
1020
|
+
*
|
1021
|
+
* @returns {?Array}
|
1022
|
+
*/ const toArray = (thing)=>{
|
1023
|
+
if (!thing) return null;
|
1024
|
+
if (isArray(thing)) return thing;
|
1025
|
+
let i = thing.length;
|
1026
|
+
if (!isNumber(i)) return null;
|
1027
|
+
const arr = new Array(i);
|
1028
|
+
while(i-- > 0)arr[i] = thing[i];
|
1029
|
+
return arr;
|
1030
|
+
};
|
1031
|
+
/**
|
1032
|
+
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
1033
|
+
* thing passed in is an instance of Uint8Array
|
1034
|
+
*
|
1035
|
+
* @param {TypedArray}
|
1036
|
+
*
|
1037
|
+
* @returns {Array}
|
1038
|
+
*/ // eslint-disable-next-line func-names
|
1039
|
+
const isTypedArray = ((TypedArray)=>(thing)=>TypedArray && thing instanceof TypedArray)('undefined' != typeof Uint8Array && getPrototypeOf(Uint8Array));
|
1040
|
+
/**
|
1041
|
+
* For each entry in the object, call the function with the key and value.
|
1042
|
+
*
|
1043
|
+
* @param {Object<any, any>} obj - The object to iterate over.
|
1044
|
+
* @param {Function} fn - The function to call for each entry.
|
1045
|
+
*
|
1046
|
+
* @returns {void}
|
1047
|
+
*/ const forEachEntry = (obj, fn)=>{
|
1048
|
+
const generator = obj && obj[Symbol.iterator];
|
1049
|
+
const iterator = generator.call(obj);
|
1050
|
+
let result;
|
1051
|
+
while((result = iterator.next()) && !result.done){
|
1052
|
+
const pair = result.value;
|
1053
|
+
fn.call(obj, pair[0], pair[1]);
|
1054
|
+
}
|
1055
|
+
};
|
1056
|
+
/**
|
1057
|
+
* It takes a regular expression and a string, and returns an array of all the matches
|
1058
|
+
*
|
1059
|
+
* @param {string} regExp - The regular expression to match against.
|
1060
|
+
* @param {string} str - The string to search.
|
1061
|
+
*
|
1062
|
+
* @returns {Array<boolean>}
|
1063
|
+
*/ const matchAll = (regExp, str)=>{
|
1064
|
+
let matches;
|
1065
|
+
const arr = [];
|
1066
|
+
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
1067
|
+
return arr;
|
1068
|
+
};
|
1069
|
+
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
1070
|
+
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
1071
|
+
return p1.toUpperCase() + p2;
|
1072
|
+
});
|
1073
|
+
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
1074
|
+
/**
|
1075
|
+
* Determine if a value is a RegExp object
|
1076
|
+
*
|
1077
|
+
* @param {*} val The value to test
|
1078
|
+
*
|
1079
|
+
* @returns {boolean} True if value is a RegExp object, otherwise false
|
1080
|
+
*/ const isRegExp = kindOfTest('RegExp');
|
1081
|
+
const reduceDescriptors = (obj, reducer)=>{
|
1082
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
1083
|
+
const reducedDescriptors = {};
|
1084
|
+
forEach(descriptors, (descriptor, name)=>{
|
1085
|
+
let ret;
|
1086
|
+
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
1087
|
+
});
|
1088
|
+
Object.defineProperties(obj, reducedDescriptors);
|
1089
|
+
};
|
1090
|
+
/**
|
1091
|
+
* Makes all methods read-only
|
1092
|
+
* @param {Object} obj
|
1093
|
+
*/ const freezeMethods = (obj)=>{
|
1094
|
+
reduceDescriptors(obj, (descriptor, name)=>{
|
1095
|
+
// skip restricted props in strict mode
|
1096
|
+
if (isFunction(obj) && -1 !== [
|
1097
|
+
'arguments',
|
1098
|
+
'caller',
|
1099
|
+
'callee'
|
1100
|
+
].indexOf(name)) return false;
|
1101
|
+
const value = obj[name];
|
1102
|
+
if (!isFunction(value)) return;
|
1103
|
+
descriptor.enumerable = false;
|
1104
|
+
if ('writable' in descriptor) {
|
1105
|
+
descriptor.writable = false;
|
1106
|
+
return;
|
1107
|
+
}
|
1108
|
+
if (!descriptor.set) descriptor.set = ()=>{
|
1109
|
+
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
1110
|
+
};
|
1111
|
+
});
|
1112
|
+
};
|
1113
|
+
const toObjectSet = (arrayOrString, delimiter)=>{
|
1114
|
+
const obj = {};
|
1115
|
+
const define1 = (arr)=>{
|
1116
|
+
arr.forEach((value)=>{
|
1117
|
+
obj[value] = true;
|
1118
|
+
});
|
1119
|
+
};
|
1120
|
+
isArray(arrayOrString) ? define1(arrayOrString) : define1(String(arrayOrString).split(delimiter));
|
1121
|
+
return obj;
|
1122
|
+
};
|
1123
|
+
const noop = ()=>{};
|
1124
|
+
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
1125
|
+
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
1126
|
+
const DIGIT = '0123456789';
|
1127
|
+
const ALPHABET = {
|
1128
|
+
DIGIT,
|
1129
|
+
ALPHA,
|
1130
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
1131
|
+
};
|
1132
|
+
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
1133
|
+
let str = '';
|
1134
|
+
const { length } = alphabet;
|
1135
|
+
while(size--)str += alphabet[Math.random() * length | 0];
|
1136
|
+
return str;
|
1137
|
+
};
|
1138
|
+
/**
|
1139
|
+
* If the thing is a FormData object, return true, otherwise return false.
|
1140
|
+
*
|
1141
|
+
* @param {unknown} thing - The thing to check.
|
1142
|
+
*
|
1143
|
+
* @returns {boolean}
|
1144
|
+
*/ function isSpecCompliantForm(thing) {
|
1145
|
+
return !!(thing && isFunction(thing.append) && 'FormData' === thing[Symbol.toStringTag] && thing[Symbol.iterator]);
|
1146
|
+
}
|
1147
|
+
const toJSONObject = (obj)=>{
|
1148
|
+
const stack = new Array(10);
|
573
1149
|
const visit = (source, i)=>{
|
574
1150
|
if (isObject(source)) {
|
575
1151
|
if (stack.indexOf(source) >= 0) return;
|
@@ -616,7 +1192,7 @@
|
|
616
1192
|
isNumber,
|
617
1193
|
isBoolean,
|
618
1194
|
isObject,
|
619
|
-
isPlainObject,
|
1195
|
+
isPlainObject: utils_isPlainObject,
|
620
1196
|
isReadableStream,
|
621
1197
|
isRequest,
|
622
1198
|
isResponse,
|
@@ -1814,7 +2390,7 @@
|
|
1814
2390
|
* @param {Object} config2
|
1815
2391
|
*
|
1816
2392
|
* @returns {Object} New object resulting from merging config2 to config1
|
1817
|
-
*/ function
|
2393
|
+
*/ function mergeConfig_mergeConfig(config1, config2) {
|
1818
2394
|
// eslint-disable-next-line no-param-reassign
|
1819
2395
|
config2 = config2 || {};
|
1820
2396
|
const config = {};
|
@@ -1884,7 +2460,7 @@
|
|
1884
2460
|
return config;
|
1885
2461
|
}
|
1886
2462
|
/* ESM default export */ const resolveConfig = (config)=>{
|
1887
|
-
const newConfig =
|
2463
|
+
const newConfig = mergeConfig_mergeConfig({}, config);
|
1888
2464
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
1889
2465
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
1890
2466
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
@@ -2476,960 +3052,393 @@
|
|
2476
3052
|
try {
|
2477
3053
|
if (err.stack) {
|
2478
3054
|
if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) err.stack += '\n' + stack;
|
2479
|
-
} else err.stack = stack;
|
2480
|
-
} catch (e) {
|
2481
|
-
// ignore the case where "stack" is an un-writable property
|
2482
|
-
}
|
2483
|
-
}
|
2484
|
-
throw err;
|
2485
|
-
}
|
2486
|
-
}
|
2487
|
-
_request(configOrUrl, config) {
|
2488
|
-
/*eslint no-param-reassign:0*/ // Allow for axios('example/url'[, config]) a la fetch API
|
2489
|
-
if ('string' == typeof configOrUrl) {
|
2490
|
-
config = config || {};
|
2491
|
-
config.url = configOrUrl;
|
2492
|
-
} else config = configOrUrl || {};
|
2493
|
-
config = mergeConfig(this.defaults, config);
|
2494
|
-
const { transitional, paramsSerializer, headers } = config;
|
2495
|
-
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
2496
|
-
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
2497
|
-
forcedJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
2498
|
-
clarifyTimeoutError: Axios_validators.transitional(Axios_validators.boolean)
|
2499
|
-
}, false);
|
2500
|
-
if (null != paramsSerializer) {
|
2501
|
-
if (utils.isFunction(paramsSerializer)) config.paramsSerializer = {
|
2502
|
-
serialize: paramsSerializer
|
2503
|
-
};
|
2504
|
-
else helpers_validator.assertOptions(paramsSerializer, {
|
2505
|
-
encode: Axios_validators.function,
|
2506
|
-
serialize: Axios_validators.function
|
2507
|
-
}, true);
|
2508
|
-
}
|
2509
|
-
// Set config.method
|
2510
|
-
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
2511
|
-
// Flatten headers
|
2512
|
-
let contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
|
2513
|
-
headers && utils.forEach([
|
2514
|
-
'delete',
|
2515
|
-
'get',
|
2516
|
-
'head',
|
2517
|
-
'post',
|
2518
|
-
'put',
|
2519
|
-
'patch',
|
2520
|
-
'common'
|
2521
|
-
], (method)=>{
|
2522
|
-
delete headers[method];
|
2523
|
-
});
|
2524
|
-
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
2525
|
-
// filter out skipped interceptors
|
2526
|
-
const requestInterceptorChain = [];
|
2527
|
-
let synchronousRequestInterceptors = true;
|
2528
|
-
this.interceptors.request.forEach(function(interceptor) {
|
2529
|
-
if ('function' == typeof interceptor.runWhen && false === interceptor.runWhen(config)) return;
|
2530
|
-
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
2531
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
2532
|
-
});
|
2533
|
-
const responseInterceptorChain = [];
|
2534
|
-
this.interceptors.response.forEach(function(interceptor) {
|
2535
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
2536
|
-
});
|
2537
|
-
let promise;
|
2538
|
-
let i = 0;
|
2539
|
-
let len;
|
2540
|
-
if (!synchronousRequestInterceptors) {
|
2541
|
-
const chain = [
|
2542
|
-
dispatchRequest.bind(this),
|
2543
|
-
void 0
|
2544
|
-
];
|
2545
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
2546
|
-
chain.push.apply(chain, responseInterceptorChain);
|
2547
|
-
len = chain.length;
|
2548
|
-
promise = Promise.resolve(config);
|
2549
|
-
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
2550
|
-
return promise;
|
2551
|
-
}
|
2552
|
-
len = requestInterceptorChain.length;
|
2553
|
-
let newConfig = config;
|
2554
|
-
i = 0;
|
2555
|
-
while(i < len){
|
2556
|
-
const onFulfilled = requestInterceptorChain[i++];
|
2557
|
-
const onRejected = requestInterceptorChain[i++];
|
2558
|
-
try {
|
2559
|
-
newConfig = onFulfilled(newConfig);
|
2560
|
-
} catch (error) {
|
2561
|
-
onRejected.call(this, error);
|
2562
|
-
break;
|
2563
|
-
}
|
2564
|
-
}
|
2565
|
-
try {
|
2566
|
-
promise = dispatchRequest.call(this, newConfig);
|
2567
|
-
} catch (error) {
|
2568
|
-
return Promise.reject(error);
|
2569
|
-
}
|
2570
|
-
i = 0;
|
2571
|
-
len = responseInterceptorChain.length;
|
2572
|
-
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
2573
|
-
return promise;
|
2574
|
-
}
|
2575
|
-
getUri(config) {
|
2576
|
-
config = mergeConfig(this.defaults, config);
|
2577
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2578
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2579
|
-
}
|
2580
|
-
}
|
2581
|
-
// Provide aliases for supported request methods
|
2582
|
-
utils.forEach([
|
2583
|
-
'delete',
|
2584
|
-
'get',
|
2585
|
-
'head',
|
2586
|
-
'options'
|
2587
|
-
], function(method) {
|
2588
|
-
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
2589
|
-
return this.request(mergeConfig(config || {}, {
|
2590
|
-
method,
|
2591
|
-
url,
|
2592
|
-
data: (config || {}).data
|
2593
|
-
}));
|
2594
|
-
};
|
2595
|
-
});
|
2596
|
-
utils.forEach([
|
2597
|
-
'post',
|
2598
|
-
'put',
|
2599
|
-
'patch'
|
2600
|
-
], function(method) {
|
2601
|
-
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
2602
|
-
return function(url, data, config) {
|
2603
|
-
return this.request(mergeConfig(config || {}, {
|
2604
|
-
method,
|
2605
|
-
headers: isForm ? {
|
2606
|
-
'Content-Type': 'multipart/form-data'
|
2607
|
-
} : {},
|
2608
|
-
url,
|
2609
|
-
data
|
2610
|
-
}));
|
2611
|
-
};
|
2612
|
-
}
|
2613
|
-
Axios_Axios.prototype[method] = generateHTTPMethod();
|
2614
|
-
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2615
|
-
});
|
2616
|
-
/* ESM default export */ const Axios = Axios_Axios;
|
2617
|
-
/**
|
2618
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2619
|
-
*
|
2620
|
-
* @param {Function} executor The executor function.
|
2621
|
-
*
|
2622
|
-
* @returns {CancelToken}
|
2623
|
-
*/ class CancelToken_CancelToken {
|
2624
|
-
constructor(executor){
|
2625
|
-
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
2626
|
-
let resolvePromise;
|
2627
|
-
this.promise = new Promise(function(resolve) {
|
2628
|
-
resolvePromise = resolve;
|
2629
|
-
});
|
2630
|
-
const token = this;
|
2631
|
-
// eslint-disable-next-line func-names
|
2632
|
-
this.promise.then((cancel)=>{
|
2633
|
-
if (!token._listeners) return;
|
2634
|
-
let i = token._listeners.length;
|
2635
|
-
while(i-- > 0)token._listeners[i](cancel);
|
2636
|
-
token._listeners = null;
|
2637
|
-
});
|
2638
|
-
// eslint-disable-next-line func-names
|
2639
|
-
this.promise.then = (onfulfilled)=>{
|
2640
|
-
let _resolve;
|
2641
|
-
// eslint-disable-next-line func-names
|
2642
|
-
const promise = new Promise((resolve)=>{
|
2643
|
-
token.subscribe(resolve);
|
2644
|
-
_resolve = resolve;
|
2645
|
-
}).then(onfulfilled);
|
2646
|
-
promise.cancel = function() {
|
2647
|
-
token.unsubscribe(_resolve);
|
2648
|
-
};
|
2649
|
-
return promise;
|
2650
|
-
};
|
2651
|
-
executor(function(message, config, request) {
|
2652
|
-
if (token.reason) // Cancellation has already been requested
|
2653
|
-
return;
|
2654
|
-
token.reason = new CanceledError(message, config, request);
|
2655
|
-
resolvePromise(token.reason);
|
2656
|
-
});
|
2657
|
-
}
|
2658
|
-
/**
|
2659
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2660
|
-
*/ throwIfRequested() {
|
2661
|
-
if (this.reason) throw this.reason;
|
2662
|
-
}
|
2663
|
-
/**
|
2664
|
-
* Subscribe to the cancel signal
|
2665
|
-
*/ subscribe(listener) {
|
2666
|
-
if (this.reason) {
|
2667
|
-
listener(this.reason);
|
2668
|
-
return;
|
2669
|
-
}
|
2670
|
-
if (this._listeners) this._listeners.push(listener);
|
2671
|
-
else this._listeners = [
|
2672
|
-
listener
|
2673
|
-
];
|
2674
|
-
}
|
2675
|
-
/**
|
2676
|
-
* Unsubscribe from the cancel signal
|
2677
|
-
*/ unsubscribe(listener) {
|
2678
|
-
if (!this._listeners) return;
|
2679
|
-
const index = this._listeners.indexOf(listener);
|
2680
|
-
if (-1 !== index) this._listeners.splice(index, 1);
|
2681
|
-
}
|
2682
|
-
toAbortSignal() {
|
2683
|
-
const controller = new AbortController();
|
2684
|
-
const abort = (err)=>{
|
2685
|
-
controller.abort(err);
|
2686
|
-
};
|
2687
|
-
this.subscribe(abort);
|
2688
|
-
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
2689
|
-
return controller.signal;
|
2690
|
-
}
|
2691
|
-
/**
|
2692
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2693
|
-
* cancels the `CancelToken`.
|
2694
|
-
*/ static source() {
|
2695
|
-
let cancel;
|
2696
|
-
const token = new CancelToken_CancelToken(function(c) {
|
2697
|
-
cancel = c;
|
2698
|
-
});
|
2699
|
-
return {
|
2700
|
-
token,
|
2701
|
-
cancel
|
2702
|
-
};
|
2703
|
-
}
|
2704
|
-
}
|
2705
|
-
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
2706
|
-
/**
|
2707
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2708
|
-
*
|
2709
|
-
* Common use case would be to use `Function.prototype.apply`.
|
2710
|
-
*
|
2711
|
-
* ```js
|
2712
|
-
* function f(x, y, z) {}
|
2713
|
-
* var args = [1, 2, 3];
|
2714
|
-
* f.apply(null, args);
|
2715
|
-
* ```
|
2716
|
-
*
|
2717
|
-
* With `spread` this example can be re-written.
|
2718
|
-
*
|
2719
|
-
* ```js
|
2720
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
2721
|
-
* ```
|
2722
|
-
*
|
2723
|
-
* @param {Function} callback
|
2724
|
-
*
|
2725
|
-
* @returns {Function}
|
2726
|
-
*/ function spread(callback) {
|
2727
|
-
return function(arr) {
|
2728
|
-
return callback.apply(null, arr);
|
2729
|
-
};
|
2730
|
-
}
|
2731
|
-
/**
|
2732
|
-
* Determines whether the payload is an error thrown by Axios
|
2733
|
-
*
|
2734
|
-
* @param {*} payload The value to test
|
2735
|
-
*
|
2736
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2737
|
-
*/ function isAxiosError(payload) {
|
2738
|
-
return utils.isObject(payload) && true === payload.isAxiosError;
|
2739
|
-
}
|
2740
|
-
const HttpStatusCode = {
|
2741
|
-
Continue: 100,
|
2742
|
-
SwitchingProtocols: 101,
|
2743
|
-
Processing: 102,
|
2744
|
-
EarlyHints: 103,
|
2745
|
-
Ok: 200,
|
2746
|
-
Created: 201,
|
2747
|
-
Accepted: 202,
|
2748
|
-
NonAuthoritativeInformation: 203,
|
2749
|
-
NoContent: 204,
|
2750
|
-
ResetContent: 205,
|
2751
|
-
PartialContent: 206,
|
2752
|
-
MultiStatus: 207,
|
2753
|
-
AlreadyReported: 208,
|
2754
|
-
ImUsed: 226,
|
2755
|
-
MultipleChoices: 300,
|
2756
|
-
MovedPermanently: 301,
|
2757
|
-
Found: 302,
|
2758
|
-
SeeOther: 303,
|
2759
|
-
NotModified: 304,
|
2760
|
-
UseProxy: 305,
|
2761
|
-
Unused: 306,
|
2762
|
-
TemporaryRedirect: 307,
|
2763
|
-
PermanentRedirect: 308,
|
2764
|
-
BadRequest: 400,
|
2765
|
-
Unauthorized: 401,
|
2766
|
-
PaymentRequired: 402,
|
2767
|
-
Forbidden: 403,
|
2768
|
-
NotFound: 404,
|
2769
|
-
MethodNotAllowed: 405,
|
2770
|
-
NotAcceptable: 406,
|
2771
|
-
ProxyAuthenticationRequired: 407,
|
2772
|
-
RequestTimeout: 408,
|
2773
|
-
Conflict: 409,
|
2774
|
-
Gone: 410,
|
2775
|
-
LengthRequired: 411,
|
2776
|
-
PreconditionFailed: 412,
|
2777
|
-
PayloadTooLarge: 413,
|
2778
|
-
UriTooLong: 414,
|
2779
|
-
UnsupportedMediaType: 415,
|
2780
|
-
RangeNotSatisfiable: 416,
|
2781
|
-
ExpectationFailed: 417,
|
2782
|
-
ImATeapot: 418,
|
2783
|
-
MisdirectedRequest: 421,
|
2784
|
-
UnprocessableEntity: 422,
|
2785
|
-
Locked: 423,
|
2786
|
-
FailedDependency: 424,
|
2787
|
-
TooEarly: 425,
|
2788
|
-
UpgradeRequired: 426,
|
2789
|
-
PreconditionRequired: 428,
|
2790
|
-
TooManyRequests: 429,
|
2791
|
-
RequestHeaderFieldsTooLarge: 431,
|
2792
|
-
UnavailableForLegalReasons: 451,
|
2793
|
-
InternalServerError: 500,
|
2794
|
-
NotImplemented: 501,
|
2795
|
-
BadGateway: 502,
|
2796
|
-
ServiceUnavailable: 503,
|
2797
|
-
GatewayTimeout: 504,
|
2798
|
-
HttpVersionNotSupported: 505,
|
2799
|
-
VariantAlsoNegotiates: 506,
|
2800
|
-
InsufficientStorage: 507,
|
2801
|
-
LoopDetected: 508,
|
2802
|
-
NotExtended: 510,
|
2803
|
-
NetworkAuthenticationRequired: 511
|
2804
|
-
};
|
2805
|
-
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
2806
|
-
HttpStatusCode[value] = key;
|
2807
|
-
});
|
2808
|
-
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
2809
|
-
/**
|
2810
|
-
* Create an instance of Axios
|
2811
|
-
*
|
2812
|
-
* @param {Object} defaultConfig The default config for the instance
|
2813
|
-
*
|
2814
|
-
* @returns {Axios} A new instance of Axios
|
2815
|
-
*/ function createInstance(defaultConfig) {
|
2816
|
-
const context = new Axios(defaultConfig);
|
2817
|
-
const instance = bind(Axios.prototype.request, context);
|
2818
|
-
// Copy axios.prototype to instance
|
2819
|
-
utils.extend(instance, Axios.prototype, context, {
|
2820
|
-
allOwnKeys: true
|
2821
|
-
});
|
2822
|
-
// Copy context to instance
|
2823
|
-
utils.extend(instance, context, null, {
|
2824
|
-
allOwnKeys: true
|
2825
|
-
});
|
2826
|
-
// Factory for creating new instances
|
2827
|
-
instance.create = function(instanceConfig) {
|
2828
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2829
|
-
};
|
2830
|
-
return instance;
|
2831
|
-
}
|
2832
|
-
// Create the default instance to be exported
|
2833
|
-
const axios = createInstance(defaults);
|
2834
|
-
// Expose Axios class to allow class inheritance
|
2835
|
-
axios.Axios = Axios;
|
2836
|
-
// Expose Cancel & CancelToken
|
2837
|
-
axios.CanceledError = CanceledError;
|
2838
|
-
axios.CancelToken = CancelToken;
|
2839
|
-
axios.isCancel = isCancel;
|
2840
|
-
axios.VERSION = VERSION;
|
2841
|
-
axios.toFormData = toFormData;
|
2842
|
-
// Expose AxiosError class
|
2843
|
-
axios.AxiosError = core_AxiosError;
|
2844
|
-
// alias for CanceledError for backward compatibility
|
2845
|
-
axios.Cancel = axios.CanceledError;
|
2846
|
-
// Expose all/spread
|
2847
|
-
axios.all = function(promises) {
|
2848
|
-
return Promise.all(promises);
|
2849
|
-
};
|
2850
|
-
axios.spread = spread;
|
2851
|
-
// Expose isAxiosError
|
2852
|
-
axios.isAxiosError = isAxiosError;
|
2853
|
-
// Expose mergeConfig
|
2854
|
-
axios.mergeConfig = mergeConfig;
|
2855
|
-
axios.AxiosHeaders = AxiosHeaders;
|
2856
|
-
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2857
|
-
axios.getAdapter = adapters_adapters.getAdapter;
|
2858
|
-
axios.HttpStatusCode = helpers_HttpStatusCode;
|
2859
|
-
axios.default = axios;
|
2860
|
-
// this module should only have a default export
|
2861
|
-
/* ESM default export */ const lib_axios = axios;
|
2862
|
-
// This module is intended to unwrap Axios default export as named.
|
2863
|
-
// Keep top-level export same with static properties
|
2864
|
-
// so that it can keep same with es module or cjs
|
2865
|
-
const { Axios: axios_Axios, AxiosError: axios_AxiosError, CanceledError: axios_CanceledError, isCancel: axios_isCancel, CancelToken: axios_CancelToken, VERSION: axios_VERSION, all: axios_all, Cancel, isAxiosError: axios_isAxiosError, spread: axios_spread, toFormData: axios_toFormData, AxiosHeaders: axios_AxiosHeaders, HttpStatusCode: axios_HttpStatusCode, formToJSON, getAdapter, mergeConfig: axios_mergeConfig } = lib_axios;
|
2866
|
-
// EXTERNAL MODULE: os (ignored)
|
2867
|
-
var os_ignored_ = __webpack_require__("?e2b1");
|
2868
|
-
// EXTERNAL MODULE: crypto (ignored)
|
2869
|
-
__webpack_require__("?c628");
|
2870
|
-
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
2871
|
-
__webpack_require__("?9452");
|
2872
|
-
class APIResource {
|
2873
|
-
constructor(client){
|
2874
|
-
this._client = client;
|
2875
|
-
}
|
2876
|
-
}
|
2877
|
-
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
2878
|
-
/**
|
2879
|
-
* Create a new agent. | 调用接口创建一个新的智能体。
|
2880
|
-
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
2881
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
2882
|
-
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
2883
|
-
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
2884
|
-
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
2885
|
-
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
2886
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2887
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2888
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2889
|
-
* @returns Information about the created bot. | 创建的 Bot 信息。
|
2890
|
-
*/ async create(params, options) {
|
2891
|
-
const apiUrl = '/v1/bot/create';
|
2892
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2893
|
-
return result.data;
|
2894
|
-
}
|
2895
|
-
/**
|
2896
|
-
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
2897
|
-
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
2898
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
2899
|
-
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
2900
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
2901
|
-
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
2902
|
-
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
2903
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2904
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2905
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2906
|
-
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
2907
|
-
* @returns Undefined | 无返回值
|
2908
|
-
*/ async update(params, options) {
|
2909
|
-
const apiUrl = '/v1/bot/update';
|
2910
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2911
|
-
return result.data;
|
2912
|
-
}
|
2913
|
-
/**
|
2914
|
-
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
2915
|
-
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
2916
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
2917
|
-
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
2918
|
-
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
2919
|
-
* @param params.page_size - Optional Pagination size. | 分页大小。
|
2920
|
-
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
2921
|
-
* @returns List of published bots. | 已发布的 Bot 列表。
|
2922
|
-
*/ async list(params, options) {
|
2923
|
-
const apiUrl = '/v1/space/published_bots_list';
|
2924
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2925
|
-
return result.data;
|
2926
|
-
}
|
2927
|
-
/**
|
2928
|
-
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
2929
|
-
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
2930
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
2931
|
-
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
2932
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
2933
|
-
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
2934
|
-
* @returns Undefined | 无返回值
|
2935
|
-
*/ async publish(params, options) {
|
2936
|
-
const apiUrl = '/v1/bot/publish';
|
2937
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2938
|
-
return result.data;
|
2939
|
-
}
|
2940
|
-
/**
|
2941
|
-
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
2942
|
-
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
2943
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
2944
|
-
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
2945
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
2946
|
-
* @returns Information about the bot. | Bot 的配置信息。
|
2947
|
-
*/ async retrieve(params, options) {
|
2948
|
-
const apiUrl = '/v1/bot/get_online_info';
|
2949
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2950
|
-
return result.data;
|
2951
|
-
}
|
2952
|
-
}
|
2953
|
-
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
2954
|
-
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
2955
|
-
try {
|
2956
|
-
return JSON.parse(jsonString);
|
2957
|
-
} catch (error) {
|
2958
|
-
return defaultValue;
|
2959
|
-
}
|
2960
|
-
}
|
2961
|
-
function sleep(ms) {
|
2962
|
-
return new Promise((resolve)=>{
|
2963
|
-
setTimeout(resolve, ms);
|
2964
|
-
});
|
2965
|
-
}
|
2966
|
-
function isBrowser() {
|
2967
|
-
return 'undefined' != typeof window;
|
2968
|
-
}
|
2969
|
-
function esm_isPlainObject(obj) {
|
2970
|
-
if ('object' != typeof obj || null === obj) return false;
|
2971
|
-
const proto = Object.getPrototypeOf(obj);
|
2972
|
-
if (null === proto) return true;
|
2973
|
-
let baseProto = proto;
|
2974
|
-
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
2975
|
-
return proto === baseProto;
|
2976
|
-
}
|
2977
|
-
function esm_mergeConfig() {
|
2978
|
-
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
2979
|
-
return objects.reduce((result, obj)=>{
|
2980
|
-
if (void 0 === obj) return result || {};
|
2981
|
-
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
2982
|
-
if (esm_isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = esm_mergeConfig(result[key] || {}, obj[key]);
|
2983
|
-
else result[key] = obj[key];
|
2984
|
-
}
|
2985
|
-
return result;
|
2986
|
-
}, {});
|
2987
|
-
}
|
2988
|
-
function isPersonalAccessToken(token) {
|
2989
|
-
return null == token ? void 0 : token.startsWith('pat_');
|
2990
|
-
}
|
2991
|
-
/* eslint-disable max-params */ class CozeError extends Error {
|
2992
|
-
}
|
2993
|
-
class APIError extends CozeError {
|
2994
|
-
static makeMessage(status, errorBody, message, headers) {
|
2995
|
-
if (!errorBody && message) return message;
|
2996
|
-
if (errorBody) {
|
2997
|
-
const list = [];
|
2998
|
-
const { code, msg, error } = errorBody;
|
2999
|
-
if (code) list.push(`code: ${code}`);
|
3000
|
-
if (msg) list.push(`msg: ${msg}`);
|
3001
|
-
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
3002
|
-
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
3003
|
-
if (logId) list.push(`logid: ${logId}`);
|
3004
|
-
const help_doc = null == error ? void 0 : error.help_doc;
|
3005
|
-
if (help_doc) list.push(`help doc: ${help_doc}`);
|
3006
|
-
return list.join(', ');
|
3007
|
-
}
|
3008
|
-
if (status) return `http status code: ${status} (no body)`;
|
3009
|
-
return '(no status code or body)';
|
3010
|
-
}
|
3011
|
-
static generate(status, errorResponse, message, headers) {
|
3012
|
-
if (!status) return new APIConnectionError({
|
3013
|
-
cause: castToError(errorResponse)
|
3014
|
-
});
|
3015
|
-
const error = errorResponse;
|
3016
|
-
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
3017
|
-
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
3018
|
-
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
3019
|
-
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
3020
|
-
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
3021
|
-
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
3022
|
-
if (408 === status) return new TimeoutError(status, error, message, headers);
|
3023
|
-
if (502 === status) return new GatewayError(status, error, message, headers);
|
3024
|
-
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
3025
|
-
return new APIError(status, error, message, headers);
|
3026
|
-
}
|
3027
|
-
constructor(status, error, message, headers){
|
3028
|
-
var _error_error, _error_error1;
|
3029
|
-
super(`${APIError.makeMessage(status, error, message, headers)}`);
|
3030
|
-
this.status = status;
|
3031
|
-
this.headers = headers;
|
3032
|
-
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
3033
|
-
// this.error = error;
|
3034
|
-
this.code = null == error ? void 0 : error.code;
|
3035
|
-
this.msg = null == error ? void 0 : error.msg;
|
3036
|
-
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
3037
|
-
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
3038
|
-
this.rawError = error;
|
3039
|
-
}
|
3040
|
-
}
|
3041
|
-
class APIConnectionError extends APIError {
|
3042
|
-
constructor({ message, cause }){
|
3043
|
-
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
3044
|
-
// if (cause) {
|
3045
|
-
// this.cause = cause;
|
3046
|
-
// }
|
3047
|
-
}
|
3048
|
-
}
|
3049
|
-
class APIUserAbortError extends APIError {
|
3050
|
-
constructor(message){
|
3051
|
-
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
3052
|
-
}
|
3053
|
-
}
|
3054
|
-
class BadRequestError extends APIError {
|
3055
|
-
constructor(...args){
|
3056
|
-
super(...args), this.name = 'BadRequestError', this.status = 400;
|
3057
|
-
}
|
3058
|
-
}
|
3059
|
-
class AuthenticationError extends APIError {
|
3060
|
-
constructor(...args){
|
3061
|
-
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
3062
|
-
}
|
3063
|
-
}
|
3064
|
-
class PermissionDeniedError extends APIError {
|
3065
|
-
constructor(...args){
|
3066
|
-
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
3067
|
-
}
|
3068
|
-
}
|
3069
|
-
class NotFoundError extends APIError {
|
3070
|
-
constructor(...args){
|
3071
|
-
super(...args), this.name = 'NotFoundError', this.status = 404;
|
3072
|
-
}
|
3073
|
-
}
|
3074
|
-
class TimeoutError extends APIError {
|
3075
|
-
constructor(...args){
|
3076
|
-
super(...args), this.name = 'TimeoutError', this.status = 408;
|
3077
|
-
}
|
3078
|
-
}
|
3079
|
-
class RateLimitError extends APIError {
|
3080
|
-
constructor(...args){
|
3081
|
-
super(...args), this.name = 'RateLimitError', this.status = 429;
|
3082
|
-
}
|
3083
|
-
}
|
3084
|
-
class InternalServerError extends APIError {
|
3085
|
-
constructor(...args){
|
3086
|
-
super(...args), this.name = 'InternalServerError', this.status = 500;
|
3087
|
-
}
|
3088
|
-
}
|
3089
|
-
class GatewayError extends APIError {
|
3090
|
-
constructor(...args){
|
3091
|
-
super(...args), this.name = 'GatewayError', this.status = 502;
|
3092
|
-
}
|
3093
|
-
}
|
3094
|
-
const castToError = (err)=>{
|
3095
|
-
if (err instanceof Error) return err;
|
3096
|
-
return new Error(err);
|
3097
|
-
};
|
3098
|
-
class Messages extends APIResource {
|
3099
|
-
/**
|
3100
|
-
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
3101
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
3102
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
3103
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3104
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3105
|
-
* @returns An array of chat messages. | 对话消息数组。
|
3106
|
-
*/ async list(conversation_id, chat_id, options) {
|
3107
|
-
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3108
|
-
const result = await this._client.get(apiUrl, void 0, false, options);
|
3109
|
-
return result.data;
|
3110
|
-
}
|
3111
|
-
}
|
3112
|
-
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
3113
|
-
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
3114
|
-
...i,
|
3115
|
-
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
3116
|
-
}));
|
3117
|
-
class Chat extends APIResource {
|
3118
|
-
/**
|
3119
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3120
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3121
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3122
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3123
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3124
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3125
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3126
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
3127
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3128
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3129
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3130
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3131
|
-
* @returns The data of the created chat. | 创建的对话数据。
|
3132
|
-
*/ async create(params, options) {
|
3133
|
-
if (!params.user_id) params.user_id = uuid();
|
3134
|
-
const { conversation_id, ...rest } = params;
|
3135
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3136
|
-
const payload = {
|
3137
|
-
...rest,
|
3138
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3139
|
-
stream: false
|
3140
|
-
};
|
3141
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3142
|
-
return result.data;
|
3143
|
-
}
|
3144
|
-
/**
|
3145
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3146
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3147
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3148
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3149
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3150
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3151
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3152
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3153
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3154
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3155
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3156
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3157
|
-
* @returns
|
3158
|
-
*/ async createAndPoll(params, options) {
|
3159
|
-
if (!params.user_id) params.user_id = uuid();
|
3160
|
-
const { conversation_id, ...rest } = params;
|
3161
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3162
|
-
const payload = {
|
3163
|
-
...rest,
|
3164
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3165
|
-
stream: false
|
3166
|
-
};
|
3167
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3168
|
-
const chatId = result.data.id;
|
3169
|
-
const conversationId = result.data.conversation_id;
|
3170
|
-
let chat;
|
3171
|
-
while(true){
|
3172
|
-
await sleep(100);
|
3173
|
-
chat = await this.retrieve(conversationId, chatId);
|
3174
|
-
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
3175
|
-
}
|
3176
|
-
const messageList = await this.messages.list(conversationId, chatId);
|
3177
|
-
return {
|
3178
|
-
chat,
|
3179
|
-
messages: messageList
|
3180
|
-
};
|
3181
|
-
}
|
3182
|
-
/**
|
3183
|
-
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
3184
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3185
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3186
|
-
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
3187
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3188
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3189
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3190
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3191
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3192
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3193
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3194
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3195
|
-
* @returns A stream of chat data. | 对话数据流。
|
3196
|
-
*/ async *stream(params, options) {
|
3197
|
-
if (!params.user_id) params.user_id = uuid();
|
3198
|
-
const { conversation_id, ...rest } = params;
|
3199
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3200
|
-
const payload = {
|
3201
|
-
...rest,
|
3202
|
-
additional_messages: handleAdditionalMessages(params.additional_messages),
|
3203
|
-
stream: true
|
3204
|
-
};
|
3205
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
3206
|
-
for await (const message of result)if ("done" === message.event) {
|
3207
|
-
const ret = {
|
3208
|
-
event: message.event,
|
3209
|
-
data: '[DONE]'
|
3210
|
-
};
|
3211
|
-
yield ret;
|
3212
|
-
} else try {
|
3213
|
-
const ret = {
|
3214
|
-
event: message.event,
|
3215
|
-
data: JSON.parse(message.data)
|
3216
|
-
};
|
3217
|
-
yield ret;
|
3218
|
-
} catch (error) {
|
3219
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3220
|
-
}
|
3221
|
-
}
|
3222
|
-
/**
|
3223
|
-
* Get the detailed information of the chat. | 查看对话的详细信息。
|
3224
|
-
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
3225
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
3226
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3227
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3228
|
-
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
3229
|
-
*/ async retrieve(conversation_id, chat_id, options) {
|
3230
|
-
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3231
|
-
const result = await this._client.post(apiUrl, void 0, false, options);
|
3232
|
-
return result.data;
|
3233
|
-
}
|
3234
|
-
/**
|
3235
|
-
* Cancel a chat session. | 取消对话会话。
|
3236
|
-
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
3237
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
3238
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3239
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3240
|
-
* @returns The data of the canceled chat. | 取消的对话数据。
|
3241
|
-
*/ async cancel(conversation_id, chat_id, options) {
|
3242
|
-
const apiUrl = '/v3/chat/cancel';
|
3243
|
-
const payload = {
|
3244
|
-
conversation_id,
|
3245
|
-
chat_id
|
3246
|
-
};
|
3247
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3248
|
-
return result.data;
|
3249
|
-
}
|
3250
|
-
/**
|
3251
|
-
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
3252
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
3253
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
3254
|
-
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
3255
|
-
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
3256
|
-
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
3257
|
-
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
3258
|
-
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
3259
|
-
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
3260
|
-
*/ async *submitToolOutputs(params, options) {
|
3261
|
-
const { conversation_id, chat_id, ...rest } = params;
|
3262
|
-
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
3263
|
-
const payload = {
|
3264
|
-
...rest
|
3265
|
-
};
|
3266
|
-
if (false === params.stream) {
|
3267
|
-
const response = await this._client.post(apiUrl, payload, false, options);
|
3268
|
-
return response.data;
|
3055
|
+
} else err.stack = stack;
|
3056
|
+
} catch (e) {
|
3057
|
+
// ignore the case where "stack" is an un-writable property
|
3058
|
+
}
|
3059
|
+
}
|
3060
|
+
throw err;
|
3269
3061
|
}
|
3270
|
-
|
3271
|
-
|
3272
|
-
|
3273
|
-
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3062
|
+
}
|
3063
|
+
_request(configOrUrl, config) {
|
3064
|
+
/*eslint no-param-reassign:0*/ // Allow for axios('example/url'[, config]) a la fetch API
|
3065
|
+
if ('string' == typeof configOrUrl) {
|
3066
|
+
config = config || {};
|
3067
|
+
config.url = configOrUrl;
|
3068
|
+
} else config = configOrUrl || {};
|
3069
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
3070
|
+
const { transitional, paramsSerializer, headers } = config;
|
3071
|
+
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
3072
|
+
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
3073
|
+
forcedJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
3074
|
+
clarifyTimeoutError: Axios_validators.transitional(Axios_validators.boolean)
|
3075
|
+
}, false);
|
3076
|
+
if (null != paramsSerializer) {
|
3077
|
+
if (utils.isFunction(paramsSerializer)) config.paramsSerializer = {
|
3078
|
+
serialize: paramsSerializer
|
3079
|
+
};
|
3080
|
+
else helpers_validator.assertOptions(paramsSerializer, {
|
3081
|
+
encode: Axios_validators.function,
|
3082
|
+
serialize: Axios_validators.function
|
3083
|
+
}, true);
|
3084
|
+
}
|
3085
|
+
// Set config.method
|
3086
|
+
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
3087
|
+
// Flatten headers
|
3088
|
+
let contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
|
3089
|
+
headers && utils.forEach([
|
3090
|
+
'delete',
|
3091
|
+
'get',
|
3092
|
+
'head',
|
3093
|
+
'post',
|
3094
|
+
'put',
|
3095
|
+
'patch',
|
3096
|
+
'common'
|
3097
|
+
], (method)=>{
|
3098
|
+
delete headers[method];
|
3099
|
+
});
|
3100
|
+
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
3101
|
+
// filter out skipped interceptors
|
3102
|
+
const requestInterceptorChain = [];
|
3103
|
+
let synchronousRequestInterceptors = true;
|
3104
|
+
this.interceptors.request.forEach(function(interceptor) {
|
3105
|
+
if ('function' == typeof interceptor.runWhen && false === interceptor.runWhen(config)) return;
|
3106
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
3107
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
3108
|
+
});
|
3109
|
+
const responseInterceptorChain = [];
|
3110
|
+
this.interceptors.response.forEach(function(interceptor) {
|
3111
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
3112
|
+
});
|
3113
|
+
let promise;
|
3114
|
+
let i = 0;
|
3115
|
+
let len;
|
3116
|
+
if (!synchronousRequestInterceptors) {
|
3117
|
+
const chain = [
|
3118
|
+
dispatchRequest.bind(this),
|
3119
|
+
void 0
|
3120
|
+
];
|
3121
|
+
chain.unshift.apply(chain, requestInterceptorChain);
|
3122
|
+
chain.push.apply(chain, responseInterceptorChain);
|
3123
|
+
len = chain.length;
|
3124
|
+
promise = Promise.resolve(config);
|
3125
|
+
while(i < len)promise = promise.then(chain[i++], chain[i++]);
|
3126
|
+
return promise;
|
3127
|
+
}
|
3128
|
+
len = requestInterceptorChain.length;
|
3129
|
+
let newConfig = config;
|
3130
|
+
i = 0;
|
3131
|
+
while(i < len){
|
3132
|
+
const onFulfilled = requestInterceptorChain[i++];
|
3133
|
+
const onRejected = requestInterceptorChain[i++];
|
3134
|
+
try {
|
3135
|
+
newConfig = onFulfilled(newConfig);
|
3284
3136
|
} catch (error) {
|
3285
|
-
|
3137
|
+
onRejected.call(this, error);
|
3138
|
+
break;
|
3286
3139
|
}
|
3287
3140
|
}
|
3141
|
+
try {
|
3142
|
+
promise = dispatchRequest.call(this, newConfig);
|
3143
|
+
} catch (error) {
|
3144
|
+
return Promise.reject(error);
|
3145
|
+
}
|
3146
|
+
i = 0;
|
3147
|
+
len = responseInterceptorChain.length;
|
3148
|
+
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
3149
|
+
return promise;
|
3288
3150
|
}
|
3289
|
-
|
3290
|
-
|
3151
|
+
getUri(config) {
|
3152
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
3153
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
3154
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
3291
3155
|
}
|
3292
3156
|
}
|
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
|
-
|
3321
|
-
|
3322
|
-
|
3323
|
-
|
3324
|
-
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
3325
|
-
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
3326
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
3327
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3328
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3329
|
-
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
3330
|
-
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
3331
|
-
* @param params.content - Optional The content of the message. | 消息的内容。
|
3332
|
-
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
3333
|
-
* @returns Information about the modified message. | 消息详情。
|
3334
|
-
*/ // eslint-disable-next-line max-params
|
3335
|
-
async update(conversation_id, message_id, params, options) {
|
3336
|
-
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3337
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3338
|
-
return response.message;
|
3339
|
-
}
|
3340
|
-
/**
|
3341
|
-
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
3342
|
-
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
3343
|
-
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
3344
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3345
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3346
|
-
* @returns Information about the message. | 消息详情。
|
3347
|
-
*/ async retrieve(conversation_id, message_id, options) {
|
3348
|
-
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3349
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3350
|
-
return response.data;
|
3157
|
+
// Provide aliases for supported request methods
|
3158
|
+
utils.forEach([
|
3159
|
+
'delete',
|
3160
|
+
'get',
|
3161
|
+
'head',
|
3162
|
+
'options'
|
3163
|
+
], function(method) {
|
3164
|
+
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
3165
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3166
|
+
method,
|
3167
|
+
url,
|
3168
|
+
data: (config || {}).data
|
3169
|
+
}));
|
3170
|
+
};
|
3171
|
+
});
|
3172
|
+
utils.forEach([
|
3173
|
+
'post',
|
3174
|
+
'put',
|
3175
|
+
'patch'
|
3176
|
+
], function(method) {
|
3177
|
+
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
3178
|
+
return function(url, data, config) {
|
3179
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3180
|
+
method,
|
3181
|
+
headers: isForm ? {
|
3182
|
+
'Content-Type': 'multipart/form-data'
|
3183
|
+
} : {},
|
3184
|
+
url,
|
3185
|
+
data
|
3186
|
+
}));
|
3187
|
+
};
|
3351
3188
|
}
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
|
3367
|
-
|
3189
|
+
Axios_Axios.prototype[method] = generateHTTPMethod();
|
3190
|
+
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
3191
|
+
});
|
3192
|
+
/* ESM default export */ const Axios = Axios_Axios;
|
3193
|
+
/**
|
3194
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
3195
|
+
*
|
3196
|
+
* @param {Function} executor The executor function.
|
3197
|
+
*
|
3198
|
+
* @returns {CancelToken}
|
3199
|
+
*/ class CancelToken_CancelToken {
|
3200
|
+
constructor(executor){
|
3201
|
+
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
3202
|
+
let resolvePromise;
|
3203
|
+
this.promise = new Promise(function(resolve) {
|
3204
|
+
resolvePromise = resolve;
|
3205
|
+
});
|
3206
|
+
const token = this;
|
3207
|
+
// eslint-disable-next-line func-names
|
3208
|
+
this.promise.then((cancel)=>{
|
3209
|
+
if (!token._listeners) return;
|
3210
|
+
let i = token._listeners.length;
|
3211
|
+
while(i-- > 0)token._listeners[i](cancel);
|
3212
|
+
token._listeners = null;
|
3213
|
+
});
|
3214
|
+
// eslint-disable-next-line func-names
|
3215
|
+
this.promise.then = (onfulfilled)=>{
|
3216
|
+
let _resolve;
|
3217
|
+
// eslint-disable-next-line func-names
|
3218
|
+
const promise = new Promise((resolve)=>{
|
3219
|
+
token.subscribe(resolve);
|
3220
|
+
_resolve = resolve;
|
3221
|
+
}).then(onfulfilled);
|
3222
|
+
promise.cancel = function() {
|
3223
|
+
token.unsubscribe(_resolve);
|
3224
|
+
};
|
3225
|
+
return promise;
|
3226
|
+
};
|
3227
|
+
executor(function(message, config, request) {
|
3228
|
+
if (token.reason) // Cancellation has already been requested
|
3229
|
+
return;
|
3230
|
+
token.reason = new CanceledError(message, config, request);
|
3231
|
+
resolvePromise(token.reason);
|
3232
|
+
});
|
3368
3233
|
}
|
3369
3234
|
/**
|
3370
|
-
*
|
3371
|
-
|
3372
|
-
|
3373
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3374
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3375
|
-
* @returns Details of the deleted message. | 已删除的消息详情。
|
3376
|
-
*/ async delete(conversation_id, message_id, options) {
|
3377
|
-
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3378
|
-
const response = await this._client.post(apiUrl, void 0, false, options);
|
3379
|
-
return response.data;
|
3235
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
3236
|
+
*/ throwIfRequested() {
|
3237
|
+
if (this.reason) throw this.reason;
|
3380
3238
|
}
|
3381
|
-
}
|
3382
|
-
class Conversations extends APIResource {
|
3383
3239
|
/**
|
3384
|
-
*
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3388
|
-
|
3389
|
-
|
3390
|
-
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3394
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3395
|
-
return response.data;
|
3240
|
+
* Subscribe to the cancel signal
|
3241
|
+
*/ subscribe(listener) {
|
3242
|
+
if (this.reason) {
|
3243
|
+
listener(this.reason);
|
3244
|
+
return;
|
3245
|
+
}
|
3246
|
+
if (this._listeners) this._listeners.push(listener);
|
3247
|
+
else this._listeners = [
|
3248
|
+
listener
|
3249
|
+
];
|
3396
3250
|
}
|
3397
3251
|
/**
|
3398
|
-
*
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3402
|
-
|
3403
|
-
*/ async retrieve(conversation_id, options) {
|
3404
|
-
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
3405
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3406
|
-
return response.data;
|
3252
|
+
* Unsubscribe from the cancel signal
|
3253
|
+
*/ unsubscribe(listener) {
|
3254
|
+
if (!this._listeners) return;
|
3255
|
+
const index = this._listeners.indexOf(listener);
|
3256
|
+
if (-1 !== index) this._listeners.splice(index, 1);
|
3407
3257
|
}
|
3408
|
-
|
3409
|
-
|
3410
|
-
|
3411
|
-
|
3412
|
-
|
3413
|
-
|
3414
|
-
|
3415
|
-
|
3416
|
-
const apiUrl = '/v1/conversations';
|
3417
|
-
const response = await this._client.get(apiUrl, params, false, options);
|
3418
|
-
return response.data;
|
3258
|
+
toAbortSignal() {
|
3259
|
+
const controller = new AbortController();
|
3260
|
+
const abort = (err)=>{
|
3261
|
+
controller.abort(err);
|
3262
|
+
};
|
3263
|
+
this.subscribe(abort);
|
3264
|
+
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
3265
|
+
return controller.signal;
|
3419
3266
|
}
|
3420
3267
|
/**
|
3421
|
-
*
|
3422
|
-
*
|
3423
|
-
|
3424
|
-
|
3425
|
-
const
|
3426
|
-
|
3427
|
-
|
3428
|
-
|
3429
|
-
|
3430
|
-
|
3268
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
3269
|
+
* cancels the `CancelToken`.
|
3270
|
+
*/ static source() {
|
3271
|
+
let cancel;
|
3272
|
+
const token = new CancelToken_CancelToken(function(c) {
|
3273
|
+
cancel = c;
|
3274
|
+
});
|
3275
|
+
return {
|
3276
|
+
token,
|
3277
|
+
cancel
|
3278
|
+
};
|
3431
3279
|
}
|
3432
3280
|
}
|
3281
|
+
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
3282
|
+
/**
|
3283
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
3284
|
+
*
|
3285
|
+
* Common use case would be to use `Function.prototype.apply`.
|
3286
|
+
*
|
3287
|
+
* ```js
|
3288
|
+
* function f(x, y, z) {}
|
3289
|
+
* var args = [1, 2, 3];
|
3290
|
+
* f.apply(null, args);
|
3291
|
+
* ```
|
3292
|
+
*
|
3293
|
+
* With `spread` this example can be re-written.
|
3294
|
+
*
|
3295
|
+
* ```js
|
3296
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
3297
|
+
* ```
|
3298
|
+
*
|
3299
|
+
* @param {Function} callback
|
3300
|
+
*
|
3301
|
+
* @returns {Function}
|
3302
|
+
*/ function spread(callback) {
|
3303
|
+
return function(arr) {
|
3304
|
+
return callback.apply(null, arr);
|
3305
|
+
};
|
3306
|
+
}
|
3307
|
+
/**
|
3308
|
+
* Determines whether the payload is an error thrown by Axios
|
3309
|
+
*
|
3310
|
+
* @param {*} payload The value to test
|
3311
|
+
*
|
3312
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
3313
|
+
*/ function isAxiosError(payload) {
|
3314
|
+
return utils.isObject(payload) && true === payload.isAxiosError;
|
3315
|
+
}
|
3316
|
+
const HttpStatusCode = {
|
3317
|
+
Continue: 100,
|
3318
|
+
SwitchingProtocols: 101,
|
3319
|
+
Processing: 102,
|
3320
|
+
EarlyHints: 103,
|
3321
|
+
Ok: 200,
|
3322
|
+
Created: 201,
|
3323
|
+
Accepted: 202,
|
3324
|
+
NonAuthoritativeInformation: 203,
|
3325
|
+
NoContent: 204,
|
3326
|
+
ResetContent: 205,
|
3327
|
+
PartialContent: 206,
|
3328
|
+
MultiStatus: 207,
|
3329
|
+
AlreadyReported: 208,
|
3330
|
+
ImUsed: 226,
|
3331
|
+
MultipleChoices: 300,
|
3332
|
+
MovedPermanently: 301,
|
3333
|
+
Found: 302,
|
3334
|
+
SeeOther: 303,
|
3335
|
+
NotModified: 304,
|
3336
|
+
UseProxy: 305,
|
3337
|
+
Unused: 306,
|
3338
|
+
TemporaryRedirect: 307,
|
3339
|
+
PermanentRedirect: 308,
|
3340
|
+
BadRequest: 400,
|
3341
|
+
Unauthorized: 401,
|
3342
|
+
PaymentRequired: 402,
|
3343
|
+
Forbidden: 403,
|
3344
|
+
NotFound: 404,
|
3345
|
+
MethodNotAllowed: 405,
|
3346
|
+
NotAcceptable: 406,
|
3347
|
+
ProxyAuthenticationRequired: 407,
|
3348
|
+
RequestTimeout: 408,
|
3349
|
+
Conflict: 409,
|
3350
|
+
Gone: 410,
|
3351
|
+
LengthRequired: 411,
|
3352
|
+
PreconditionFailed: 412,
|
3353
|
+
PayloadTooLarge: 413,
|
3354
|
+
UriTooLong: 414,
|
3355
|
+
UnsupportedMediaType: 415,
|
3356
|
+
RangeNotSatisfiable: 416,
|
3357
|
+
ExpectationFailed: 417,
|
3358
|
+
ImATeapot: 418,
|
3359
|
+
MisdirectedRequest: 421,
|
3360
|
+
UnprocessableEntity: 422,
|
3361
|
+
Locked: 423,
|
3362
|
+
FailedDependency: 424,
|
3363
|
+
TooEarly: 425,
|
3364
|
+
UpgradeRequired: 426,
|
3365
|
+
PreconditionRequired: 428,
|
3366
|
+
TooManyRequests: 429,
|
3367
|
+
RequestHeaderFieldsTooLarge: 431,
|
3368
|
+
UnavailableForLegalReasons: 451,
|
3369
|
+
InternalServerError: 500,
|
3370
|
+
NotImplemented: 501,
|
3371
|
+
BadGateway: 502,
|
3372
|
+
ServiceUnavailable: 503,
|
3373
|
+
GatewayTimeout: 504,
|
3374
|
+
HttpVersionNotSupported: 505,
|
3375
|
+
VariantAlsoNegotiates: 506,
|
3376
|
+
InsufficientStorage: 507,
|
3377
|
+
LoopDetected: 508,
|
3378
|
+
NotExtended: 510,
|
3379
|
+
NetworkAuthenticationRequired: 511
|
3380
|
+
};
|
3381
|
+
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
3382
|
+
HttpStatusCode[value] = key;
|
3383
|
+
});
|
3384
|
+
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
3385
|
+
/**
|
3386
|
+
* Create an instance of Axios
|
3387
|
+
*
|
3388
|
+
* @param {Object} defaultConfig The default config for the instance
|
3389
|
+
*
|
3390
|
+
* @returns {Axios} A new instance of Axios
|
3391
|
+
*/ function createInstance(defaultConfig) {
|
3392
|
+
const context = new Axios(defaultConfig);
|
3393
|
+
const instance = bind(Axios.prototype.request, context);
|
3394
|
+
// Copy axios.prototype to instance
|
3395
|
+
utils.extend(instance, Axios.prototype, context, {
|
3396
|
+
allOwnKeys: true
|
3397
|
+
});
|
3398
|
+
// Copy context to instance
|
3399
|
+
utils.extend(instance, context, null, {
|
3400
|
+
allOwnKeys: true
|
3401
|
+
});
|
3402
|
+
// Factory for creating new instances
|
3403
|
+
instance.create = function(instanceConfig) {
|
3404
|
+
return createInstance(mergeConfig_mergeConfig(defaultConfig, instanceConfig));
|
3405
|
+
};
|
3406
|
+
return instance;
|
3407
|
+
}
|
3408
|
+
// Create the default instance to be exported
|
3409
|
+
const axios = createInstance(defaults);
|
3410
|
+
// Expose Axios class to allow class inheritance
|
3411
|
+
axios.Axios = Axios;
|
3412
|
+
// Expose Cancel & CancelToken
|
3413
|
+
axios.CanceledError = CanceledError;
|
3414
|
+
axios.CancelToken = CancelToken;
|
3415
|
+
axios.isCancel = isCancel;
|
3416
|
+
axios.VERSION = VERSION;
|
3417
|
+
axios.toFormData = toFormData;
|
3418
|
+
// Expose AxiosError class
|
3419
|
+
axios.AxiosError = core_AxiosError;
|
3420
|
+
// alias for CanceledError for backward compatibility
|
3421
|
+
axios.Cancel = axios.CanceledError;
|
3422
|
+
// Expose all/spread
|
3423
|
+
axios.all = function(promises) {
|
3424
|
+
return Promise.all(promises);
|
3425
|
+
};
|
3426
|
+
axios.spread = spread;
|
3427
|
+
// Expose isAxiosError
|
3428
|
+
axios.isAxiosError = isAxiosError;
|
3429
|
+
// Expose mergeConfig
|
3430
|
+
axios.mergeConfig = mergeConfig_mergeConfig;
|
3431
|
+
axios.AxiosHeaders = AxiosHeaders;
|
3432
|
+
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
3433
|
+
axios.getAdapter = adapters_adapters.getAdapter;
|
3434
|
+
axios.HttpStatusCode = helpers_HttpStatusCode;
|
3435
|
+
axios.default = axios;
|
3436
|
+
// this module should only have a default export
|
3437
|
+
/* ESM default export */ const lib_axios = axios;
|
3438
|
+
// This module is intended to unwrap Axios default export as named.
|
3439
|
+
// Keep top-level export same with static properties
|
3440
|
+
// so that it can keep same with es module or cjs
|
3441
|
+
const { Axios: axios_Axios, AxiosError: axios_AxiosError, CanceledError: axios_CanceledError, isCancel: axios_isCancel, CancelToken: axios_CancelToken, VERSION: axios_VERSION, all: axios_all, Cancel, isAxiosError: axios_isAxiosError, spread: axios_spread, toFormData: axios_toFormData, AxiosHeaders: axios_AxiosHeaders, HttpStatusCode: axios_HttpStatusCode, formToJSON, getAdapter, mergeConfig: axios_mergeConfig } = lib_axios;
|
3433
3442
|
class Files extends APIResource {
|
3434
3443
|
/**
|
3435
3444
|
* Upload files to Coze platform. | 调用接口上传文件到扣子。
|
@@ -3592,7 +3601,7 @@
|
|
3592
3601
|
* @returns ListDocumentData | 知识库文件列表
|
3593
3602
|
*/ list(params, options) {
|
3594
3603
|
const apiUrl = '/open_api/knowledge/document/list';
|
3595
|
-
const response = this._client.get(apiUrl, params, false,
|
3604
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3596
3605
|
headers: documents_headers
|
3597
3606
|
}));
|
3598
3607
|
return response;
|
@@ -3610,7 +3619,7 @@
|
|
3610
3619
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3611
3620
|
*/ async create(params, options) {
|
3612
3621
|
const apiUrl = '/open_api/knowledge/document/create';
|
3613
|
-
const response = await this._client.post(apiUrl, params, false,
|
3622
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3614
3623
|
headers: documents_headers
|
3615
3624
|
}));
|
3616
3625
|
return response.document_infos;
|
@@ -3626,7 +3635,7 @@
|
|
3626
3635
|
* @returns void | 无返回
|
3627
3636
|
*/ async delete(params, options) {
|
3628
3637
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3629
|
-
await this._client.post(apiUrl, params, false,
|
3638
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3630
3639
|
headers: documents_headers
|
3631
3640
|
}));
|
3632
3641
|
}
|
@@ -3642,7 +3651,7 @@
|
|
3642
3651
|
* @returns void | 无返回
|
3643
3652
|
*/ async update(params, options) {
|
3644
3653
|
const apiUrl = '/open_api/knowledge/document/update';
|
3645
|
-
await this._client.post(apiUrl, params, false,
|
3654
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3646
3655
|
headers: documents_headers
|
3647
3656
|
}));
|
3648
3657
|
}
|
@@ -3670,7 +3679,7 @@
|
|
3670
3679
|
* @returns ListDocumentData | 知识库文件列表
|
3671
3680
|
*/ list(params, options) {
|
3672
3681
|
const apiUrl = '/open_api/knowledge/document/list';
|
3673
|
-
const response = this._client.get(apiUrl, params, false,
|
3682
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3674
3683
|
headers: documents_documents_headers
|
3675
3684
|
}));
|
3676
3685
|
return response;
|
@@ -3686,7 +3695,7 @@
|
|
3686
3695
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3687
3696
|
*/ async create(params, options) {
|
3688
3697
|
const apiUrl = '/open_api/knowledge/document/create';
|
3689
|
-
const response = await this._client.post(apiUrl, params, false,
|
3698
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3690
3699
|
headers: documents_documents_headers
|
3691
3700
|
}));
|
3692
3701
|
return response.document_infos;
|
@@ -3700,7 +3709,7 @@
|
|
3700
3709
|
* @returns void | 无返回
|
3701
3710
|
*/ async delete(params, options) {
|
3702
3711
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3703
|
-
await this._client.post(apiUrl, params, false,
|
3712
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3704
3713
|
headers: documents_documents_headers
|
3705
3714
|
}));
|
3706
3715
|
}
|
@@ -3714,7 +3723,7 @@
|
|
3714
3723
|
* @returns void | 无返回
|
3715
3724
|
*/ async update(params, options) {
|
3716
3725
|
const apiUrl = '/open_api/knowledge/document/update';
|
3717
|
-
await this._client.post(apiUrl, params, false,
|
3726
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3718
3727
|
headers: documents_documents_headers
|
3719
3728
|
}));
|
3720
3729
|
}
|
@@ -3778,7 +3787,7 @@
|
|
3778
3787
|
* @returns Speech synthesis data
|
3779
3788
|
*/ async create(params, options) {
|
3780
3789
|
const apiUrl = '/v1/audio/speech';
|
3781
|
-
const response = await this._client.post(apiUrl, params, false,
|
3790
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3782
3791
|
responseType: 'arraybuffer'
|
3783
3792
|
}));
|
3784
3793
|
return response;
|
@@ -3791,23 +3800,26 @@
|
|
3791
3800
|
return response.data;
|
3792
3801
|
}
|
3793
3802
|
}
|
3794
|
-
class
|
3803
|
+
class audio_Audio extends APIResource {
|
3795
3804
|
constructor(...args){
|
3796
3805
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3797
3806
|
}
|
3798
3807
|
}
|
3799
|
-
|
3800
|
-
|
3808
|
+
// EXTERNAL MODULE: os (ignored)
|
3809
|
+
var os_ignored_ = __webpack_require__("?9050");
|
3810
|
+
var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
|
3811
|
+
var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.16-beta.1","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","main":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
|
3812
|
+
const { version: version_version } = package_namespaceObject;
|
3801
3813
|
const getEnv = ()=>{
|
3802
3814
|
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
3803
3815
|
const { platform } = process;
|
3804
3816
|
let osName = platform.toLowerCase();
|
3805
|
-
let osVersion =
|
3817
|
+
let osVersion = os_ignored_default().release();
|
3806
3818
|
if ('darwin' === platform) {
|
3807
3819
|
osName = 'macos';
|
3808
3820
|
// Try to parse the macOS version
|
3809
3821
|
try {
|
3810
|
-
const darwinVersion =
|
3822
|
+
const darwinVersion = os_ignored_default().release().split('.');
|
3811
3823
|
if (darwinVersion.length >= 2) {
|
3812
3824
|
const majorVersion = parseInt(darwinVersion[0], 10);
|
3813
3825
|
if (!isNaN(majorVersion) && majorVersion >= 9) {
|
@@ -3820,10 +3832,10 @@
|
|
3820
3832
|
}
|
3821
3833
|
} else if ('win32' === platform) {
|
3822
3834
|
osName = 'windows';
|
3823
|
-
osVersion =
|
3835
|
+
osVersion = os_ignored_default().release();
|
3824
3836
|
} else if ('linux' === platform) {
|
3825
3837
|
osName = 'linux';
|
3826
|
-
osVersion =
|
3838
|
+
osVersion = os_ignored_default().release();
|
3827
3839
|
}
|
3828
3840
|
return {
|
3829
3841
|
osName,
|
@@ -3833,12 +3845,12 @@
|
|
3833
3845
|
};
|
3834
3846
|
const getUserAgent = ()=>{
|
3835
3847
|
const { nodeVersion, osName, osVersion } = getEnv();
|
3836
|
-
return `coze-js/${
|
3848
|
+
return `coze-js/${version_version} node/${nodeVersion} ${osName}/${osVersion}`.toLowerCase();
|
3837
3849
|
};
|
3838
3850
|
const getNodeClientUserAgent = ()=>{
|
3839
3851
|
const { osVersion, nodeVersion, osName } = getEnv();
|
3840
3852
|
const ua = {
|
3841
|
-
version:
|
3853
|
+
version: version_version,
|
3842
3854
|
lang: 'node',
|
3843
3855
|
lang_version: nodeVersion,
|
3844
3856
|
os_name: osName,
|
@@ -3846,15 +3858,17 @@
|
|
3846
3858
|
};
|
3847
3859
|
return JSON.stringify(ua);
|
3848
3860
|
};
|
3849
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ const
|
3861
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
|
3850
3862
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3851
3863
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
3852
3864
|
var _error_response;
|
3853
3865
|
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);
|
3854
3866
|
}
|
3855
3867
|
if ('ERR_CANCELED' === error.code) return new APIUserAbortError(error.message);
|
3856
|
-
|
3857
|
-
|
3868
|
+
else {
|
3869
|
+
var _error_response1, _error_response2, _error_response3;
|
3870
|
+
return error_APIError.generate((null === (_error_response1 = error.response) || void 0 === _error_response1 ? void 0 : _error_response1.status) || 500, null === (_error_response2 = error.response) || void 0 === _error_response2 ? void 0 : _error_response2.data, error.message, null === (_error_response3 = error.response) || void 0 === _error_response3 ? void 0 : _error_response3.headers);
|
3871
|
+
}
|
3858
3872
|
};
|
3859
3873
|
async function fetchAPI(url) {
|
3860
3874
|
let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
|
@@ -3870,7 +3884,7 @@
|
|
3870
3884
|
adapter: options.isStreaming ? 'fetch' : void 0,
|
3871
3885
|
...options
|
3872
3886
|
}).catch((error)=>{
|
3873
|
-
throw
|
3887
|
+
throw fetcher_handleError(error);
|
3874
3888
|
});
|
3875
3889
|
return {
|
3876
3890
|
async *stream () {
|
@@ -3908,7 +3922,7 @@
|
|
3908
3922
|
buffer = lines[lines.length - 1]; // Keep the last incomplete line in the buffer
|
3909
3923
|
}
|
3910
3924
|
} catch (error) {
|
3911
|
-
|
3925
|
+
fetcher_handleError(error);
|
3912
3926
|
}
|
3913
3927
|
},
|
3914
3928
|
json: ()=>response.data,
|
@@ -3932,8 +3946,8 @@
|
|
3932
3946
|
}
|
3933
3947
|
/**
|
3934
3948
|
* default coze base URL is api.coze.com
|
3935
|
-
*/ const
|
3936
|
-
/* eslint-disable max-params */ class
|
3949
|
+
*/ const constant_COZE_COM_BASE_URL = 'https://api.coze.com';
|
3950
|
+
/* eslint-disable max-params */ class core_APIClient {
|
3937
3951
|
async getToken() {
|
3938
3952
|
if ('function' == typeof this.token) return await this.token();
|
3939
3953
|
return this.token;
|
@@ -3943,11 +3957,11 @@
|
|
3943
3957
|
const headers = {
|
3944
3958
|
authorization: `Bearer ${token}`
|
3945
3959
|
};
|
3946
|
-
if (!
|
3960
|
+
if (!utils_isBrowser()) {
|
3947
3961
|
headers['User-Agent'] = getUserAgent();
|
3948
3962
|
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
3949
3963
|
}
|
3950
|
-
const config =
|
3964
|
+
const config = mergeConfig(this.axiosOptions, options, {
|
3951
3965
|
headers
|
3952
3966
|
});
|
3953
3967
|
config.method = method;
|
@@ -3971,7 +3985,7 @@
|
|
3971
3985
|
if (contentType && contentType.includes('application/json')) {
|
3972
3986
|
const result = await json();
|
3973
3987
|
const { code, msg } = result;
|
3974
|
-
if (0 !== code && void 0 !== code) throw
|
3988
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3975
3989
|
}
|
3976
3990
|
return stream();
|
3977
3991
|
}
|
@@ -3979,7 +3993,7 @@
|
|
3979
3993
|
{
|
3980
3994
|
const result = await json();
|
3981
3995
|
const { code, msg } = result;
|
3982
|
-
if (0 !== code && void 0 !== code) throw
|
3996
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3983
3997
|
return result;
|
3984
3998
|
}
|
3985
3999
|
}
|
@@ -4011,31 +4025,35 @@
|
|
4011
4025
|
}
|
4012
4026
|
constructor(config){
|
4013
4027
|
this._config = config;
|
4014
|
-
this.baseURL = config.baseURL ||
|
4028
|
+
this.baseURL = config.baseURL || constant_COZE_COM_BASE_URL;
|
4015
4029
|
this.token = config.token;
|
4016
4030
|
this.axiosOptions = config.axiosOptions || {};
|
4017
4031
|
this.axiosInstance = config.axiosInstance;
|
4018
4032
|
this.debug = config.debug || false;
|
4019
4033
|
this.allowPersonalAccessTokenInBrowser = config.allowPersonalAccessTokenInBrowser || false;
|
4020
4034
|
this.headers = config.headers;
|
4021
|
-
if (
|
4022
|
-
}
|
4023
|
-
}
|
4024
|
-
|
4025
|
-
|
4026
|
-
|
4027
|
-
|
4028
|
-
|
4029
|
-
|
4030
|
-
|
4031
|
-
|
4032
|
-
|
4033
|
-
|
4034
|
-
|
4035
|
+
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');
|
4036
|
+
}
|
4037
|
+
}
|
4038
|
+
core_APIClient.APIError = error_APIError;
|
4039
|
+
core_APIClient.BadRequestError = BadRequestError;
|
4040
|
+
core_APIClient.AuthenticationError = AuthenticationError;
|
4041
|
+
core_APIClient.PermissionDeniedError = PermissionDeniedError;
|
4042
|
+
core_APIClient.NotFoundError = NotFoundError;
|
4043
|
+
core_APIClient.RateLimitError = RateLimitError;
|
4044
|
+
core_APIClient.InternalServerError = InternalServerError;
|
4045
|
+
core_APIClient.GatewayError = GatewayError;
|
4046
|
+
core_APIClient.TimeoutError = TimeoutError;
|
4047
|
+
core_APIClient.UserAbortError = APIUserAbortError;
|
4048
|
+
// EXTERNAL MODULE: crypto (ignored)
|
4049
|
+
__webpack_require__("?666e");
|
4050
|
+
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
4051
|
+
__webpack_require__("?79fd");
|
4052
|
+
class CozeAPI extends core_APIClient {
|
4035
4053
|
constructor(...args){
|
4036
4054
|
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4037
4055
|
* @deprecated
|
4038
|
-
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new
|
4056
|
+
*/ 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);
|
4039
4057
|
}
|
4040
4058
|
}
|
4041
4059
|
/**
|
@@ -9267,7 +9285,7 @@
|
|
9267
9285
|
}, stringPad = {
|
9268
9286
|
start: createMethod(!1),
|
9269
9287
|
end: createMethod(!0)
|
9270
|
-
},
|
9288
|
+
}, index_esm_min_userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(index_esm_min_userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
|
9271
9289
|
$$F({
|
9272
9290
|
target: "String",
|
9273
9291
|
proto: !0,
|
@@ -38420,7 +38438,7 @@
|
|
38420
38438
|
+ * @param milliseconds The time to sleep in milliseconds
|
38421
38439
|
+ * @throws {Error} If milliseconds is negative
|
38422
38440
|
+ * @returns Promise that resolves after the specified duration
|
38423
|
-
+ */ const
|
38441
|
+
+ */ const src_utils_sleep = (milliseconds)=>{
|
38424
38442
|
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
38425
38443
|
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
38426
38444
|
};
|