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