@coze/realtime-api 0.0.4 → 1.0.0-alpha.7419f0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/cjs/{index.cjs → index.js} +1775 -1370
- package/dist/esm/{index.js → index.mjs} +1775 -1370
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/client.d.ts +9 -2
- package/dist/types/error.d.ts +10 -2
- package/dist/types/event-handler.d.ts +63 -4
- package/dist/types/index.d.ts +11 -2
- package/dist/types/utils.d.ts +15 -2
- package/dist/umd/index.js +1774 -1369
- package/package.json +39 -20
- package/assets/api-overview.png +0 -0
- /package/dist/{esm → cjs}/index.js.LICENSE.txt +0 -0
- /package/dist/{cjs/index.cjs.LICENSE.txt → esm/index.mjs.LICENSE.txt} +0 -0
package/dist/umd/index.js
CHANGED
@@ -6,9 +6,46 @@
|
|
6
6
|
else root["CozeRealtimeApi"] = factory();
|
7
7
|
})(self, ()=>(()=>{
|
8
8
|
"use strict";
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
var __webpack_modules__ = {
|
10
|
+
"?666e": function() {
|
11
|
+
/* (ignored) */ },
|
12
|
+
"?79fd": function() {
|
13
|
+
/* (ignored) */ },
|
14
|
+
"?9050": function() {
|
15
|
+
/* (ignored) */ }
|
16
|
+
};
|
17
|
+
/************************************************************************/ // The module cache
|
18
|
+
var __webpack_module_cache__ = {};
|
19
|
+
// The require function
|
20
|
+
function __webpack_require__(moduleId) {
|
21
|
+
// Check if module is in cache
|
22
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
23
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
24
|
+
// Create a new module (and put it into the cache)
|
25
|
+
var module1 = __webpack_module_cache__[moduleId] = {
|
26
|
+
exports: {}
|
27
|
+
};
|
28
|
+
// Execute the module function
|
29
|
+
__webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
|
30
|
+
// Return the exports of the module
|
31
|
+
return module1.exports;
|
32
|
+
}
|
33
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
34
|
+
(()=>{
|
35
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
36
|
+
__webpack_require__.n = function(module1) {
|
37
|
+
var getter = module1 && module1.__esModule ? function() {
|
38
|
+
return module1['default'];
|
39
|
+
} : function() {
|
40
|
+
return module1;
|
41
|
+
};
|
42
|
+
__webpack_require__.d(getter, {
|
43
|
+
a: getter
|
44
|
+
});
|
45
|
+
return getter;
|
46
|
+
};
|
47
|
+
})();
|
48
|
+
// webpack/runtime/define_property_getters
|
12
49
|
(()=>{
|
13
50
|
__webpack_require__.d = function(exports1, definition) {
|
14
51
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
@@ -57,7 +94,7 @@
|
|
57
94
|
EventNames: ()=>/* reexport */ event_handler_EventNames,
|
58
95
|
RealtimeClient: ()=>/* binding */ RealtimeClient
|
59
96
|
});
|
60
|
-
// NAMESPACE OBJECT: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7/node_modules/axios/lib/platform/common/utils.js
|
97
|
+
// NAMESPACE OBJECT: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7_debug@4.3.7/node_modules/axios/lib/platform/common/utils.js
|
61
98
|
var common_utils_namespaceObject = {};
|
62
99
|
__webpack_require__.r(common_utils_namespaceObject);
|
63
100
|
__webpack_require__.d(common_utils_namespaceObject, {
|
@@ -71,483 +108,1045 @@
|
|
71
108
|
var src_utils_namespaceObject = {};
|
72
109
|
__webpack_require__.r(src_utils_namespaceObject);
|
73
110
|
__webpack_require__.d(src_utils_namespaceObject, {
|
111
|
+
checkDevicePermission: ()=>checkDevicePermission,
|
74
112
|
checkPermission: ()=>checkPermission,
|
75
113
|
getAudioDevices: ()=>getAudioDevices,
|
76
|
-
sleep: ()=>
|
114
|
+
sleep: ()=>src_utils_sleep
|
77
115
|
});
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
}
|
116
|
+
class APIResource {
|
117
|
+
constructor(client){
|
118
|
+
this._client = client;
|
119
|
+
}
|
82
120
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
121
|
+
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
122
|
+
/**
|
123
|
+
* Create a new agent. | 调用接口创建一个新的智能体。
|
124
|
+
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
125
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
126
|
+
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
127
|
+
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
128
|
+
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
129
|
+
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
130
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
131
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
132
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
133
|
+
* @returns Information about the created bot. | 创建的 Bot 信息。
|
134
|
+
*/ async create(params, options) {
|
135
|
+
const apiUrl = '/v1/bot/create';
|
136
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
137
|
+
return result.data;
|
138
|
+
}
|
139
|
+
/**
|
140
|
+
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
141
|
+
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
142
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
143
|
+
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
144
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
145
|
+
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
146
|
+
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
147
|
+
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
148
|
+
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
149
|
+
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
150
|
+
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
151
|
+
* @returns Undefined | 无返回值
|
152
|
+
*/ async update(params, options) {
|
153
|
+
const apiUrl = '/v1/bot/update';
|
154
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
155
|
+
return result.data;
|
156
|
+
}
|
157
|
+
/**
|
158
|
+
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
159
|
+
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
160
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
161
|
+
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
162
|
+
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
163
|
+
* @param params.page_size - Optional Pagination size. | 分页大小。
|
164
|
+
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
165
|
+
* @returns List of published bots. | 已发布的 Bot 列表。
|
166
|
+
*/ async list(params, options) {
|
167
|
+
const apiUrl = '/v1/space/published_bots_list';
|
168
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
169
|
+
return result.data;
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
173
|
+
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
174
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
175
|
+
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
176
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
177
|
+
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
178
|
+
* @returns Undefined | 无返回值
|
179
|
+
*/ async publish(params, options) {
|
180
|
+
const apiUrl = '/v1/bot/publish';
|
181
|
+
const result = await this._client.post(apiUrl, params, false, options);
|
182
|
+
return result.data;
|
183
|
+
}
|
184
|
+
/**
|
185
|
+
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
186
|
+
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
187
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
188
|
+
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
189
|
+
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
190
|
+
* @returns Information about the bot. | Bot 的配置信息。
|
191
|
+
*/ async retrieve(params, options) {
|
192
|
+
const apiUrl = '/v1/bot/get_online_info';
|
193
|
+
const result = await this._client.get(apiUrl, params, false, options);
|
194
|
+
return result.data;
|
195
|
+
}
|
117
196
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
/**
|
126
|
-
* Determine if a value is a view on an ArrayBuffer
|
127
|
-
*
|
128
|
-
* @param {*} val The value to test
|
129
|
-
*
|
130
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
131
|
-
*/ function isArrayBufferView(val) {
|
132
|
-
let result;
|
133
|
-
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
134
|
-
return result;
|
197
|
+
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
198
|
+
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
199
|
+
try {
|
200
|
+
return JSON.parse(jsonString);
|
201
|
+
} catch (error) {
|
202
|
+
return defaultValue;
|
203
|
+
}
|
135
204
|
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
* @param {*} val The value to test
|
184
|
-
*
|
185
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
186
|
-
*/ const isDate = kindOfTest('Date');
|
187
|
-
/**
|
188
|
-
* Determine if a value is a File
|
189
|
-
*
|
190
|
-
* @param {*} val The value to test
|
191
|
-
*
|
192
|
-
* @returns {boolean} True if value is a File, otherwise false
|
193
|
-
*/ const isFile = kindOfTest('File');
|
194
|
-
/**
|
195
|
-
* Determine if a value is a Blob
|
196
|
-
*
|
197
|
-
* @param {*} val The value to test
|
198
|
-
*
|
199
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
200
|
-
*/ const isBlob = kindOfTest('Blob');
|
201
|
-
/**
|
202
|
-
* Determine if a value is a FileList
|
203
|
-
*
|
204
|
-
* @param {*} val The value to test
|
205
|
-
*
|
206
|
-
* @returns {boolean} True if value is a File, otherwise false
|
207
|
-
*/ const utils_isFileList = kindOfTest('FileList');
|
208
|
-
/**
|
209
|
-
* Determine if a value is a Stream
|
210
|
-
*
|
211
|
-
* @param {*} val The value to test
|
212
|
-
*
|
213
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
214
|
-
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
215
|
-
/**
|
216
|
-
* Determine if a value is a FormData
|
217
|
-
*
|
218
|
-
* @param {*} thing The value to test
|
219
|
-
*
|
220
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
221
|
-
*/ const utils_isFormData = (thing)=>{
|
222
|
-
let kind;
|
223
|
-
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
224
|
-
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
225
|
-
};
|
226
|
-
/**
|
227
|
-
* Determine if a value is a URLSearchParams object
|
228
|
-
*
|
229
|
-
* @param {*} val The value to test
|
230
|
-
*
|
231
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
232
|
-
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
233
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
234
|
-
'ReadableStream',
|
235
|
-
'Request',
|
236
|
-
'Response',
|
237
|
-
'Headers'
|
238
|
-
].map(kindOfTest);
|
239
|
-
/**
|
240
|
-
* Trim excess whitespace off the beginning and end of a string
|
241
|
-
*
|
242
|
-
* @param {String} str The String to trim
|
243
|
-
*
|
244
|
-
* @returns {String} The String freed of excess whitespace
|
245
|
-
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
246
|
-
/**
|
247
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
248
|
-
*
|
249
|
-
* If `obj` is an Array callback will be called passing
|
250
|
-
* the value, index, and complete array for each item.
|
251
|
-
*
|
252
|
-
* If 'obj' is an Object callback will be called passing
|
253
|
-
* the value, key, and complete object for each property.
|
254
|
-
*
|
255
|
-
* @param {Object|Array} obj The object to iterate
|
256
|
-
* @param {Function} fn The callback to invoke for each item
|
257
|
-
*
|
258
|
-
* @param {Boolean} [allOwnKeys = false]
|
259
|
-
* @returns {any}
|
260
|
-
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
261
|
-
// Don't bother if no value provided
|
262
|
-
if (null == obj) return;
|
263
|
-
let i;
|
264
|
-
let l;
|
265
|
-
// Force an array if not already something iterable
|
266
|
-
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
267
|
-
obj
|
268
|
-
];
|
269
|
-
if (isArray(obj)) // Iterate over array values
|
270
|
-
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
271
|
-
else {
|
272
|
-
// Iterate over object keys
|
273
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
274
|
-
const len = keys.length;
|
275
|
-
let key;
|
276
|
-
for(i = 0; i < len; i++){
|
277
|
-
key = keys[i];
|
278
|
-
fn.call(null, obj[key], key, obj);
|
205
|
+
function utils_sleep(ms) {
|
206
|
+
return new Promise((resolve)=>{
|
207
|
+
setTimeout(resolve, ms);
|
208
|
+
});
|
209
|
+
}
|
210
|
+
function utils_isBrowser() {
|
211
|
+
return 'undefined' != typeof window;
|
212
|
+
}
|
213
|
+
function isPlainObject(obj) {
|
214
|
+
if ('object' != typeof obj || null === obj) return false;
|
215
|
+
const proto = Object.getPrototypeOf(obj);
|
216
|
+
if (null === proto) return true;
|
217
|
+
let baseProto = proto;
|
218
|
+
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
219
|
+
return proto === baseProto;
|
220
|
+
}
|
221
|
+
function mergeConfig() {
|
222
|
+
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
223
|
+
return objects.reduce((result, obj)=>{
|
224
|
+
if (void 0 === obj) return result || {};
|
225
|
+
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
226
|
+
if (isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = mergeConfig(result[key] || {}, obj[key]);
|
227
|
+
else result[key] = obj[key];
|
228
|
+
}
|
229
|
+
return result;
|
230
|
+
}, {});
|
231
|
+
}
|
232
|
+
function isPersonalAccessToken(token) {
|
233
|
+
return null == token ? void 0 : token.startsWith('pat_');
|
234
|
+
}
|
235
|
+
/* eslint-disable max-params */ class CozeError extends Error {
|
236
|
+
}
|
237
|
+
class error_APIError extends CozeError {
|
238
|
+
static makeMessage(status, errorBody, message, headers) {
|
239
|
+
if (!errorBody && message) return message;
|
240
|
+
if (errorBody) {
|
241
|
+
const list = [];
|
242
|
+
const { code, msg, error } = errorBody;
|
243
|
+
if (code) list.push(`code: ${code}`);
|
244
|
+
if (msg) list.push(`msg: ${msg}`);
|
245
|
+
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
246
|
+
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
247
|
+
if (logId) list.push(`logid: ${logId}`);
|
248
|
+
const help_doc = null == error ? void 0 : error.help_doc;
|
249
|
+
if (help_doc) list.push(`help doc: ${help_doc}`);
|
250
|
+
return list.join(', ');
|
279
251
|
}
|
252
|
+
if (status) return `http status code: ${status} (no body)`;
|
253
|
+
return '(no status code or body)';
|
254
|
+
}
|
255
|
+
static generate(status, errorResponse, message, headers) {
|
256
|
+
if (!status) return new APIConnectionError({
|
257
|
+
cause: castToError(errorResponse)
|
258
|
+
});
|
259
|
+
const error = errorResponse;
|
260
|
+
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
261
|
+
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
262
|
+
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
263
|
+
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
264
|
+
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
265
|
+
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
266
|
+
if (408 === status) return new TimeoutError(status, error, message, headers);
|
267
|
+
if (502 === status) return new GatewayError(status, error, message, headers);
|
268
|
+
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
269
|
+
return new error_APIError(status, error, message, headers);
|
270
|
+
}
|
271
|
+
constructor(status, error, message, headers){
|
272
|
+
var _error_error, _error_error1;
|
273
|
+
super(`${error_APIError.makeMessage(status, error, message, headers)}`);
|
274
|
+
this.status = status;
|
275
|
+
this.headers = headers;
|
276
|
+
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
277
|
+
// this.error = error;
|
278
|
+
this.code = null == error ? void 0 : error.code;
|
279
|
+
this.msg = null == error ? void 0 : error.msg;
|
280
|
+
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
281
|
+
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
282
|
+
this.rawError = error;
|
280
283
|
}
|
281
284
|
}
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
_key = keys[i];
|
289
|
-
if (key === _key.toLowerCase()) return _key;
|
285
|
+
class APIConnectionError extends error_APIError {
|
286
|
+
constructor({ message, cause }){
|
287
|
+
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
288
|
+
// if (cause) {
|
289
|
+
// this.cause = cause;
|
290
|
+
// }
|
290
291
|
}
|
291
|
-
return null;
|
292
292
|
}
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
298
|
-
/**
|
299
|
-
* Accepts varargs expecting each argument to be an object, then
|
300
|
-
* immutably merges the properties of each object and returns result.
|
301
|
-
*
|
302
|
-
* When multiple objects contain the same key the later object in
|
303
|
-
* the arguments list will take precedence.
|
304
|
-
*
|
305
|
-
* Example:
|
306
|
-
*
|
307
|
-
* ```js
|
308
|
-
* var result = merge({foo: 123}, {foo: 456});
|
309
|
-
* console.log(result.foo); // outputs 456
|
310
|
-
* ```
|
311
|
-
*
|
312
|
-
* @param {Object} obj1 Object to merge
|
313
|
-
*
|
314
|
-
* @returns {Object} Result of all merge properties
|
315
|
-
*/ function utils_merge() {
|
316
|
-
const { caseless } = isContextDefined(this) && this || {};
|
317
|
-
const result = {};
|
318
|
-
const assignValue = (val, key)=>{
|
319
|
-
const targetKey = caseless && findKey(result, key) || key;
|
320
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
321
|
-
else if (isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
322
|
-
else if (isArray(val)) result[targetKey] = val.slice();
|
323
|
-
else result[targetKey] = val;
|
324
|
-
};
|
325
|
-
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
326
|
-
return result;
|
293
|
+
class APIUserAbortError extends error_APIError {
|
294
|
+
constructor(message){
|
295
|
+
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
296
|
+
}
|
327
297
|
}
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
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
|
-
|
298
|
+
class BadRequestError extends error_APIError {
|
299
|
+
constructor(...args){
|
300
|
+
super(...args), this.name = 'BadRequestError', this.status = 400;
|
301
|
+
}
|
302
|
+
}
|
303
|
+
class AuthenticationError extends error_APIError {
|
304
|
+
constructor(...args){
|
305
|
+
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
class PermissionDeniedError extends error_APIError {
|
309
|
+
constructor(...args){
|
310
|
+
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
class NotFoundError extends error_APIError {
|
314
|
+
constructor(...args){
|
315
|
+
super(...args), this.name = 'NotFoundError', this.status = 404;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
class TimeoutError extends error_APIError {
|
319
|
+
constructor(...args){
|
320
|
+
super(...args), this.name = 'TimeoutError', this.status = 408;
|
321
|
+
}
|
322
|
+
}
|
323
|
+
class RateLimitError extends error_APIError {
|
324
|
+
constructor(...args){
|
325
|
+
super(...args), this.name = 'RateLimitError', this.status = 429;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
class InternalServerError extends error_APIError {
|
329
|
+
constructor(...args){
|
330
|
+
super(...args), this.name = 'InternalServerError', this.status = 500;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
class GatewayError extends error_APIError {
|
334
|
+
constructor(...args){
|
335
|
+
super(...args), this.name = 'GatewayError', this.status = 502;
|
336
|
+
}
|
337
|
+
}
|
338
|
+
const castToError = (err)=>{
|
339
|
+
if (err instanceof Error) return err;
|
340
|
+
return new Error(err);
|
371
341
|
};
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
342
|
+
class Messages extends APIResource {
|
343
|
+
/**
|
344
|
+
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
345
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
346
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
347
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
348
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
349
|
+
* @returns An array of chat messages. | 对话消息数组。
|
350
|
+
*/ async list(conversation_id, chat_id, options) {
|
351
|
+
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
352
|
+
const result = await this._client.get(apiUrl, void 0, false, options);
|
353
|
+
return result.data;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
357
|
+
const handleAdditionalMessages = (additional_messages)=>null == additional_messages ? void 0 : additional_messages.map((i)=>({
|
358
|
+
...i,
|
359
|
+
content: 'object' == typeof i.content ? JSON.stringify(i.content) : i.content
|
360
|
+
}));
|
361
|
+
class Chat extends APIResource {
|
362
|
+
/**
|
363
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
364
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
365
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
366
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
367
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
368
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
369
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
370
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
371
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
372
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
373
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
374
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
375
|
+
* @returns The data of the created chat. | 创建的对话数据。
|
376
|
+
*/ async create(params, options) {
|
377
|
+
if (!params.user_id) params.user_id = uuid();
|
378
|
+
const { conversation_id, ...rest } = params;
|
379
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
380
|
+
const payload = {
|
381
|
+
...rest,
|
382
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
383
|
+
stream: false
|
384
|
+
};
|
385
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
386
|
+
return result.data;
|
387
|
+
}
|
388
|
+
/**
|
389
|
+
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
390
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
391
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
392
|
+
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
393
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
394
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
395
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
396
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
397
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
398
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
399
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
400
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
401
|
+
* @returns
|
402
|
+
*/ async createAndPoll(params, options) {
|
403
|
+
if (!params.user_id) params.user_id = uuid();
|
404
|
+
const { conversation_id, ...rest } = params;
|
405
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
406
|
+
const payload = {
|
407
|
+
...rest,
|
408
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
409
|
+
stream: false
|
410
|
+
};
|
411
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
412
|
+
const chatId = result.data.id;
|
413
|
+
const conversationId = result.data.conversation_id;
|
414
|
+
let chat;
|
415
|
+
while(true){
|
416
|
+
await utils_sleep(100);
|
417
|
+
chat = await this.retrieve(conversationId, chatId);
|
418
|
+
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
419
|
+
}
|
420
|
+
const messageList = await this.messages.list(conversationId, chatId);
|
421
|
+
return {
|
422
|
+
chat,
|
423
|
+
messages: messageList
|
424
|
+
};
|
425
|
+
}
|
426
|
+
/**
|
427
|
+
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
428
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
429
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
430
|
+
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
431
|
+
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
432
|
+
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
433
|
+
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
434
|
+
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
435
|
+
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
436
|
+
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
437
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
438
|
+
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
439
|
+
* @returns A stream of chat data. | 对话数据流。
|
440
|
+
*/ async *stream(params, options) {
|
441
|
+
if (!params.user_id) params.user_id = uuid();
|
442
|
+
const { conversation_id, ...rest } = params;
|
443
|
+
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
444
|
+
const payload = {
|
445
|
+
...rest,
|
446
|
+
additional_messages: handleAdditionalMessages(params.additional_messages),
|
447
|
+
stream: true
|
448
|
+
};
|
449
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
450
|
+
for await (const message of result)if ("done" === message.event) {
|
451
|
+
const ret = {
|
452
|
+
event: message.event,
|
453
|
+
data: '[DONE]'
|
454
|
+
};
|
455
|
+
yield ret;
|
456
|
+
} else try {
|
457
|
+
const ret = {
|
458
|
+
event: message.event,
|
459
|
+
data: JSON.parse(message.data)
|
460
|
+
};
|
461
|
+
yield ret;
|
462
|
+
} catch (error) {
|
463
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
464
|
+
}
|
465
|
+
}
|
466
|
+
/**
|
467
|
+
* Get the detailed information of the chat. | 查看对话的详细信息。
|
468
|
+
* @docs en:https://www.coze.com/docs/developer_guides/retrieve_chat?_lang=en
|
469
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/retrieve_chat?_lang=zh
|
470
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
471
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
472
|
+
* @returns The data of the retrieved chat. | 检索到的对话数据。
|
473
|
+
*/ async retrieve(conversation_id, chat_id, options) {
|
474
|
+
const apiUrl = `/v3/chat/retrieve?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
475
|
+
const result = await this._client.post(apiUrl, void 0, false, options);
|
476
|
+
return result.data;
|
477
|
+
}
|
478
|
+
/**
|
479
|
+
* Cancel a chat session. | 取消对话会话。
|
480
|
+
* @docs en:https://www.coze.com/docs/developer_guides/cancel_chat?_lang=en
|
481
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/cancel_chat?_lang=zh
|
482
|
+
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
483
|
+
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
484
|
+
* @returns The data of the canceled chat. | 取消的对话数据。
|
485
|
+
*/ async cancel(conversation_id, chat_id, options) {
|
486
|
+
const apiUrl = '/v3/chat/cancel';
|
487
|
+
const payload = {
|
488
|
+
conversation_id,
|
489
|
+
chat_id
|
490
|
+
};
|
491
|
+
const result = await this._client.post(apiUrl, payload, false, options);
|
492
|
+
return result.data;
|
493
|
+
}
|
494
|
+
/**
|
495
|
+
* Submit tool outputs for a chat session. | 提交对话会话的工具输出。
|
496
|
+
* @docs en:https://www.coze.com/docs/developer_guides/chat_submit_tool_outputs?_lang=en
|
497
|
+
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_submit_tool_outputs?_lang=zh
|
498
|
+
* @param params - Required Parameters for submitting tool outputs. | 提交工具输出的参数。
|
499
|
+
* @param params.conversation_id - Required The ID of the conversation. | 会话 ID。
|
500
|
+
* @param params.chat_id - Required The ID of the chat. | 对话 ID。
|
501
|
+
* @param params.tool_outputs - Required The outputs of the tool. | 工具的输出。
|
502
|
+
* @param params.stream - Optional Whether to use streaming response. | 是否使用流式响应。
|
503
|
+
* @returns The data of the submitted tool outputs or a stream of chat data. | 提交的工具输出数据或对话数据流。
|
504
|
+
*/ async *submitToolOutputs(params, options) {
|
505
|
+
const { conversation_id, chat_id, ...rest } = params;
|
506
|
+
const apiUrl = `/v3/chat/submit_tool_outputs?conversation_id=${params.conversation_id}&chat_id=${params.chat_id}`;
|
507
|
+
const payload = {
|
508
|
+
...rest
|
509
|
+
};
|
510
|
+
if (false === params.stream) {
|
511
|
+
const response = await this._client.post(apiUrl, payload, false, options);
|
512
|
+
return response.data;
|
513
|
+
}
|
514
|
+
{
|
515
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
516
|
+
for await (const message of result)if ("done" === message.event) {
|
517
|
+
const ret = {
|
518
|
+
event: message.event,
|
519
|
+
data: '[DONE]'
|
520
|
+
};
|
521
|
+
yield ret;
|
522
|
+
} else try {
|
523
|
+
const ret = {
|
524
|
+
event: message.event,
|
525
|
+
data: JSON.parse(message.data)
|
526
|
+
};
|
527
|
+
yield ret;
|
528
|
+
} catch (error) {
|
529
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
396
530
|
}
|
397
531
|
}
|
398
|
-
|
399
|
-
|
400
|
-
|
532
|
+
}
|
533
|
+
constructor(...args){
|
534
|
+
super(...args), this.messages = new Messages(this._client);
|
535
|
+
}
|
536
|
+
}
|
537
|
+
var chat_ChatEventType = /*#__PURE__*/ function(ChatEventType) {
|
538
|
+
ChatEventType["CONVERSATION_CHAT_CREATED"] = "conversation.chat.created";
|
539
|
+
ChatEventType["CONVERSATION_CHAT_IN_PROGRESS"] = "conversation.chat.in_progress";
|
540
|
+
ChatEventType["CONVERSATION_CHAT_COMPLETED"] = "conversation.chat.completed";
|
541
|
+
ChatEventType["CONVERSATION_CHAT_FAILED"] = "conversation.chat.failed";
|
542
|
+
ChatEventType["CONVERSATION_CHAT_REQUIRES_ACTION"] = "conversation.chat.requires_action";
|
543
|
+
ChatEventType["CONVERSATION_MESSAGE_DELTA"] = "conversation.message.delta";
|
544
|
+
ChatEventType["CONVERSATION_MESSAGE_COMPLETED"] = "conversation.message.completed";
|
545
|
+
ChatEventType["CONVERSATION_AUDIO_DELTA"] = "conversation.audio.delta";
|
546
|
+
ChatEventType["DONE"] = "done";
|
547
|
+
ChatEventType["ERROR"] = "error";
|
548
|
+
return ChatEventType;
|
549
|
+
}({});
|
550
|
+
class messages_Messages extends APIResource {
|
551
|
+
/**
|
552
|
+
* Create a message and add it to the specified conversation. | 创建一条消息,并将其添加到指定的会话中。
|
553
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_message?_lang=en
|
554
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_message?_lang=zh
|
555
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
556
|
+
* @param params - Required The parameters for creating a message | 创建消息所需的参数
|
557
|
+
* @param params.role - Required The entity that sent this message. Possible values: user, assistant. | 发送这条消息的实体。取值:user, assistant。
|
558
|
+
* @param params.content - Required The content of the message. | 消息的内容。
|
559
|
+
* @param params.content_type - Required The type of the message content. | 消息内容的类型。
|
560
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
561
|
+
* @returns Information about the new message. | 消息详情。
|
562
|
+
*/ async create(conversation_id, params, options) {
|
563
|
+
const apiUrl = `/v1/conversation/message/create?conversation_id=${conversation_id}`;
|
564
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
565
|
+
return response.data;
|
566
|
+
}
|
567
|
+
/**
|
568
|
+
* Modify a message, supporting the modification of message content, additional content, and message type. | 修改一条消息,支持修改消息内容、附加内容和消息类型。
|
569
|
+
* @docs en: https://www.coze.com/docs/developer_guides/modify_message?_lang=en
|
570
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_message?_lang=zh
|
571
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
572
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
573
|
+
* @param params - Required The parameters for modifying a message | 修改消息所需的参数
|
574
|
+
* @param params.meta_data - Optional Additional information when modifying a message. | 修改消息时的附加消息。
|
575
|
+
* @param params.content - Optional The content of the message. | 消息的内容。
|
576
|
+
* @param params.content_type - Optional The type of the message content. | 消息内容的类型。
|
577
|
+
* @returns Information about the modified message. | 消息详情。
|
578
|
+
*/ // eslint-disable-next-line max-params
|
579
|
+
async update(conversation_id, message_id, params, options) {
|
580
|
+
const apiUrl = `/v1/conversation/message/modify?conversation_id=${conversation_id}&message_id=${message_id}`;
|
581
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
582
|
+
return response.message;
|
583
|
+
}
|
584
|
+
/**
|
585
|
+
* Get the detailed information of specified message. | 查看指定消息的详细信息。
|
586
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_message?_lang=en
|
587
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_message?_lang=zh
|
588
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
589
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
590
|
+
* @returns Information about the message. | 消息详情。
|
591
|
+
*/ async retrieve(conversation_id, message_id, options) {
|
592
|
+
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
593
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
594
|
+
return response.data;
|
595
|
+
}
|
596
|
+
/**
|
597
|
+
* List messages in a conversation. | 列出会话中的消息。
|
598
|
+
* @docs en: https://www.coze.com/docs/developer_guides/message_list?_lang=en
|
599
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/message_list?_lang=zh
|
600
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
601
|
+
* @param params - Optional The parameters for listing messages | 列出消息所需的参数
|
602
|
+
* @param params.order - Optional The order of the messages. | 消息的顺序。
|
603
|
+
* @param params.chat_id - Optional The ID of the chat. | 聊天 ID。
|
604
|
+
* @param params.before_id - Optional The ID of the message before which to list. | 列出此消息之前的消息 ID。
|
605
|
+
* @param params.after_id - Optional The ID of the message after which to list. | 列出此消息之后的消息 ID。
|
606
|
+
* @param params.limit - Optional The maximum number of messages to return. | 返回的最大消息数。
|
607
|
+
* @returns A list of messages. | 消息列表。
|
608
|
+
*/ async list(conversation_id, params, options) {
|
609
|
+
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
610
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
611
|
+
return response;
|
612
|
+
}
|
613
|
+
/**
|
614
|
+
* Call the API to delete a message within a specified conversation. | 调用接口在指定会话中删除消息。
|
615
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_message?_lang=en
|
616
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_message?_lang=zh
|
617
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
618
|
+
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
619
|
+
* @returns Details of the deleted message. | 已删除的消息详情。
|
620
|
+
*/ async delete(conversation_id, message_id, options) {
|
621
|
+
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
622
|
+
const response = await this._client.post(apiUrl, void 0, false, options);
|
623
|
+
return response.data;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
class Conversations extends APIResource {
|
627
|
+
/**
|
628
|
+
* Create a conversation. Conversation is an interaction between an agent and a user, including one or more messages. | 调用接口创建一个会话。
|
629
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_conversation?_lang=en
|
630
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_conversation?_lang=zh
|
631
|
+
* @param params - Required The parameters for creating a conversation | 创建会话所需的参数
|
632
|
+
* @param params.messages - Optional Messages in the conversation. | 会话中的消息内容。
|
633
|
+
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
634
|
+
* @param params.bot_id - Optional Bind and isolate conversation on different bots. | 绑定和隔离不同Bot的会话。
|
635
|
+
* @returns Information about the created conversation. | 会话的基础信息。
|
636
|
+
*/ async create(params, options) {
|
637
|
+
const apiUrl = '/v1/conversation/create';
|
638
|
+
const response = await this._client.post(apiUrl, params, false, options);
|
639
|
+
return response.data;
|
640
|
+
}
|
641
|
+
/**
|
642
|
+
* Get the information of specific conversation. | 通过会话 ID 查看会话信息。
|
643
|
+
* @docs en: https://www.coze.com/docs/developer_guides/retrieve_conversation?_lang=en
|
644
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/retrieve_conversation?_lang=zh
|
645
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
646
|
+
* @returns Information about the conversation. | 会话的基础信息。
|
647
|
+
*/ async retrieve(conversation_id, options) {
|
648
|
+
const apiUrl = `/v1/conversation/retrieve?conversation_id=${conversation_id}`;
|
649
|
+
const response = await this._client.get(apiUrl, null, false, options);
|
650
|
+
return response.data;
|
651
|
+
}
|
652
|
+
/**
|
653
|
+
* List all conversations. | 列出 Bot 下所有会话。
|
654
|
+
* @param params
|
655
|
+
* @param params.bot_id - Required Bot ID. | Bot ID。
|
656
|
+
* @param params.page_num - Optional The page number. | 页码,默认值为 1。
|
657
|
+
* @param params.page_size - Optional The number of conversations per page. | 每页的会话数量,默认值为 50。
|
658
|
+
* @returns Information about the conversations. | 会话的信息。
|
659
|
+
*/ async list(params, options) {
|
660
|
+
const apiUrl = '/v1/conversations';
|
661
|
+
const response = await this._client.get(apiUrl, params, false, options);
|
662
|
+
return response.data;
|
663
|
+
}
|
664
|
+
/**
|
665
|
+
* Clear a conversation. | 清空会话。
|
666
|
+
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
667
|
+
* @returns Information about the conversation session. | 会话的会话 ID。
|
668
|
+
*/ async clear(conversation_id, options) {
|
669
|
+
const apiUrl = `/v1/conversations/${conversation_id}/clear`;
|
670
|
+
const response = await this._client.post(apiUrl, null, false, options);
|
671
|
+
return response.data;
|
672
|
+
}
|
673
|
+
constructor(...args){
|
674
|
+
super(...args), this.messages = new messages_Messages(this._client);
|
675
|
+
}
|
676
|
+
}
|
677
|
+
function bind(fn, thisArg) {
|
678
|
+
return function() {
|
679
|
+
return fn.apply(thisArg, arguments);
|
680
|
+
};
|
681
|
+
}
|
682
|
+
// utils is a library of generic helper functions non-specific to axios
|
683
|
+
const { toString: utils_toString } = Object.prototype;
|
684
|
+
const { getPrototypeOf } = Object;
|
685
|
+
const kindOf = ((cache)=>(thing)=>{
|
686
|
+
const str = utils_toString.call(thing);
|
687
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
688
|
+
})(Object.create(null));
|
689
|
+
const kindOfTest = (type)=>{
|
690
|
+
type = type.toLowerCase();
|
691
|
+
return (thing)=>kindOf(thing) === type;
|
401
692
|
};
|
693
|
+
const typeOfTest = (type)=>(thing)=>typeof thing === type;
|
402
694
|
/**
|
403
|
-
*
|
695
|
+
* Determine if a value is an Array
|
404
696
|
*
|
405
|
-
* @param {
|
406
|
-
* @param {String} searchString
|
407
|
-
* @param {Number} [position= 0]
|
697
|
+
* @param {Object} val The value to test
|
408
698
|
*
|
409
|
-
* @returns {boolean}
|
410
|
-
*/ const
|
411
|
-
str = String(str);
|
412
|
-
if (void 0 === position || position > str.length) position = str.length;
|
413
|
-
position -= searchString.length;
|
414
|
-
const lastIndex = str.indexOf(searchString, position);
|
415
|
-
return -1 !== lastIndex && lastIndex === position;
|
416
|
-
};
|
699
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
700
|
+
*/ const { isArray } = Array;
|
417
701
|
/**
|
418
|
-
*
|
702
|
+
* Determine if a value is undefined
|
419
703
|
*
|
420
|
-
* @param {*}
|
704
|
+
* @param {*} val The value to test
|
421
705
|
*
|
422
|
-
* @returns {
|
423
|
-
*/ const
|
424
|
-
if (!thing) return null;
|
425
|
-
if (isArray(thing)) return thing;
|
426
|
-
let i = thing.length;
|
427
|
-
if (!isNumber(i)) return null;
|
428
|
-
const arr = new Array(i);
|
429
|
-
while(i-- > 0)arr[i] = thing[i];
|
430
|
-
return arr;
|
431
|
-
};
|
706
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
707
|
+
*/ const isUndefined = typeOfTest('undefined');
|
432
708
|
/**
|
433
|
-
*
|
434
|
-
* thing passed in is an instance of Uint8Array
|
709
|
+
* Determine if a value is a Buffer
|
435
710
|
*
|
436
|
-
* @param {
|
711
|
+
* @param {*} val The value to test
|
437
712
|
*
|
438
|
-
* @returns {
|
439
|
-
*/
|
440
|
-
|
713
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
714
|
+
*/ function isBuffer(val) {
|
715
|
+
return null !== val && !isUndefined(val) && null !== val.constructor && !isUndefined(val.constructor) && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
716
|
+
}
|
441
717
|
/**
|
442
|
-
*
|
718
|
+
* Determine if a value is an ArrayBuffer
|
443
719
|
*
|
444
|
-
* @param {
|
445
|
-
* @param {Function} fn - The function to call for each entry.
|
720
|
+
* @param {*} val The value to test
|
446
721
|
*
|
447
|
-
* @returns {
|
448
|
-
*/ const
|
449
|
-
|
450
|
-
|
722
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
723
|
+
*/ const isArrayBuffer = kindOfTest('ArrayBuffer');
|
724
|
+
/**
|
725
|
+
* Determine if a value is a view on an ArrayBuffer
|
726
|
+
*
|
727
|
+
* @param {*} val The value to test
|
728
|
+
*
|
729
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
730
|
+
*/ function isArrayBufferView(val) {
|
451
731
|
let result;
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
}
|
456
|
-
};
|
732
|
+
result = 'undefined' != typeof ArrayBuffer && ArrayBuffer.isView ? ArrayBuffer.isView(val) : val && val.buffer && isArrayBuffer(val.buffer);
|
733
|
+
return result;
|
734
|
+
}
|
457
735
|
/**
|
458
|
-
*
|
736
|
+
* Determine if a value is a String
|
459
737
|
*
|
460
|
-
* @param {
|
461
|
-
* @param {string} str - The string to search.
|
738
|
+
* @param {*} val The value to test
|
462
739
|
*
|
463
|
-
* @returns {
|
464
|
-
*/ const
|
465
|
-
let matches;
|
466
|
-
const arr = [];
|
467
|
-
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
468
|
-
return arr;
|
469
|
-
};
|
470
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
471
|
-
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
472
|
-
return p1.toUpperCase() + p2;
|
473
|
-
});
|
474
|
-
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
740
|
+
* @returns {boolean} True if value is a String, otherwise false
|
741
|
+
*/ const isString = typeOfTest('string');
|
475
742
|
/**
|
476
|
-
* Determine if a value is a
|
743
|
+
* Determine if a value is a Function
|
477
744
|
*
|
478
745
|
* @param {*} val The value to test
|
746
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
747
|
+
*/ const isFunction = typeOfTest('function');
|
748
|
+
/**
|
749
|
+
* Determine if a value is a Number
|
479
750
|
*
|
480
|
-
* @
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
const reducedDescriptors = {};
|
485
|
-
forEach(descriptors, (descriptor, name)=>{
|
486
|
-
let ret;
|
487
|
-
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
488
|
-
});
|
489
|
-
Object.defineProperties(obj, reducedDescriptors);
|
490
|
-
};
|
751
|
+
* @param {*} val The value to test
|
752
|
+
*
|
753
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
754
|
+
*/ const isNumber = typeOfTest('number');
|
491
755
|
/**
|
492
|
-
*
|
493
|
-
*
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
'arguments',
|
499
|
-
'caller',
|
500
|
-
'callee'
|
501
|
-
].indexOf(name)) return false;
|
502
|
-
const value = obj[name];
|
503
|
-
if (!isFunction(value)) return;
|
504
|
-
descriptor.enumerable = false;
|
505
|
-
if ('writable' in descriptor) {
|
506
|
-
descriptor.writable = false;
|
507
|
-
return;
|
508
|
-
}
|
509
|
-
if (!descriptor.set) descriptor.set = ()=>{
|
510
|
-
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
511
|
-
};
|
512
|
-
});
|
513
|
-
};
|
514
|
-
const toObjectSet = (arrayOrString, delimiter)=>{
|
515
|
-
const obj = {};
|
516
|
-
const define1 = (arr)=>{
|
517
|
-
arr.forEach((value)=>{
|
518
|
-
obj[value] = true;
|
519
|
-
});
|
520
|
-
};
|
521
|
-
isArray(arrayOrString) ? define1(arrayOrString) : define1(String(arrayOrString).split(delimiter));
|
522
|
-
return obj;
|
523
|
-
};
|
524
|
-
const noop = ()=>{};
|
525
|
-
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
526
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
527
|
-
const DIGIT = '0123456789';
|
528
|
-
const ALPHABET = {
|
529
|
-
DIGIT,
|
530
|
-
ALPHA,
|
531
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
532
|
-
};
|
533
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
534
|
-
let str = '';
|
535
|
-
const { length } = alphabet;
|
536
|
-
while(size--)str += alphabet[Math.random() * length | 0];
|
537
|
-
return str;
|
538
|
-
};
|
756
|
+
* Determine if a value is an Object
|
757
|
+
*
|
758
|
+
* @param {*} thing The value to test
|
759
|
+
*
|
760
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
761
|
+
*/ const isObject = (thing)=>null !== thing && 'object' == typeof thing;
|
539
762
|
/**
|
540
|
-
*
|
763
|
+
* Determine if a value is a Boolean
|
541
764
|
*
|
542
|
-
* @param {
|
765
|
+
* @param {*} thing The value to test
|
766
|
+
* @returns {boolean} True if value is a Boolean, otherwise false
|
767
|
+
*/ const isBoolean = (thing)=>true === thing || false === thing;
|
768
|
+
/**
|
769
|
+
* Determine if a value is a plain Object
|
543
770
|
*
|
544
|
-
* @
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
const
|
550
|
-
|
771
|
+
* @param {*} val The value to test
|
772
|
+
*
|
773
|
+
* @returns {boolean} True if value is a plain Object, otherwise false
|
774
|
+
*/ const utils_isPlainObject = (val)=>{
|
775
|
+
if ('object' !== kindOf(val)) return false;
|
776
|
+
const prototype = getPrototypeOf(val);
|
777
|
+
return (null === prototype || prototype === Object.prototype || null === Object.getPrototypeOf(prototype)) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
778
|
+
};
|
779
|
+
/**
|
780
|
+
* Determine if a value is a Date
|
781
|
+
*
|
782
|
+
* @param {*} val The value to test
|
783
|
+
*
|
784
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
785
|
+
*/ const isDate = kindOfTest('Date');
|
786
|
+
/**
|
787
|
+
* Determine if a value is a File
|
788
|
+
*
|
789
|
+
* @param {*} val The value to test
|
790
|
+
*
|
791
|
+
* @returns {boolean} True if value is a File, otherwise false
|
792
|
+
*/ const isFile = kindOfTest('File');
|
793
|
+
/**
|
794
|
+
* Determine if a value is a Blob
|
795
|
+
*
|
796
|
+
* @param {*} val The value to test
|
797
|
+
*
|
798
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
799
|
+
*/ const isBlob = kindOfTest('Blob');
|
800
|
+
/**
|
801
|
+
* Determine if a value is a FileList
|
802
|
+
*
|
803
|
+
* @param {*} val The value to test
|
804
|
+
*
|
805
|
+
* @returns {boolean} True if value is a File, otherwise false
|
806
|
+
*/ const utils_isFileList = kindOfTest('FileList');
|
807
|
+
/**
|
808
|
+
* Determine if a value is a Stream
|
809
|
+
*
|
810
|
+
* @param {*} val The value to test
|
811
|
+
*
|
812
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
813
|
+
*/ const utils_isStream = (val)=>isObject(val) && isFunction(val.pipe);
|
814
|
+
/**
|
815
|
+
* Determine if a value is a FormData
|
816
|
+
*
|
817
|
+
* @param {*} thing The value to test
|
818
|
+
*
|
819
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
820
|
+
*/ const utils_isFormData = (thing)=>{
|
821
|
+
let kind;
|
822
|
+
return thing && ('function' == typeof FormData && thing instanceof FormData || isFunction(thing.append) && ('formdata' === (kind = kindOf(thing)) || // detect form-data instance
|
823
|
+
'object' === kind && isFunction(thing.toString) && '[object FormData]' === thing.toString()));
|
824
|
+
};
|
825
|
+
/**
|
826
|
+
* Determine if a value is a URLSearchParams object
|
827
|
+
*
|
828
|
+
* @param {*} val The value to test
|
829
|
+
*
|
830
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
831
|
+
*/ const isURLSearchParams = kindOfTest('URLSearchParams');
|
832
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = [
|
833
|
+
'ReadableStream',
|
834
|
+
'Request',
|
835
|
+
'Response',
|
836
|
+
'Headers'
|
837
|
+
].map(kindOfTest);
|
838
|
+
/**
|
839
|
+
* Trim excess whitespace off the beginning and end of a string
|
840
|
+
*
|
841
|
+
* @param {String} str The String to trim
|
842
|
+
*
|
843
|
+
* @returns {String} The String freed of excess whitespace
|
844
|
+
*/ const trim = (str)=>str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
845
|
+
/**
|
846
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
847
|
+
*
|
848
|
+
* If `obj` is an Array callback will be called passing
|
849
|
+
* the value, index, and complete array for each item.
|
850
|
+
*
|
851
|
+
* If 'obj' is an Object callback will be called passing
|
852
|
+
* the value, key, and complete object for each property.
|
853
|
+
*
|
854
|
+
* @param {Object|Array} obj The object to iterate
|
855
|
+
* @param {Function} fn The callback to invoke for each item
|
856
|
+
*
|
857
|
+
* @param {Boolean} [allOwnKeys = false]
|
858
|
+
* @returns {any}
|
859
|
+
*/ function forEach(obj, fn, { allOwnKeys = false } = {}) {
|
860
|
+
// Don't bother if no value provided
|
861
|
+
if (null == obj) return;
|
862
|
+
let i;
|
863
|
+
let l;
|
864
|
+
// Force an array if not already something iterable
|
865
|
+
if ('object' != typeof obj) /*eslint no-param-reassign:0*/ obj = [
|
866
|
+
obj
|
867
|
+
];
|
868
|
+
if (isArray(obj)) // Iterate over array values
|
869
|
+
for(i = 0, l = obj.length; i < l; i++)fn.call(null, obj[i], i, obj);
|
870
|
+
else {
|
871
|
+
// Iterate over object keys
|
872
|
+
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
873
|
+
const len = keys.length;
|
874
|
+
let key;
|
875
|
+
for(i = 0; i < len; i++){
|
876
|
+
key = keys[i];
|
877
|
+
fn.call(null, obj[key], key, obj);
|
878
|
+
}
|
879
|
+
}
|
880
|
+
}
|
881
|
+
function findKey(obj, key) {
|
882
|
+
key = key.toLowerCase();
|
883
|
+
const keys = Object.keys(obj);
|
884
|
+
let i = keys.length;
|
885
|
+
let _key;
|
886
|
+
while(i-- > 0){
|
887
|
+
_key = keys[i];
|
888
|
+
if (key === _key.toLowerCase()) return _key;
|
889
|
+
}
|
890
|
+
return null;
|
891
|
+
}
|
892
|
+
const _global = (()=>{
|
893
|
+
/*eslint no-undef:0*/ if ("undefined" != typeof globalThis) return globalThis;
|
894
|
+
return "undefined" != typeof self ? self : 'undefined' != typeof window ? window : global;
|
895
|
+
})();
|
896
|
+
const isContextDefined = (context)=>!isUndefined(context) && context !== _global;
|
897
|
+
/**
|
898
|
+
* Accepts varargs expecting each argument to be an object, then
|
899
|
+
* immutably merges the properties of each object and returns result.
|
900
|
+
*
|
901
|
+
* When multiple objects contain the same key the later object in
|
902
|
+
* the arguments list will take precedence.
|
903
|
+
*
|
904
|
+
* Example:
|
905
|
+
*
|
906
|
+
* ```js
|
907
|
+
* var result = merge({foo: 123}, {foo: 456});
|
908
|
+
* console.log(result.foo); // outputs 456
|
909
|
+
* ```
|
910
|
+
*
|
911
|
+
* @param {Object} obj1 Object to merge
|
912
|
+
*
|
913
|
+
* @returns {Object} Result of all merge properties
|
914
|
+
*/ function utils_merge() {
|
915
|
+
const { caseless } = isContextDefined(this) && this || {};
|
916
|
+
const result = {};
|
917
|
+
const assignValue = (val, key)=>{
|
918
|
+
const targetKey = caseless && findKey(result, key) || key;
|
919
|
+
if (utils_isPlainObject(result[targetKey]) && utils_isPlainObject(val)) result[targetKey] = utils_merge(result[targetKey], val);
|
920
|
+
else if (utils_isPlainObject(val)) result[targetKey] = utils_merge({}, val);
|
921
|
+
else if (isArray(val)) result[targetKey] = val.slice();
|
922
|
+
else result[targetKey] = val;
|
923
|
+
};
|
924
|
+
for(let i = 0, l = arguments.length; i < l; i++)arguments[i] && forEach(arguments[i], assignValue);
|
925
|
+
return result;
|
926
|
+
}
|
927
|
+
/**
|
928
|
+
* Extends object a by mutably adding to it the properties of object b.
|
929
|
+
*
|
930
|
+
* @param {Object} a The object to be extended
|
931
|
+
* @param {Object} b The object to copy properties from
|
932
|
+
* @param {Object} thisArg The object to bind function to
|
933
|
+
*
|
934
|
+
* @param {Boolean} [allOwnKeys]
|
935
|
+
* @returns {Object} The resulting value of object a
|
936
|
+
*/ const extend = (a, b, thisArg, { allOwnKeys } = {})=>{
|
937
|
+
forEach(b, (val, key)=>{
|
938
|
+
if (thisArg && isFunction(val)) a[key] = bind(val, thisArg);
|
939
|
+
else a[key] = val;
|
940
|
+
}, {
|
941
|
+
allOwnKeys
|
942
|
+
});
|
943
|
+
return a;
|
944
|
+
};
|
945
|
+
/**
|
946
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
947
|
+
*
|
948
|
+
* @param {string} content with BOM
|
949
|
+
*
|
950
|
+
* @returns {string} content value without BOM
|
951
|
+
*/ const stripBOM = (content)=>{
|
952
|
+
if (0xFEFF === content.charCodeAt(0)) content = content.slice(1);
|
953
|
+
return content;
|
954
|
+
};
|
955
|
+
/**
|
956
|
+
* Inherit the prototype methods from one constructor into another
|
957
|
+
* @param {function} constructor
|
958
|
+
* @param {function} superConstructor
|
959
|
+
* @param {object} [props]
|
960
|
+
* @param {object} [descriptors]
|
961
|
+
*
|
962
|
+
* @returns {void}
|
963
|
+
*/ const inherits = (constructor, superConstructor, props, descriptors)=>{
|
964
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
965
|
+
constructor.prototype.constructor = constructor;
|
966
|
+
Object.defineProperty(constructor, 'super', {
|
967
|
+
value: superConstructor.prototype
|
968
|
+
});
|
969
|
+
props && Object.assign(constructor.prototype, props);
|
970
|
+
};
|
971
|
+
/**
|
972
|
+
* Resolve object with deep prototype chain to a flat object
|
973
|
+
* @param {Object} sourceObj source object
|
974
|
+
* @param {Object} [destObj]
|
975
|
+
* @param {Function|Boolean} [filter]
|
976
|
+
* @param {Function} [propFilter]
|
977
|
+
*
|
978
|
+
* @returns {Object}
|
979
|
+
*/ const toFlatObject = (sourceObj, destObj, filter, propFilter)=>{
|
980
|
+
let props;
|
981
|
+
let i;
|
982
|
+
let prop;
|
983
|
+
const merged = {};
|
984
|
+
destObj = destObj || {};
|
985
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
986
|
+
if (null == sourceObj) return destObj;
|
987
|
+
do {
|
988
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
989
|
+
i = props.length;
|
990
|
+
while(i-- > 0){
|
991
|
+
prop = props[i];
|
992
|
+
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
993
|
+
destObj[prop] = sourceObj[prop];
|
994
|
+
merged[prop] = true;
|
995
|
+
}
|
996
|
+
}
|
997
|
+
sourceObj = false !== filter && getPrototypeOf(sourceObj);
|
998
|
+
}while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
999
|
+
return destObj;
|
1000
|
+
};
|
1001
|
+
/**
|
1002
|
+
* Determines whether a string ends with the characters of a specified string
|
1003
|
+
*
|
1004
|
+
* @param {String} str
|
1005
|
+
* @param {String} searchString
|
1006
|
+
* @param {Number} [position= 0]
|
1007
|
+
*
|
1008
|
+
* @returns {boolean}
|
1009
|
+
*/ const endsWith = (str, searchString, position)=>{
|
1010
|
+
str = String(str);
|
1011
|
+
if (void 0 === position || position > str.length) position = str.length;
|
1012
|
+
position -= searchString.length;
|
1013
|
+
const lastIndex = str.indexOf(searchString, position);
|
1014
|
+
return -1 !== lastIndex && lastIndex === position;
|
1015
|
+
};
|
1016
|
+
/**
|
1017
|
+
* Returns new array from array like object or null if failed
|
1018
|
+
*
|
1019
|
+
* @param {*} [thing]
|
1020
|
+
*
|
1021
|
+
* @returns {?Array}
|
1022
|
+
*/ const toArray = (thing)=>{
|
1023
|
+
if (!thing) return null;
|
1024
|
+
if (isArray(thing)) return thing;
|
1025
|
+
let i = thing.length;
|
1026
|
+
if (!isNumber(i)) return null;
|
1027
|
+
const arr = new Array(i);
|
1028
|
+
while(i-- > 0)arr[i] = thing[i];
|
1029
|
+
return arr;
|
1030
|
+
};
|
1031
|
+
/**
|
1032
|
+
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
1033
|
+
* thing passed in is an instance of Uint8Array
|
1034
|
+
*
|
1035
|
+
* @param {TypedArray}
|
1036
|
+
*
|
1037
|
+
* @returns {Array}
|
1038
|
+
*/ // eslint-disable-next-line func-names
|
1039
|
+
const isTypedArray = ((TypedArray)=>(thing)=>TypedArray && thing instanceof TypedArray)('undefined' != typeof Uint8Array && getPrototypeOf(Uint8Array));
|
1040
|
+
/**
|
1041
|
+
* For each entry in the object, call the function with the key and value.
|
1042
|
+
*
|
1043
|
+
* @param {Object<any, any>} obj - The object to iterate over.
|
1044
|
+
* @param {Function} fn - The function to call for each entry.
|
1045
|
+
*
|
1046
|
+
* @returns {void}
|
1047
|
+
*/ const forEachEntry = (obj, fn)=>{
|
1048
|
+
const generator = obj && obj[Symbol.iterator];
|
1049
|
+
const iterator = generator.call(obj);
|
1050
|
+
let result;
|
1051
|
+
while((result = iterator.next()) && !result.done){
|
1052
|
+
const pair = result.value;
|
1053
|
+
fn.call(obj, pair[0], pair[1]);
|
1054
|
+
}
|
1055
|
+
};
|
1056
|
+
/**
|
1057
|
+
* It takes a regular expression and a string, and returns an array of all the matches
|
1058
|
+
*
|
1059
|
+
* @param {string} regExp - The regular expression to match against.
|
1060
|
+
* @param {string} str - The string to search.
|
1061
|
+
*
|
1062
|
+
* @returns {Array<boolean>}
|
1063
|
+
*/ const matchAll = (regExp, str)=>{
|
1064
|
+
let matches;
|
1065
|
+
const arr = [];
|
1066
|
+
while(null !== (matches = regExp.exec(str)))arr.push(matches);
|
1067
|
+
return arr;
|
1068
|
+
};
|
1069
|
+
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */ const isHTMLForm = kindOfTest('HTMLFormElement');
|
1070
|
+
const toCamelCase = (str)=>str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g, function(m, p1, p2) {
|
1071
|
+
return p1.toUpperCase() + p2;
|
1072
|
+
});
|
1073
|
+
/* Creating a function that will check if an object has a property. */ const utils_hasOwnProperty = (({ hasOwnProperty })=>(obj, prop)=>hasOwnProperty.call(obj, prop))(Object.prototype);
|
1074
|
+
/**
|
1075
|
+
* Determine if a value is a RegExp object
|
1076
|
+
*
|
1077
|
+
* @param {*} val The value to test
|
1078
|
+
*
|
1079
|
+
* @returns {boolean} True if value is a RegExp object, otherwise false
|
1080
|
+
*/ const isRegExp = kindOfTest('RegExp');
|
1081
|
+
const reduceDescriptors = (obj, reducer)=>{
|
1082
|
+
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
1083
|
+
const reducedDescriptors = {};
|
1084
|
+
forEach(descriptors, (descriptor, name)=>{
|
1085
|
+
let ret;
|
1086
|
+
if (false !== (ret = reducer(descriptor, name, obj))) reducedDescriptors[name] = ret || descriptor;
|
1087
|
+
});
|
1088
|
+
Object.defineProperties(obj, reducedDescriptors);
|
1089
|
+
};
|
1090
|
+
/**
|
1091
|
+
* Makes all methods read-only
|
1092
|
+
* @param {Object} obj
|
1093
|
+
*/ const freezeMethods = (obj)=>{
|
1094
|
+
reduceDescriptors(obj, (descriptor, name)=>{
|
1095
|
+
// skip restricted props in strict mode
|
1096
|
+
if (isFunction(obj) && -1 !== [
|
1097
|
+
'arguments',
|
1098
|
+
'caller',
|
1099
|
+
'callee'
|
1100
|
+
].indexOf(name)) return false;
|
1101
|
+
const value = obj[name];
|
1102
|
+
if (!isFunction(value)) return;
|
1103
|
+
descriptor.enumerable = false;
|
1104
|
+
if ('writable' in descriptor) {
|
1105
|
+
descriptor.writable = false;
|
1106
|
+
return;
|
1107
|
+
}
|
1108
|
+
if (!descriptor.set) descriptor.set = ()=>{
|
1109
|
+
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
1110
|
+
};
|
1111
|
+
});
|
1112
|
+
};
|
1113
|
+
const toObjectSet = (arrayOrString, delimiter)=>{
|
1114
|
+
const obj = {};
|
1115
|
+
const define1 = (arr)=>{
|
1116
|
+
arr.forEach((value)=>{
|
1117
|
+
obj[value] = true;
|
1118
|
+
});
|
1119
|
+
};
|
1120
|
+
isArray(arrayOrString) ? define1(arrayOrString) : define1(String(arrayOrString).split(delimiter));
|
1121
|
+
return obj;
|
1122
|
+
};
|
1123
|
+
const noop = ()=>{};
|
1124
|
+
const toFiniteNumber = (value, defaultValue)=>null != value && Number.isFinite(value = +value) ? value : defaultValue;
|
1125
|
+
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
1126
|
+
const DIGIT = '0123456789';
|
1127
|
+
const ALPHABET = {
|
1128
|
+
DIGIT,
|
1129
|
+
ALPHA,
|
1130
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
1131
|
+
};
|
1132
|
+
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT)=>{
|
1133
|
+
let str = '';
|
1134
|
+
const { length } = alphabet;
|
1135
|
+
while(size--)str += alphabet[Math.random() * length | 0];
|
1136
|
+
return str;
|
1137
|
+
};
|
1138
|
+
/**
|
1139
|
+
* If the thing is a FormData object, return true, otherwise return false.
|
1140
|
+
*
|
1141
|
+
* @param {unknown} thing - The thing to check.
|
1142
|
+
*
|
1143
|
+
* @returns {boolean}
|
1144
|
+
*/ function isSpecCompliantForm(thing) {
|
1145
|
+
return !!(thing && isFunction(thing.append) && 'FormData' === thing[Symbol.toStringTag] && thing[Symbol.iterator]);
|
1146
|
+
}
|
1147
|
+
const toJSONObject = (obj)=>{
|
1148
|
+
const stack = new Array(10);
|
1149
|
+
const visit = (source, i)=>{
|
551
1150
|
if (isObject(source)) {
|
552
1151
|
if (stack.indexOf(source) >= 0) return;
|
553
1152
|
if (!('toJSON' in source)) {
|
@@ -593,7 +1192,7 @@
|
|
593
1192
|
isNumber,
|
594
1193
|
isBoolean,
|
595
1194
|
isObject,
|
596
|
-
isPlainObject,
|
1195
|
+
isPlainObject: utils_isPlainObject,
|
597
1196
|
isReadableStream,
|
598
1197
|
isRequest,
|
599
1198
|
isResponse,
|
@@ -1068,14 +1667,14 @@
|
|
1068
1667
|
*/ const hasStandardBrowserWebWorkerEnv = (()=>'undefined' != typeof WorkerGlobalScope && // eslint-disable-next-line no-undef
|
1069
1668
|
self instanceof WorkerGlobalScope && 'function' == typeof self.importScripts)();
|
1070
1669
|
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
1071
|
-
/* ESM default export */ const
|
1670
|
+
/* ESM default export */ const lib_platform = {
|
1072
1671
|
...common_utils_namespaceObject,
|
1073
1672
|
...browser
|
1074
1673
|
};
|
1075
1674
|
function toURLEncodedForm(data, options) {
|
1076
|
-
return toFormData(data, new
|
1675
|
+
return toFormData(data, new lib_platform.classes.URLSearchParams(), Object.assign({
|
1077
1676
|
visitor: function(value, key, path, helpers) {
|
1078
|
-
if (
|
1677
|
+
if (lib_platform.isNode && utils.isBuffer(value)) {
|
1079
1678
|
this.append(key, value.toString('base64'));
|
1080
1679
|
return false;
|
1081
1680
|
}
|
@@ -1236,8 +1835,8 @@
|
|
1236
1835
|
maxContentLength: -1,
|
1237
1836
|
maxBodyLength: -1,
|
1238
1837
|
env: {
|
1239
|
-
FormData:
|
1240
|
-
Blob:
|
1838
|
+
FormData: lib_platform.classes.FormData,
|
1839
|
+
Blob: lib_platform.classes.Blob
|
1241
1840
|
},
|
1242
1841
|
validateStatus: function(status) {
|
1243
1842
|
return status >= 200 && status < 300;
|
@@ -1671,10 +2270,10 @@
|
|
1671
2270
|
];
|
1672
2271
|
};
|
1673
2272
|
const asyncDecorator = (fn)=>(...args)=>utils.asap(()=>fn(...args));
|
1674
|
-
/* ESM default export */ const helpers_isURLSameOrigin =
|
2273
|
+
/* ESM default export */ const helpers_isURLSameOrigin = lib_platform.hasStandardBrowserEnv ? // Standard browser envs have full support of the APIs needed to test
|
1675
2274
|
// whether the request URL is of the same origin as current location.
|
1676
2275
|
function() {
|
1677
|
-
const msie =
|
2276
|
+
const msie = lib_platform.navigator && /(msie|trident)/i.test(lib_platform.navigator.userAgent);
|
1678
2277
|
const urlParsingNode = document.createElement('a');
|
1679
2278
|
let originURL;
|
1680
2279
|
/**
|
@@ -1718,7 +2317,7 @@
|
|
1718
2317
|
return true;
|
1719
2318
|
};
|
1720
2319
|
}();
|
1721
|
-
/* ESM default export */ const cookies =
|
2320
|
+
/* ESM default export */ const cookies = lib_platform.hasStandardBrowserEnv ? // Standard browser envs support document.cookie
|
1722
2321
|
{
|
1723
2322
|
write (name, value, expires, path, domain, secure) {
|
1724
2323
|
const cookie = [
|
@@ -1791,7 +2390,7 @@
|
|
1791
2390
|
* @param {Object} config2
|
1792
2391
|
*
|
1793
2392
|
* @returns {Object} New object resulting from merging config2 to config1
|
1794
|
-
*/ function
|
2393
|
+
*/ function mergeConfig_mergeConfig(config1, config2) {
|
1795
2394
|
// eslint-disable-next-line no-param-reassign
|
1796
2395
|
config2 = config2 || {};
|
1797
2396
|
const config = {};
|
@@ -1861,7 +2460,7 @@
|
|
1861
2460
|
return config;
|
1862
2461
|
}
|
1863
2462
|
/* ESM default export */ const resolveConfig = (config)=>{
|
1864
|
-
const newConfig =
|
2463
|
+
const newConfig = mergeConfig_mergeConfig({}, config);
|
1865
2464
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
1866
2465
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
1867
2466
|
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
@@ -1869,7 +2468,7 @@
|
|
1869
2468
|
if (auth) headers.set('Authorization', 'Basic ' + btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : '')));
|
1870
2469
|
let contentType;
|
1871
2470
|
if (utils.isFormData(data)) {
|
1872
|
-
if (
|
2471
|
+
if (lib_platform.hasStandardBrowserEnv || lib_platform.hasStandardBrowserWebWorkerEnv) headers.setContentType(void 0); // Let the browser set it
|
1873
2472
|
else if (false !== (contentType = headers.getContentType())) {
|
1874
2473
|
// fix semicolon duplication issue for ReactNative FormData implementation
|
1875
2474
|
const [type, ...tokens] = contentType ? contentType.split(';').map((token)=>token.trim()).filter(Boolean) : [];
|
@@ -1882,7 +2481,7 @@
|
|
1882
2481
|
// Add xsrf header
|
1883
2482
|
// This is only done if running in a standard browser environment.
|
1884
2483
|
// Specifically not if we're in a web worker, or react-native.
|
1885
|
-
if (
|
2484
|
+
if (lib_platform.hasStandardBrowserEnv) {
|
1886
2485
|
withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
1887
2486
|
if (withXSRFToken || false !== withXSRFToken && helpers_isURLSameOrigin(newConfig.url)) {
|
1888
2487
|
// Add xsrf header
|
@@ -2007,7 +2606,7 @@
|
|
2007
2606
|
if (_config.signal) _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
|
2008
2607
|
}
|
2009
2608
|
const protocol = parseProtocol(_config.url);
|
2010
|
-
if (protocol && -1 ===
|
2609
|
+
if (protocol && -1 === lib_platform.protocols.indexOf(protocol)) {
|
2011
2610
|
reject(new core_AxiosError('Unsupported protocol ' + protocol + ':', core_AxiosError.ERR_BAD_REQUEST, config));
|
2012
2611
|
return;
|
2013
2612
|
}
|
@@ -2119,7 +2718,7 @@
|
|
2119
2718
|
}, {
|
2120
2719
|
highWaterMark: 2
|
2121
2720
|
});
|
2122
|
-
}; // CONCATENATED MODULE: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7/node_modules/axios/lib/adapters/fetch.js
|
2721
|
+
}; // CONCATENATED MODULE: ../../common/temp/default/node_modules/.pnpm/axios@1.7.7_debug@4.3.7/node_modules/axios/lib/adapters/fetch.js
|
2123
2722
|
const isFetchSupported = 'function' == typeof fetch && 'function' == typeof Request && 'function' == typeof Response;
|
2124
2723
|
const isReadableStreamSupported = isFetchSupported && 'function' == typeof ReadableStream;
|
2125
2724
|
// used only inside the fetch adapter
|
@@ -2133,7 +2732,7 @@
|
|
2133
2732
|
};
|
2134
2733
|
const supportsRequestStream = isReadableStreamSupported && test(()=>{
|
2135
2734
|
let duplexAccessed = false;
|
2136
|
-
const hasContentType = new Request(
|
2735
|
+
const hasContentType = new Request(lib_platform.origin, {
|
2137
2736
|
body: new ReadableStream(),
|
2138
2737
|
method: 'POST',
|
2139
2738
|
get duplex () {
|
@@ -2165,7 +2764,7 @@
|
|
2165
2764
|
if (null == body) return 0;
|
2166
2765
|
if (utils.isBlob(body)) return body.size;
|
2167
2766
|
if (utils.isSpecCompliantForm(body)) {
|
2168
|
-
const _request = new Request(
|
2767
|
+
const _request = new Request(lib_platform.origin, {
|
2169
2768
|
method: 'POST',
|
2170
2769
|
body
|
2171
2770
|
});
|
@@ -2467,7 +3066,7 @@
|
|
2467
3066
|
config = config || {};
|
2468
3067
|
config.url = configOrUrl;
|
2469
3068
|
} else config = configOrUrl || {};
|
2470
|
-
config =
|
3069
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
2471
3070
|
const { transitional, paramsSerializer, headers } = config;
|
2472
3071
|
if (void 0 !== transitional) helpers_validator.assertOptions(transitional, {
|
2473
3072
|
silentJSONParsing: Axios_validators.transitional(Axios_validators.boolean),
|
@@ -2549,836 +3148,297 @@
|
|
2549
3148
|
while(i < len)promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
2550
3149
|
return promise;
|
2551
3150
|
}
|
2552
|
-
getUri(config) {
|
2553
|
-
config =
|
2554
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
2555
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2556
|
-
}
|
2557
|
-
}
|
2558
|
-
// Provide aliases for supported request methods
|
2559
|
-
utils.forEach([
|
2560
|
-
'delete',
|
2561
|
-
'get',
|
2562
|
-
'head',
|
2563
|
-
'options'
|
2564
|
-
], function(method) {
|
2565
|
-
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
2566
|
-
return this.request(mergeConfig(config || {}, {
|
2567
|
-
method,
|
2568
|
-
url,
|
2569
|
-
data: (config || {}).data
|
2570
|
-
}));
|
2571
|
-
};
|
2572
|
-
});
|
2573
|
-
utils.forEach([
|
2574
|
-
'post',
|
2575
|
-
'put',
|
2576
|
-
'patch'
|
2577
|
-
], function(method) {
|
2578
|
-
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
2579
|
-
return function(url, data, config) {
|
2580
|
-
return this.request(mergeConfig(config || {}, {
|
2581
|
-
method,
|
2582
|
-
headers: isForm ? {
|
2583
|
-
'Content-Type': 'multipart/form-data'
|
2584
|
-
} : {},
|
2585
|
-
url,
|
2586
|
-
data
|
2587
|
-
}));
|
2588
|
-
};
|
2589
|
-
}
|
2590
|
-
Axios_Axios.prototype[method] = generateHTTPMethod();
|
2591
|
-
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2592
|
-
});
|
2593
|
-
/* ESM default export */ const Axios = Axios_Axios;
|
2594
|
-
/**
|
2595
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2596
|
-
*
|
2597
|
-
* @param {Function} executor The executor function.
|
2598
|
-
*
|
2599
|
-
* @returns {CancelToken}
|
2600
|
-
*/ class CancelToken_CancelToken {
|
2601
|
-
constructor(executor){
|
2602
|
-
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
2603
|
-
let resolvePromise;
|
2604
|
-
this.promise = new Promise(function(resolve) {
|
2605
|
-
resolvePromise = resolve;
|
2606
|
-
});
|
2607
|
-
const token = this;
|
2608
|
-
// eslint-disable-next-line func-names
|
2609
|
-
this.promise.then((cancel)=>{
|
2610
|
-
if (!token._listeners) return;
|
2611
|
-
let i = token._listeners.length;
|
2612
|
-
while(i-- > 0)token._listeners[i](cancel);
|
2613
|
-
token._listeners = null;
|
2614
|
-
});
|
2615
|
-
// eslint-disable-next-line func-names
|
2616
|
-
this.promise.then = (onfulfilled)=>{
|
2617
|
-
let _resolve;
|
2618
|
-
// eslint-disable-next-line func-names
|
2619
|
-
const promise = new Promise((resolve)=>{
|
2620
|
-
token.subscribe(resolve);
|
2621
|
-
_resolve = resolve;
|
2622
|
-
}).then(onfulfilled);
|
2623
|
-
promise.cancel = function() {
|
2624
|
-
token.unsubscribe(_resolve);
|
2625
|
-
};
|
2626
|
-
return promise;
|
2627
|
-
};
|
2628
|
-
executor(function(message, config, request) {
|
2629
|
-
if (token.reason) // Cancellation has already been requested
|
2630
|
-
return;
|
2631
|
-
token.reason = new CanceledError(message, config, request);
|
2632
|
-
resolvePromise(token.reason);
|
2633
|
-
});
|
2634
|
-
}
|
2635
|
-
/**
|
2636
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
2637
|
-
*/ throwIfRequested() {
|
2638
|
-
if (this.reason) throw this.reason;
|
2639
|
-
}
|
2640
|
-
/**
|
2641
|
-
* Subscribe to the cancel signal
|
2642
|
-
*/ subscribe(listener) {
|
2643
|
-
if (this.reason) {
|
2644
|
-
listener(this.reason);
|
2645
|
-
return;
|
2646
|
-
}
|
2647
|
-
if (this._listeners) this._listeners.push(listener);
|
2648
|
-
else this._listeners = [
|
2649
|
-
listener
|
2650
|
-
];
|
2651
|
-
}
|
2652
|
-
/**
|
2653
|
-
* Unsubscribe from the cancel signal
|
2654
|
-
*/ unsubscribe(listener) {
|
2655
|
-
if (!this._listeners) return;
|
2656
|
-
const index = this._listeners.indexOf(listener);
|
2657
|
-
if (-1 !== index) this._listeners.splice(index, 1);
|
2658
|
-
}
|
2659
|
-
toAbortSignal() {
|
2660
|
-
const controller = new AbortController();
|
2661
|
-
const abort = (err)=>{
|
2662
|
-
controller.abort(err);
|
2663
|
-
};
|
2664
|
-
this.subscribe(abort);
|
2665
|
-
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
2666
|
-
return controller.signal;
|
2667
|
-
}
|
2668
|
-
/**
|
2669
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2670
|
-
* cancels the `CancelToken`.
|
2671
|
-
*/ static source() {
|
2672
|
-
let cancel;
|
2673
|
-
const token = new CancelToken_CancelToken(function(c) {
|
2674
|
-
cancel = c;
|
2675
|
-
});
|
2676
|
-
return {
|
2677
|
-
token,
|
2678
|
-
cancel
|
2679
|
-
};
|
2680
|
-
}
|
2681
|
-
}
|
2682
|
-
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
2683
|
-
/**
|
2684
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2685
|
-
*
|
2686
|
-
* Common use case would be to use `Function.prototype.apply`.
|
2687
|
-
*
|
2688
|
-
* ```js
|
2689
|
-
* function f(x, y, z) {}
|
2690
|
-
* var args = [1, 2, 3];
|
2691
|
-
* f.apply(null, args);
|
2692
|
-
* ```
|
2693
|
-
*
|
2694
|
-
* With `spread` this example can be re-written.
|
2695
|
-
*
|
2696
|
-
* ```js
|
2697
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
2698
|
-
* ```
|
2699
|
-
*
|
2700
|
-
* @param {Function} callback
|
2701
|
-
*
|
2702
|
-
* @returns {Function}
|
2703
|
-
*/ function spread(callback) {
|
2704
|
-
return function(arr) {
|
2705
|
-
return callback.apply(null, arr);
|
2706
|
-
};
|
2707
|
-
}
|
2708
|
-
/**
|
2709
|
-
* Determines whether the payload is an error thrown by Axios
|
2710
|
-
*
|
2711
|
-
* @param {*} payload The value to test
|
2712
|
-
*
|
2713
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2714
|
-
*/ function isAxiosError(payload) {
|
2715
|
-
return utils.isObject(payload) && true === payload.isAxiosError;
|
2716
|
-
}
|
2717
|
-
const HttpStatusCode = {
|
2718
|
-
Continue: 100,
|
2719
|
-
SwitchingProtocols: 101,
|
2720
|
-
Processing: 102,
|
2721
|
-
EarlyHints: 103,
|
2722
|
-
Ok: 200,
|
2723
|
-
Created: 201,
|
2724
|
-
Accepted: 202,
|
2725
|
-
NonAuthoritativeInformation: 203,
|
2726
|
-
NoContent: 204,
|
2727
|
-
ResetContent: 205,
|
2728
|
-
PartialContent: 206,
|
2729
|
-
MultiStatus: 207,
|
2730
|
-
AlreadyReported: 208,
|
2731
|
-
ImUsed: 226,
|
2732
|
-
MultipleChoices: 300,
|
2733
|
-
MovedPermanently: 301,
|
2734
|
-
Found: 302,
|
2735
|
-
SeeOther: 303,
|
2736
|
-
NotModified: 304,
|
2737
|
-
UseProxy: 305,
|
2738
|
-
Unused: 306,
|
2739
|
-
TemporaryRedirect: 307,
|
2740
|
-
PermanentRedirect: 308,
|
2741
|
-
BadRequest: 400,
|
2742
|
-
Unauthorized: 401,
|
2743
|
-
PaymentRequired: 402,
|
2744
|
-
Forbidden: 403,
|
2745
|
-
NotFound: 404,
|
2746
|
-
MethodNotAllowed: 405,
|
2747
|
-
NotAcceptable: 406,
|
2748
|
-
ProxyAuthenticationRequired: 407,
|
2749
|
-
RequestTimeout: 408,
|
2750
|
-
Conflict: 409,
|
2751
|
-
Gone: 410,
|
2752
|
-
LengthRequired: 411,
|
2753
|
-
PreconditionFailed: 412,
|
2754
|
-
PayloadTooLarge: 413,
|
2755
|
-
UriTooLong: 414,
|
2756
|
-
UnsupportedMediaType: 415,
|
2757
|
-
RangeNotSatisfiable: 416,
|
2758
|
-
ExpectationFailed: 417,
|
2759
|
-
ImATeapot: 418,
|
2760
|
-
MisdirectedRequest: 421,
|
2761
|
-
UnprocessableEntity: 422,
|
2762
|
-
Locked: 423,
|
2763
|
-
FailedDependency: 424,
|
2764
|
-
TooEarly: 425,
|
2765
|
-
UpgradeRequired: 426,
|
2766
|
-
PreconditionRequired: 428,
|
2767
|
-
TooManyRequests: 429,
|
2768
|
-
RequestHeaderFieldsTooLarge: 431,
|
2769
|
-
UnavailableForLegalReasons: 451,
|
2770
|
-
InternalServerError: 500,
|
2771
|
-
NotImplemented: 501,
|
2772
|
-
BadGateway: 502,
|
2773
|
-
ServiceUnavailable: 503,
|
2774
|
-
GatewayTimeout: 504,
|
2775
|
-
HttpVersionNotSupported: 505,
|
2776
|
-
VariantAlsoNegotiates: 506,
|
2777
|
-
InsufficientStorage: 507,
|
2778
|
-
LoopDetected: 508,
|
2779
|
-
NotExtended: 510,
|
2780
|
-
NetworkAuthenticationRequired: 511
|
2781
|
-
};
|
2782
|
-
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
2783
|
-
HttpStatusCode[value] = key;
|
2784
|
-
});
|
2785
|
-
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
2786
|
-
/**
|
2787
|
-
* Create an instance of Axios
|
2788
|
-
*
|
2789
|
-
* @param {Object} defaultConfig The default config for the instance
|
2790
|
-
*
|
2791
|
-
* @returns {Axios} A new instance of Axios
|
2792
|
-
*/ function createInstance(defaultConfig) {
|
2793
|
-
const context = new Axios(defaultConfig);
|
2794
|
-
const instance = bind(Axios.prototype.request, context);
|
2795
|
-
// Copy axios.prototype to instance
|
2796
|
-
utils.extend(instance, Axios.prototype, context, {
|
2797
|
-
allOwnKeys: true
|
2798
|
-
});
|
2799
|
-
// Copy context to instance
|
2800
|
-
utils.extend(instance, context, null, {
|
2801
|
-
allOwnKeys: true
|
2802
|
-
});
|
2803
|
-
// Factory for creating new instances
|
2804
|
-
instance.create = function(instanceConfig) {
|
2805
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2806
|
-
};
|
2807
|
-
return instance;
|
2808
|
-
}
|
2809
|
-
// Create the default instance to be exported
|
2810
|
-
const axios = createInstance(defaults);
|
2811
|
-
// Expose Axios class to allow class inheritance
|
2812
|
-
axios.Axios = Axios;
|
2813
|
-
// Expose Cancel & CancelToken
|
2814
|
-
axios.CanceledError = CanceledError;
|
2815
|
-
axios.CancelToken = CancelToken;
|
2816
|
-
axios.isCancel = isCancel;
|
2817
|
-
axios.VERSION = VERSION;
|
2818
|
-
axios.toFormData = toFormData;
|
2819
|
-
// Expose AxiosError class
|
2820
|
-
axios.AxiosError = core_AxiosError;
|
2821
|
-
// alias for CanceledError for backward compatibility
|
2822
|
-
axios.Cancel = axios.CanceledError;
|
2823
|
-
// Expose all/spread
|
2824
|
-
axios.all = function(promises) {
|
2825
|
-
return Promise.all(promises);
|
2826
|
-
};
|
2827
|
-
axios.spread = spread;
|
2828
|
-
// Expose isAxiosError
|
2829
|
-
axios.isAxiosError = isAxiosError;
|
2830
|
-
// Expose mergeConfig
|
2831
|
-
axios.mergeConfig = mergeConfig;
|
2832
|
-
axios.AxiosHeaders = AxiosHeaders;
|
2833
|
-
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2834
|
-
axios.getAdapter = adapters_adapters.getAdapter;
|
2835
|
-
axios.HttpStatusCode = helpers_HttpStatusCode;
|
2836
|
-
axios.default = axios;
|
2837
|
-
// this module should only have a default export
|
2838
|
-
/* ESM default export */ const lib_axios = axios;
|
2839
|
-
// This module is intended to unwrap Axios default export as named.
|
2840
|
-
// Keep top-level export same with static properties
|
2841
|
-
// so that it can keep same with es module or cjs
|
2842
|
-
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;
|
2843
|
-
var __webpack_modules__ = {
|
2844
|
-
"?6728": function() {
|
2845
|
-
/* (ignored) */ }
|
2846
|
-
};
|
2847
|
-
/************************************************************************/ // The module cache
|
2848
|
-
var __webpack_module_cache__ = {};
|
2849
|
-
// The require function
|
2850
|
-
function __nested_webpack_require_293__(moduleId) {
|
2851
|
-
// Check if module is in cache
|
2852
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
2853
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
2854
|
-
// Create a new module (and put it into the cache)
|
2855
|
-
var module1 = __webpack_module_cache__[moduleId] = {
|
2856
|
-
exports: {}
|
2857
|
-
};
|
2858
|
-
// Execute the module function
|
2859
|
-
__webpack_modules__[moduleId](module1, module1.exports, __nested_webpack_require_293__);
|
2860
|
-
// Return the exports of the module
|
2861
|
-
return module1.exports;
|
2862
|
-
} /************************************************************************/
|
2863
|
-
class APIResource {
|
2864
|
-
constructor(client){
|
2865
|
-
this._client = client;
|
2866
|
-
}
|
2867
|
-
}
|
2868
|
-
/* eslint-disable @typescript-eslint/no-namespace */ class Bots extends APIResource {
|
2869
|
-
/**
|
2870
|
-
* Create a new agent. | 调用接口创建一个新的智能体。
|
2871
|
-
* @docs en:https://www.coze.com/docs/developer_guides/create_bot?_lang=en
|
2872
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/create_bot?_lang=zh
|
2873
|
-
* @param params - Required The parameters for creating a bot. | 创建 Bot 的参数。
|
2874
|
-
* @param params.space_id - Required The Space ID of the space where the agent is located. | Bot 所在的空间的 Space ID。
|
2875
|
-
* @param params.name - Required The name of the agent. It should be 1 to 20 characters long. | Bot 的名称。
|
2876
|
-
* @param params.description - Optional The description of the agent. It can be 0 to 500 characters long. | Bot 的描述信息。
|
2877
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2878
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2879
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2880
|
-
* @returns Information about the created bot. | 创建的 Bot 信息。
|
2881
|
-
*/ async create(params, options) {
|
2882
|
-
const apiUrl = '/v1/bot/create';
|
2883
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2884
|
-
return result.data;
|
2885
|
-
}
|
2886
|
-
/**
|
2887
|
-
* Update the configuration of an agent. | 调用接口修改智能体的配置。
|
2888
|
-
* @docs en:https://www.coze.com/docs/developer_guides/update_bot?_lang=en
|
2889
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/update_bot?_lang=zh
|
2890
|
-
* @param params - Required The parameters for updating a bot. | 修改 Bot 的参数。
|
2891
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 待修改配置的智能体ID。
|
2892
|
-
* @param params.name - Optional The name of the agent. | Bot 的名称。
|
2893
|
-
* @param params.description - Optional The description of the agent. | Bot 的描述信息。
|
2894
|
-
* @param params.icon_file_id - Optional The file ID for the agent's avatar. | 作为智能体头像的文件 ID。
|
2895
|
-
* @param params.prompt_info - Optional The personality and reply logic of the agent. | Bot 的提示词配置。
|
2896
|
-
* @param params.onboarding_info - Optional The settings related to the agent's opening remarks. | Bot 的开场白配置。
|
2897
|
-
* @param params.knowledge - Optional Knowledge configurations of the agent. | Bot 的知识库配置。
|
2898
|
-
* @returns Undefined | 无返回值
|
2899
|
-
*/ async update(params, options) {
|
2900
|
-
const apiUrl = '/v1/bot/update';
|
2901
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2902
|
-
return result.data;
|
2903
|
-
}
|
2904
|
-
/**
|
2905
|
-
* Get the agents published as API service. | 调用接口查看指定空间发布到 Agent as API 渠道的智能体列表。
|
2906
|
-
* @docs en:https://www.coze.com/docs/developer_guides/published_bots_list?_lang=en
|
2907
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/published_bots_list?_lang=zh
|
2908
|
-
* @param params - Required The parameters for listing bots. | 列出 Bot 的参数。
|
2909
|
-
* @param params.space_id - Required The ID of the space. | Bot 所在的空间的 Space ID。
|
2910
|
-
* @param params.page_size - Optional Pagination size. | 分页大小。
|
2911
|
-
* @param params.page_index - Optional Page number for paginated queries. | 分页查询时的页码。
|
2912
|
-
* @returns List of published bots. | 已发布的 Bot 列表。
|
2913
|
-
*/ async list(params, options) {
|
2914
|
-
const apiUrl = '/v1/space/published_bots_list';
|
2915
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2916
|
-
return result.data;
|
2917
|
-
}
|
2918
|
-
/**
|
2919
|
-
* Publish the specified agent as an API service. | 调用接口创建一个新的智能体。
|
2920
|
-
* @docs en:https://www.coze.com/docs/developer_guides/publish_bot?_lang=en
|
2921
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/publish_bot?_lang=zh
|
2922
|
-
* @param params - Required The parameters for publishing a bot. | 发布 Bot 的参数。
|
2923
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要发布的智能体ID。
|
2924
|
-
* @param params.connector_ids - Required The list of publishing channel IDs for the agent. | 智能体的发布渠道 ID 列表。
|
2925
|
-
* @returns Undefined | 无返回值
|
2926
|
-
*/ async publish(params, options) {
|
2927
|
-
const apiUrl = '/v1/bot/publish';
|
2928
|
-
const result = await this._client.post(apiUrl, params, false, options);
|
2929
|
-
return result.data;
|
2930
|
-
}
|
2931
|
-
/**
|
2932
|
-
* Get the configuration information of the agent. | 获取指定智能体的配置信息。
|
2933
|
-
* @docs en:https://www.coze.com/docs/developer_guides/get_metadata?_lang=en
|
2934
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/get_metadata?_lang=zh
|
2935
|
-
* @param params - Required The parameters for retrieving a bot. | 获取 Bot 的参数。
|
2936
|
-
* @param params.bot_id - Required The ID of the agent that the API interacts with. | 要查看的智能体ID。
|
2937
|
-
* @returns Information about the bot. | Bot 的配置信息。
|
2938
|
-
*/ async retrieve(params, options) {
|
2939
|
-
const apiUrl = '/v1/bot/get_online_info';
|
2940
|
-
const result = await this._client.get(apiUrl, params, false, options);
|
2941
|
-
return result.data;
|
2942
|
-
}
|
2943
|
-
}
|
2944
|
-
/* eslint-disable security/detect-object-injection */ /* eslint-disable @typescript-eslint/no-explicit-any */ function safeJsonParse(jsonString) {
|
2945
|
-
let defaultValue = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : '';
|
2946
|
-
try {
|
2947
|
-
return JSON.parse(jsonString);
|
2948
|
-
} catch (error) {
|
2949
|
-
return defaultValue;
|
2950
|
-
}
|
2951
|
-
}
|
2952
|
-
function sleep(ms) {
|
2953
|
-
return new Promise((resolve)=>{
|
2954
|
-
setTimeout(resolve, ms);
|
2955
|
-
});
|
2956
|
-
}
|
2957
|
-
function isBrowser() {
|
2958
|
-
return 'undefined' != typeof window;
|
2959
|
-
}
|
2960
|
-
function esm_isPlainObject(obj) {
|
2961
|
-
if ('object' != typeof obj || null === obj) return false;
|
2962
|
-
const proto = Object.getPrototypeOf(obj);
|
2963
|
-
if (null === proto) return true;
|
2964
|
-
let baseProto = proto;
|
2965
|
-
while(null !== Object.getPrototypeOf(baseProto))baseProto = Object.getPrototypeOf(baseProto);
|
2966
|
-
return proto === baseProto;
|
2967
|
-
}
|
2968
|
-
function esm_mergeConfig() {
|
2969
|
-
for(var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++)objects[_key] = arguments[_key];
|
2970
|
-
return objects.reduce((result, obj)=>{
|
2971
|
-
if (void 0 === obj) return result || {};
|
2972
|
-
for(const key in obj)if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
2973
|
-
if (esm_isPlainObject(obj[key]) && !Array.isArray(obj[key])) result[key] = esm_mergeConfig(result[key] || {}, obj[key]);
|
2974
|
-
else result[key] = obj[key];
|
2975
|
-
}
|
2976
|
-
return result;
|
2977
|
-
}, {});
|
2978
|
-
}
|
2979
|
-
function isPersonalAccessToken(token) {
|
2980
|
-
return null == token ? void 0 : token.startsWith('pat_');
|
2981
|
-
}
|
2982
|
-
/* eslint-disable max-params */ class CozeError extends Error {
|
2983
|
-
}
|
2984
|
-
class APIError extends CozeError {
|
2985
|
-
static makeMessage(status, errorBody, message, headers) {
|
2986
|
-
if (!errorBody && message) return message;
|
2987
|
-
if (errorBody) {
|
2988
|
-
const list = [];
|
2989
|
-
const { code, msg, error } = errorBody;
|
2990
|
-
if (code) list.push(`code: ${code}`);
|
2991
|
-
if (msg) list.push(`msg: ${msg}`);
|
2992
|
-
if ((null == error ? void 0 : error.detail) && msg !== error.detail) list.push(`detail: ${error.detail}`);
|
2993
|
-
const logId = (null == error ? void 0 : error.logid) || (null == headers ? void 0 : headers['x-tt-logid']);
|
2994
|
-
if (logId) list.push(`logid: ${logId}`);
|
2995
|
-
const help_doc = null == error ? void 0 : error.help_doc;
|
2996
|
-
if (help_doc) list.push(`help doc: ${help_doc}`);
|
2997
|
-
return list.join(', ');
|
2998
|
-
}
|
2999
|
-
if (status) return `http status code: ${status} (no body)`;
|
3000
|
-
return '(no status code or body)';
|
3001
|
-
}
|
3002
|
-
static generate(status, errorResponse, message, headers) {
|
3003
|
-
if (!status) return new APIConnectionError({
|
3004
|
-
cause: castToError(errorResponse)
|
3005
|
-
});
|
3006
|
-
const error = errorResponse;
|
3007
|
-
// https://www.coze.cn/docs/developer_guides/coze_error_codes
|
3008
|
-
if (400 === status || (null == error ? void 0 : error.code) === 4000) return new BadRequestError(status, error, message, headers);
|
3009
|
-
if (401 === status || (null == error ? void 0 : error.code) === 4100) return new AuthenticationError(status, error, message, headers);
|
3010
|
-
if (403 === status || (null == error ? void 0 : error.code) === 4101) return new PermissionDeniedError(status, error, message, headers);
|
3011
|
-
if (404 === status || (null == error ? void 0 : error.code) === 4200) return new NotFoundError(status, error, message, headers);
|
3012
|
-
if (429 === status || (null == error ? void 0 : error.code) === 4013) return new RateLimitError(status, error, message, headers);
|
3013
|
-
if (408 === status) return new TimeoutError(status, error, message, headers);
|
3014
|
-
if (502 === status) return new GatewayError(status, error, message, headers);
|
3015
|
-
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
3016
|
-
return new APIError(status, error, message, headers);
|
3017
|
-
}
|
3018
|
-
constructor(status, error, message, headers){
|
3019
|
-
var _error_error, _error_error1;
|
3020
|
-
super(`${APIError.makeMessage(status, error, message, headers)}`);
|
3021
|
-
this.status = status;
|
3022
|
-
this.headers = headers;
|
3023
|
-
this.logid = null == headers ? void 0 : headers['x-tt-logid'];
|
3024
|
-
// this.error = error;
|
3025
|
-
this.code = null == error ? void 0 : error.code;
|
3026
|
-
this.msg = null == error ? void 0 : error.msg;
|
3027
|
-
this.detail = null == error ? void 0 : null === (_error_error = error.error) || void 0 === _error_error ? void 0 : _error_error.detail;
|
3028
|
-
this.help_doc = null == error ? void 0 : null === (_error_error1 = error.error) || void 0 === _error_error1 ? void 0 : _error_error1.help_doc;
|
3029
|
-
this.rawError = error;
|
3030
|
-
}
|
3031
|
-
}
|
3032
|
-
class APIConnectionError extends APIError {
|
3033
|
-
constructor({ message, cause }){
|
3034
|
-
super(void 0, void 0, message || 'Connection error.', void 0), this.status = void 0;
|
3035
|
-
// if (cause) {
|
3036
|
-
// this.cause = cause;
|
3037
|
-
// }
|
3038
|
-
}
|
3039
|
-
}
|
3040
|
-
class APIUserAbortError extends APIError {
|
3041
|
-
constructor(message){
|
3042
|
-
super(void 0, void 0, message || 'Request was aborted.', void 0), this.name = 'UserAbortError', this.status = void 0;
|
3043
|
-
}
|
3044
|
-
}
|
3045
|
-
class BadRequestError extends APIError {
|
3046
|
-
constructor(...args){
|
3047
|
-
super(...args), this.name = 'BadRequestError', this.status = 400;
|
3048
|
-
}
|
3049
|
-
}
|
3050
|
-
class AuthenticationError extends APIError {
|
3051
|
-
constructor(...args){
|
3052
|
-
super(...args), this.name = 'AuthenticationError', this.status = 401;
|
3053
|
-
}
|
3054
|
-
}
|
3055
|
-
class PermissionDeniedError extends APIError {
|
3056
|
-
constructor(...args){
|
3057
|
-
super(...args), this.name = 'PermissionDeniedError', this.status = 403;
|
3058
|
-
}
|
3059
|
-
}
|
3060
|
-
class NotFoundError extends APIError {
|
3061
|
-
constructor(...args){
|
3062
|
-
super(...args), this.name = 'NotFoundError', this.status = 404;
|
3063
|
-
}
|
3064
|
-
}
|
3065
|
-
class TimeoutError extends APIError {
|
3066
|
-
constructor(...args){
|
3067
|
-
super(...args), this.name = 'TimeoutError', this.status = 408;
|
3068
|
-
}
|
3069
|
-
}
|
3070
|
-
class RateLimitError extends APIError {
|
3071
|
-
constructor(...args){
|
3072
|
-
super(...args), this.name = 'RateLimitError', this.status = 429;
|
3073
|
-
}
|
3074
|
-
}
|
3075
|
-
class InternalServerError extends APIError {
|
3076
|
-
constructor(...args){
|
3077
|
-
super(...args), this.name = 'InternalServerError', this.status = 500;
|
3078
|
-
}
|
3079
|
-
}
|
3080
|
-
class GatewayError extends APIError {
|
3081
|
-
constructor(...args){
|
3082
|
-
super(...args), this.name = 'GatewayError', this.status = 502;
|
3083
|
-
}
|
3084
|
-
}
|
3085
|
-
const castToError = (err)=>{
|
3086
|
-
if (err instanceof Error) return err;
|
3087
|
-
return new Error(err);
|
3088
|
-
};
|
3089
|
-
class Messages extends APIResource {
|
3090
|
-
/**
|
3091
|
-
* Get the list of messages in a chat. | 获取对话中的消息列表。
|
3092
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_message_list?_lang=en
|
3093
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_message_list?_lang=zh
|
3094
|
-
* @param conversation_id - Required The ID of the conversation. | 会话 ID。
|
3095
|
-
* @param chat_id - Required The ID of the chat. | 对话 ID。
|
3096
|
-
* @returns An array of chat messages. | 对话消息数组。
|
3097
|
-
*/ async list(conversation_id, chat_id, options) {
|
3098
|
-
const apiUrl = `/v3/chat/message/list?conversation_id=${conversation_id}&chat_id=${chat_id}`;
|
3099
|
-
const result = await this._client.get(apiUrl, void 0, false, options);
|
3100
|
-
return result.data;
|
3101
|
-
}
|
3102
|
-
}
|
3103
|
-
const uuid = ()=>(Math.random() * new Date().getTime()).toString();
|
3104
|
-
class Chat extends APIResource {
|
3105
|
-
/**
|
3106
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3107
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3108
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3109
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3110
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3111
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3112
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3113
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义变量。
|
3114
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3115
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3116
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3117
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3118
|
-
* @returns The data of the created chat. | 创建的对话数据。
|
3119
|
-
*/ async create(params, options) {
|
3120
|
-
if (!params.user_id) params.user_id = uuid();
|
3121
|
-
const { conversation_id, ...rest } = params;
|
3122
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3123
|
-
const payload = {
|
3124
|
-
...rest,
|
3125
|
-
stream: false
|
3126
|
-
};
|
3127
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3128
|
-
return result.data;
|
3129
|
-
}
|
3130
|
-
/**
|
3131
|
-
* Call the Chat API to send messages to a published Coze agent. | 调用此接口发起一次对话,支持添加上下文
|
3132
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3133
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3134
|
-
* @param params - Required The parameters for creating a chat session. | 创建会话的参数。
|
3135
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3136
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3137
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3138
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3139
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3140
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3141
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3142
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3143
|
-
* @returns
|
3144
|
-
*/ async createAndPoll(params, options) {
|
3145
|
-
if (!params.user_id) params.user_id = uuid();
|
3146
|
-
const { conversation_id, ...rest } = params;
|
3147
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3148
|
-
const payload = {
|
3149
|
-
...rest,
|
3150
|
-
stream: false
|
3151
|
-
};
|
3152
|
-
const result = await this._client.post(apiUrl, payload, false, options);
|
3153
|
-
const chatId = result.data.id;
|
3154
|
-
const conversationId = result.data.conversation_id;
|
3155
|
-
let chat;
|
3156
|
-
while(true){
|
3157
|
-
await sleep(100);
|
3158
|
-
chat = await this.retrieve(conversationId, chatId);
|
3159
|
-
if ('completed' === chat.status || 'failed' === chat.status || 'requires_action' === chat.status) break;
|
3160
|
-
}
|
3161
|
-
const messageList = await this.messages.list(conversationId, chatId);
|
3162
|
-
return {
|
3163
|
-
chat,
|
3164
|
-
messages: messageList
|
3165
|
-
};
|
3166
|
-
}
|
3167
|
-
/**
|
3168
|
-
* Call the Chat API to send messages to a published Coze agent with streaming response. | 调用此接口发起一次对话,支持流式响应。
|
3169
|
-
* @docs en:https://www.coze.com/docs/developer_guides/chat_v3?_lang=en
|
3170
|
-
* @docs zh:https://www.coze.cn/docs/developer_guides/chat_v3?_lang=zh
|
3171
|
-
* @param params - Required The parameters for streaming a chat session. | 流式会话的参数。
|
3172
|
-
* @param params.bot_id - Required The ID of the agent. | 要进行会话聊天的 Bot ID。
|
3173
|
-
* @param params.user_id - Optional The ID of the user interacting with the Bot. | 标识当前与 Bot 交互的用户。
|
3174
|
-
* @param params.additional_messages - Optional Additional messages for the conversation. | 对话的附加信息。
|
3175
|
-
* @param params.custom_variables - Optional Variables defined in the Bot. | Bot 中定义的变量。
|
3176
|
-
* @param params.auto_save_history - Optional Whether to automatically save the conversation history. | 是否自动保存历史对话记录。
|
3177
|
-
* @param params.meta_data - Optional Additional metadata for the message. | 创建消息时的附加消息。
|
3178
|
-
* @param params.conversation_id - Optional The ID of the conversation. | 标识对话发生在哪一次会话中。
|
3179
|
-
* @param params.extra_params - Optional Extra parameters for the conversation. | 附加参数。
|
3180
|
-
* @returns A stream of chat data. | 对话数据流。
|
3181
|
-
*/ async *stream(params, options) {
|
3182
|
-
if (!params.user_id) params.user_id = uuid();
|
3183
|
-
const { conversation_id, ...rest } = params;
|
3184
|
-
const apiUrl = `/v3/chat${conversation_id ? `?conversation_id=${conversation_id}` : ''}`;
|
3185
|
-
const payload = {
|
3186
|
-
...rest,
|
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;
|
3253
|
-
}
|
3254
|
-
{
|
3255
|
-
const result = await this._client.post(apiUrl, payload, true, options);
|
3256
|
-
for await (const message of result)if ("done" === message.event) {
|
3257
|
-
const ret = {
|
3258
|
-
event: message.event,
|
3259
|
-
data: '[DONE]'
|
3260
|
-
};
|
3261
|
-
yield ret;
|
3262
|
-
} else try {
|
3263
|
-
const ret = {
|
3264
|
-
event: message.event,
|
3265
|
-
data: JSON.parse(message.data)
|
3266
|
-
};
|
3267
|
-
yield ret;
|
3268
|
-
} catch (error) {
|
3269
|
-
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3270
|
-
}
|
3271
|
-
}
|
3272
|
-
}
|
3273
|
-
constructor(...args){
|
3274
|
-
super(...args), this.messages = new Messages(this._client);
|
3151
|
+
getUri(config) {
|
3152
|
+
config = mergeConfig_mergeConfig(this.defaults, config);
|
3153
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
3154
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
3275
3155
|
}
|
3276
3156
|
}
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
|
3284
|
-
|
3285
|
-
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3157
|
+
// Provide aliases for supported request methods
|
3158
|
+
utils.forEach([
|
3159
|
+
'delete',
|
3160
|
+
'get',
|
3161
|
+
'head',
|
3162
|
+
'options'
|
3163
|
+
], function(method) {
|
3164
|
+
/*eslint func-names:0*/ Axios_Axios.prototype[method] = function(url, config) {
|
3165
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3166
|
+
method,
|
3167
|
+
url,
|
3168
|
+
data: (config || {}).data
|
3169
|
+
}));
|
3170
|
+
};
|
3171
|
+
});
|
3172
|
+
utils.forEach([
|
3173
|
+
'post',
|
3174
|
+
'put',
|
3175
|
+
'patch'
|
3176
|
+
], function(method) {
|
3177
|
+
/*eslint func-names:0*/ function generateHTTPMethod(isForm) {
|
3178
|
+
return function(url, data, config) {
|
3179
|
+
return this.request(mergeConfig_mergeConfig(config || {}, {
|
3180
|
+
method,
|
3181
|
+
headers: isForm ? {
|
3182
|
+
'Content-Type': 'multipart/form-data'
|
3183
|
+
} : {},
|
3184
|
+
url,
|
3185
|
+
data
|
3186
|
+
}));
|
3187
|
+
};
|
3293
3188
|
}
|
3294
|
-
|
3295
|
-
|
3296
|
-
|
3297
|
-
|
3298
|
-
|
3299
|
-
|
3300
|
-
|
3301
|
-
|
3302
|
-
|
3303
|
-
|
3304
|
-
|
3305
|
-
|
3306
|
-
|
3307
|
-
|
3308
|
-
|
3309
|
-
|
3189
|
+
Axios_Axios.prototype[method] = generateHTTPMethod();
|
3190
|
+
Axios_Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
3191
|
+
});
|
3192
|
+
/* ESM default export */ const Axios = Axios_Axios;
|
3193
|
+
/**
|
3194
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
3195
|
+
*
|
3196
|
+
* @param {Function} executor The executor function.
|
3197
|
+
*
|
3198
|
+
* @returns {CancelToken}
|
3199
|
+
*/ class CancelToken_CancelToken {
|
3200
|
+
constructor(executor){
|
3201
|
+
if ('function' != typeof executor) throw new TypeError('executor must be a function.');
|
3202
|
+
let resolvePromise;
|
3203
|
+
this.promise = new Promise(function(resolve) {
|
3204
|
+
resolvePromise = resolve;
|
3205
|
+
});
|
3206
|
+
const token = this;
|
3207
|
+
// eslint-disable-next-line func-names
|
3208
|
+
this.promise.then((cancel)=>{
|
3209
|
+
if (!token._listeners) return;
|
3210
|
+
let i = token._listeners.length;
|
3211
|
+
while(i-- > 0)token._listeners[i](cancel);
|
3212
|
+
token._listeners = null;
|
3213
|
+
});
|
3214
|
+
// eslint-disable-next-line func-names
|
3215
|
+
this.promise.then = (onfulfilled)=>{
|
3216
|
+
let _resolve;
|
3217
|
+
// eslint-disable-next-line func-names
|
3218
|
+
const promise = new Promise((resolve)=>{
|
3219
|
+
token.subscribe(resolve);
|
3220
|
+
_resolve = resolve;
|
3221
|
+
}).then(onfulfilled);
|
3222
|
+
promise.cancel = function() {
|
3223
|
+
token.unsubscribe(_resolve);
|
3224
|
+
};
|
3225
|
+
return promise;
|
3226
|
+
};
|
3227
|
+
executor(function(message, config, request) {
|
3228
|
+
if (token.reason) // Cancellation has already been requested
|
3229
|
+
return;
|
3230
|
+
token.reason = new CanceledError(message, config, request);
|
3231
|
+
resolvePromise(token.reason);
|
3232
|
+
});
|
3310
3233
|
}
|
3311
3234
|
/**
|
3312
|
-
*
|
3313
|
-
|
3314
|
-
|
3315
|
-
* @param conversation_id - Required The ID of the conversation. | Conversation ID,即会话的唯一标识。
|
3316
|
-
* @param message_id - Required The ID of the message. | Message ID,即消息的唯一标识。
|
3317
|
-
* @returns Information about the message. | 消息详情。
|
3318
|
-
*/ async retrieve(conversation_id, message_id, options) {
|
3319
|
-
const apiUrl = `/v1/conversation/message/retrieve?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3320
|
-
const response = await this._client.get(apiUrl, null, false, options);
|
3321
|
-
return response.data;
|
3235
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
3236
|
+
*/ throwIfRequested() {
|
3237
|
+
if (this.reason) throw this.reason;
|
3322
3238
|
}
|
3323
3239
|
/**
|
3324
|
-
*
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
|
3330
|
-
|
3331
|
-
|
3332
|
-
|
3333
|
-
|
3334
|
-
* @returns A list of messages. | 消息列表。
|
3335
|
-
*/ async list(conversation_id, params, options) {
|
3336
|
-
const apiUrl = `/v1/conversation/message/list?conversation_id=${conversation_id}`;
|
3337
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3338
|
-
return response;
|
3240
|
+
* Subscribe to the cancel signal
|
3241
|
+
*/ subscribe(listener) {
|
3242
|
+
if (this.reason) {
|
3243
|
+
listener(this.reason);
|
3244
|
+
return;
|
3245
|
+
}
|
3246
|
+
if (this._listeners) this._listeners.push(listener);
|
3247
|
+
else this._listeners = [
|
3248
|
+
listener
|
3249
|
+
];
|
3339
3250
|
}
|
3340
3251
|
/**
|
3341
|
-
*
|
3342
|
-
|
3343
|
-
|
3344
|
-
|
3345
|
-
|
3346
|
-
* @returns Details of the deleted message. | 已删除的消息详情。
|
3347
|
-
*/ async delete(conversation_id, message_id, options) {
|
3348
|
-
const apiUrl = `/v1/conversation/message/delete?conversation_id=${conversation_id}&message_id=${message_id}`;
|
3349
|
-
const response = await this._client.post(apiUrl, void 0, false, options);
|
3350
|
-
return response.data;
|
3252
|
+
* Unsubscribe from the cancel signal
|
3253
|
+
*/ unsubscribe(listener) {
|
3254
|
+
if (!this._listeners) return;
|
3255
|
+
const index = this._listeners.indexOf(listener);
|
3256
|
+
if (-1 !== index) this._listeners.splice(index, 1);
|
3351
3257
|
}
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
* @param params.meta_data - Optional Additional information when creating a message. | 创建消息时的附加消息。
|
3361
|
-
* @returns Information about the created conversation. | 会话的基础信息。
|
3362
|
-
*/ async create(params, options) {
|
3363
|
-
const apiUrl = '/v1/conversation/create';
|
3364
|
-
const response = await this._client.post(apiUrl, params, false, options);
|
3365
|
-
return response.data;
|
3258
|
+
toAbortSignal() {
|
3259
|
+
const controller = new AbortController();
|
3260
|
+
const abort = (err)=>{
|
3261
|
+
controller.abort(err);
|
3262
|
+
};
|
3263
|
+
this.subscribe(abort);
|
3264
|
+
controller.signal.unsubscribe = ()=>this.unsubscribe(abort);
|
3265
|
+
return controller.signal;
|
3366
3266
|
}
|
3367
3267
|
/**
|
3368
|
-
*
|
3369
|
-
*
|
3370
|
-
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3374
|
-
|
3375
|
-
|
3376
|
-
|
3377
|
-
|
3378
|
-
|
3379
|
-
super(...args), this.messages = new messages_Messages(this._client);
|
3268
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
3269
|
+
* cancels the `CancelToken`.
|
3270
|
+
*/ static source() {
|
3271
|
+
let cancel;
|
3272
|
+
const token = new CancelToken_CancelToken(function(c) {
|
3273
|
+
cancel = c;
|
3274
|
+
});
|
3275
|
+
return {
|
3276
|
+
token,
|
3277
|
+
cancel
|
3278
|
+
};
|
3380
3279
|
}
|
3381
3280
|
}
|
3281
|
+
/* ESM default export */ const CancelToken = CancelToken_CancelToken;
|
3282
|
+
/**
|
3283
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
3284
|
+
*
|
3285
|
+
* Common use case would be to use `Function.prototype.apply`.
|
3286
|
+
*
|
3287
|
+
* ```js
|
3288
|
+
* function f(x, y, z) {}
|
3289
|
+
* var args = [1, 2, 3];
|
3290
|
+
* f.apply(null, args);
|
3291
|
+
* ```
|
3292
|
+
*
|
3293
|
+
* With `spread` this example can be re-written.
|
3294
|
+
*
|
3295
|
+
* ```js
|
3296
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
3297
|
+
* ```
|
3298
|
+
*
|
3299
|
+
* @param {Function} callback
|
3300
|
+
*
|
3301
|
+
* @returns {Function}
|
3302
|
+
*/ function spread(callback) {
|
3303
|
+
return function(arr) {
|
3304
|
+
return callback.apply(null, arr);
|
3305
|
+
};
|
3306
|
+
}
|
3307
|
+
/**
|
3308
|
+
* Determines whether the payload is an error thrown by Axios
|
3309
|
+
*
|
3310
|
+
* @param {*} payload The value to test
|
3311
|
+
*
|
3312
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
3313
|
+
*/ function isAxiosError(payload) {
|
3314
|
+
return utils.isObject(payload) && true === payload.isAxiosError;
|
3315
|
+
}
|
3316
|
+
const HttpStatusCode = {
|
3317
|
+
Continue: 100,
|
3318
|
+
SwitchingProtocols: 101,
|
3319
|
+
Processing: 102,
|
3320
|
+
EarlyHints: 103,
|
3321
|
+
Ok: 200,
|
3322
|
+
Created: 201,
|
3323
|
+
Accepted: 202,
|
3324
|
+
NonAuthoritativeInformation: 203,
|
3325
|
+
NoContent: 204,
|
3326
|
+
ResetContent: 205,
|
3327
|
+
PartialContent: 206,
|
3328
|
+
MultiStatus: 207,
|
3329
|
+
AlreadyReported: 208,
|
3330
|
+
ImUsed: 226,
|
3331
|
+
MultipleChoices: 300,
|
3332
|
+
MovedPermanently: 301,
|
3333
|
+
Found: 302,
|
3334
|
+
SeeOther: 303,
|
3335
|
+
NotModified: 304,
|
3336
|
+
UseProxy: 305,
|
3337
|
+
Unused: 306,
|
3338
|
+
TemporaryRedirect: 307,
|
3339
|
+
PermanentRedirect: 308,
|
3340
|
+
BadRequest: 400,
|
3341
|
+
Unauthorized: 401,
|
3342
|
+
PaymentRequired: 402,
|
3343
|
+
Forbidden: 403,
|
3344
|
+
NotFound: 404,
|
3345
|
+
MethodNotAllowed: 405,
|
3346
|
+
NotAcceptable: 406,
|
3347
|
+
ProxyAuthenticationRequired: 407,
|
3348
|
+
RequestTimeout: 408,
|
3349
|
+
Conflict: 409,
|
3350
|
+
Gone: 410,
|
3351
|
+
LengthRequired: 411,
|
3352
|
+
PreconditionFailed: 412,
|
3353
|
+
PayloadTooLarge: 413,
|
3354
|
+
UriTooLong: 414,
|
3355
|
+
UnsupportedMediaType: 415,
|
3356
|
+
RangeNotSatisfiable: 416,
|
3357
|
+
ExpectationFailed: 417,
|
3358
|
+
ImATeapot: 418,
|
3359
|
+
MisdirectedRequest: 421,
|
3360
|
+
UnprocessableEntity: 422,
|
3361
|
+
Locked: 423,
|
3362
|
+
FailedDependency: 424,
|
3363
|
+
TooEarly: 425,
|
3364
|
+
UpgradeRequired: 426,
|
3365
|
+
PreconditionRequired: 428,
|
3366
|
+
TooManyRequests: 429,
|
3367
|
+
RequestHeaderFieldsTooLarge: 431,
|
3368
|
+
UnavailableForLegalReasons: 451,
|
3369
|
+
InternalServerError: 500,
|
3370
|
+
NotImplemented: 501,
|
3371
|
+
BadGateway: 502,
|
3372
|
+
ServiceUnavailable: 503,
|
3373
|
+
GatewayTimeout: 504,
|
3374
|
+
HttpVersionNotSupported: 505,
|
3375
|
+
VariantAlsoNegotiates: 506,
|
3376
|
+
InsufficientStorage: 507,
|
3377
|
+
LoopDetected: 508,
|
3378
|
+
NotExtended: 510,
|
3379
|
+
NetworkAuthenticationRequired: 511
|
3380
|
+
};
|
3381
|
+
Object.entries(HttpStatusCode).forEach(([key, value])=>{
|
3382
|
+
HttpStatusCode[value] = key;
|
3383
|
+
});
|
3384
|
+
/* ESM default export */ const helpers_HttpStatusCode = HttpStatusCode;
|
3385
|
+
/**
|
3386
|
+
* Create an instance of Axios
|
3387
|
+
*
|
3388
|
+
* @param {Object} defaultConfig The default config for the instance
|
3389
|
+
*
|
3390
|
+
* @returns {Axios} A new instance of Axios
|
3391
|
+
*/ function createInstance(defaultConfig) {
|
3392
|
+
const context = new Axios(defaultConfig);
|
3393
|
+
const instance = bind(Axios.prototype.request, context);
|
3394
|
+
// Copy axios.prototype to instance
|
3395
|
+
utils.extend(instance, Axios.prototype, context, {
|
3396
|
+
allOwnKeys: true
|
3397
|
+
});
|
3398
|
+
// Copy context to instance
|
3399
|
+
utils.extend(instance, context, null, {
|
3400
|
+
allOwnKeys: true
|
3401
|
+
});
|
3402
|
+
// Factory for creating new instances
|
3403
|
+
instance.create = function(instanceConfig) {
|
3404
|
+
return createInstance(mergeConfig_mergeConfig(defaultConfig, instanceConfig));
|
3405
|
+
};
|
3406
|
+
return instance;
|
3407
|
+
}
|
3408
|
+
// Create the default instance to be exported
|
3409
|
+
const axios = createInstance(defaults);
|
3410
|
+
// Expose Axios class to allow class inheritance
|
3411
|
+
axios.Axios = Axios;
|
3412
|
+
// Expose Cancel & CancelToken
|
3413
|
+
axios.CanceledError = CanceledError;
|
3414
|
+
axios.CancelToken = CancelToken;
|
3415
|
+
axios.isCancel = isCancel;
|
3416
|
+
axios.VERSION = VERSION;
|
3417
|
+
axios.toFormData = toFormData;
|
3418
|
+
// Expose AxiosError class
|
3419
|
+
axios.AxiosError = core_AxiosError;
|
3420
|
+
// alias for CanceledError for backward compatibility
|
3421
|
+
axios.Cancel = axios.CanceledError;
|
3422
|
+
// Expose all/spread
|
3423
|
+
axios.all = function(promises) {
|
3424
|
+
return Promise.all(promises);
|
3425
|
+
};
|
3426
|
+
axios.spread = spread;
|
3427
|
+
// Expose isAxiosError
|
3428
|
+
axios.isAxiosError = isAxiosError;
|
3429
|
+
// Expose mergeConfig
|
3430
|
+
axios.mergeConfig = mergeConfig_mergeConfig;
|
3431
|
+
axios.AxiosHeaders = AxiosHeaders;
|
3432
|
+
axios.formToJSON = (thing)=>formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
3433
|
+
axios.getAdapter = adapters_adapters.getAdapter;
|
3434
|
+
axios.HttpStatusCode = helpers_HttpStatusCode;
|
3435
|
+
axios.default = axios;
|
3436
|
+
// this module should only have a default export
|
3437
|
+
/* ESM default export */ const lib_axios = axios;
|
3438
|
+
// This module is intended to unwrap Axios default export as named.
|
3439
|
+
// Keep top-level export same with static properties
|
3440
|
+
// so that it can keep same with es module or cjs
|
3441
|
+
const { Axios: axios_Axios, AxiosError: axios_AxiosError, CanceledError: axios_CanceledError, isCancel: axios_isCancel, CancelToken: axios_CancelToken, VERSION: axios_VERSION, all: axios_all, Cancel, isAxiosError: axios_isAxiosError, spread: axios_spread, toFormData: axios_toFormData, AxiosHeaders: axios_AxiosHeaders, HttpStatusCode: axios_HttpStatusCode, formToJSON, getAdapter, mergeConfig: axios_mergeConfig } = lib_axios;
|
3382
3442
|
class Files extends APIResource {
|
3383
3443
|
/**
|
3384
3444
|
* Upload files to Coze platform. | 调用接口上传文件到扣子。
|
@@ -3413,6 +3473,9 @@
|
|
3413
3473
|
* @param params.bot_id - Optional The ID of the bot associated with the workflow. | 可选 与工作流关联的机器人 ID。
|
3414
3474
|
* @param params.parameters - Optional Parameters for the workflow execution. | 可选 工作流执行的参数。
|
3415
3475
|
* @param params.ext - Optional Additional information for the workflow execution. | 可选 工作流执行的附加信息。
|
3476
|
+
* @param params.execute_mode - Optional The mode in which to execute the workflow. | 可选 工作流执行的模式。
|
3477
|
+
* @param params.connector_id - Optional The ID of the connector to use for the workflow. | 可选 用于工作流的连接器 ID。
|
3478
|
+
* @param params.app_id - Optional The ID of the app. | 可选 要进行会话聊天的 App ID
|
3416
3479
|
* @returns RunWorkflowData | 工作流运行数据
|
3417
3480
|
*/ async create(params, options) {
|
3418
3481
|
const apiUrl = '/v1/workflow/run';
|
@@ -3427,6 +3490,9 @@
|
|
3427
3490
|
* @param params.bot_id - Optional The ID of the bot associated with the workflow. | 可选 与工作流关联的机器人 ID。
|
3428
3491
|
* @param params.parameters - Optional Parameters for the workflow execution. | 可选 工作流执行的参数。
|
3429
3492
|
* @param params.ext - Optional Additional information for the workflow execution. | 可选 工作流执行的附加信息。
|
3493
|
+
* @param params.execute_mode - Optional The mode in which to execute the workflow. | 可选 工作流执行的模式。
|
3494
|
+
* @param params.connector_id - Optional The ID of the connector to use for the workflow. | 可选 用于工作流的连接器 ID。
|
3495
|
+
* @param params.app_id - Optional The ID of the app. | 可选 要进行会话聊天的 App ID
|
3430
3496
|
* @returns Stream<WorkflowEvent, { id: string; event: string; data: string }> | 工作流事件流
|
3431
3497
|
*/ async *stream(params, options) {
|
3432
3498
|
const apiUrl = '/v1/workflow/stream_run';
|
@@ -3460,9 +3526,46 @@
|
|
3460
3526
|
this.data = data;
|
3461
3527
|
}
|
3462
3528
|
}
|
3529
|
+
class WorkflowChat extends APIResource {
|
3530
|
+
/**
|
3531
|
+
* Execute a chat workflow. | 执行对话流
|
3532
|
+
* @docs en: https://www.coze.cn/docs/developer_guides/workflow_chat?_lang=en
|
3533
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/workflow_chat?_lang=zh
|
3534
|
+
* @param params.workflow_id - Required The ID of the workflow to chat with. | 必选 要对话的工作流 ID。
|
3535
|
+
* @param params.additional_messages - Required Array of messages for the chat. | 必选 对话的消息数组。
|
3536
|
+
* @param params.parameters - Required Parameters for the workflow execution. | 必选 工作流执行的参数。
|
3537
|
+
* @param params.app_id - Optional The ID of the app. | 可选 应用 ID。
|
3538
|
+
* @param params.bot_id - Optional The ID of the bot. | 可选 Bot ID。
|
3539
|
+
* @param params.conversation_id - Optional The ID of the conversation. | 可选 会话 ID。
|
3540
|
+
* @param params.ext - Optional Additional information for the chat. | 可选 对话的附加信息。
|
3541
|
+
* @returns AsyncGenerator<StreamChatData> | 对话数据流
|
3542
|
+
*/ async *stream(params, options) {
|
3543
|
+
const apiUrl = '/v1/workflows/chat';
|
3544
|
+
const payload = {
|
3545
|
+
...params,
|
3546
|
+
additional_messages: handleAdditionalMessages(params.additional_messages)
|
3547
|
+
};
|
3548
|
+
const result = await this._client.post(apiUrl, payload, true, options);
|
3549
|
+
for await (const message of result)if (message.event === chat_ChatEventType.DONE) {
|
3550
|
+
const ret = {
|
3551
|
+
event: message.event,
|
3552
|
+
data: '[DONE]'
|
3553
|
+
};
|
3554
|
+
yield ret;
|
3555
|
+
} else try {
|
3556
|
+
const ret = {
|
3557
|
+
event: message.event,
|
3558
|
+
data: JSON.parse(message.data)
|
3559
|
+
};
|
3560
|
+
yield ret;
|
3561
|
+
} catch (error) {
|
3562
|
+
throw new CozeError(`Could not parse message into JSON:${message.data}`);
|
3563
|
+
}
|
3564
|
+
}
|
3565
|
+
}
|
3463
3566
|
class Workflows extends APIResource {
|
3464
3567
|
constructor(...args){
|
3465
|
-
super(...args), this.runs = new Runs(this._client);
|
3568
|
+
super(...args), this.runs = new Runs(this._client), this.chat = new WorkflowChat(this._client);
|
3466
3569
|
}
|
3467
3570
|
}
|
3468
3571
|
class WorkSpaces extends APIResource {
|
@@ -3486,6 +3589,8 @@
|
|
3486
3589
|
};
|
3487
3590
|
class Documents extends APIResource {
|
3488
3591
|
/**
|
3592
|
+
* @deprecated The method is deprecated and will be removed in a future version. Please use 'client.datasets.documents.list' instead.
|
3593
|
+
*
|
3489
3594
|
* View the file list of a specified knowledge base, which includes lists of documents, spreadsheets, or images.
|
3490
3595
|
* | 调用接口查看指定知识库的内容列表,即文件、表格或图像列表。
|
3491
3596
|
* @docs en: https://www.coze.com/docs/developer_guides/list_knowledge_files?_lang=en
|
@@ -3496,12 +3601,14 @@
|
|
3496
3601
|
* @returns ListDocumentData | 知识库文件列表
|
3497
3602
|
*/ list(params, options) {
|
3498
3603
|
const apiUrl = '/open_api/knowledge/document/list';
|
3499
|
-
const response = this._client.get(apiUrl, params, false,
|
3604
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3500
3605
|
headers: documents_headers
|
3501
3606
|
}));
|
3502
3607
|
return response;
|
3503
3608
|
}
|
3504
3609
|
/**
|
3610
|
+
* @deprecated The method is deprecated and will be removed in a future version. Please use 'client.datasets.documents.create' instead.
|
3611
|
+
*
|
3505
3612
|
* Upload files to the specific knowledge. | 调用此接口向指定知识库中上传文件。
|
3506
3613
|
* @docs en: https://www.coze.com/docs/developer_guides/create_knowledge_files?_lang=en
|
3507
3614
|
* @docs zh: https://www.coze.cn/docs/developer_guides/create_knowledge_files?_lang=zh
|
@@ -3512,12 +3619,14 @@
|
|
3512
3619
|
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3513
3620
|
*/ async create(params, options) {
|
3514
3621
|
const apiUrl = '/open_api/knowledge/document/create';
|
3515
|
-
const response = await this._client.post(apiUrl, params, false,
|
3622
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3516
3623
|
headers: documents_headers
|
3517
3624
|
}));
|
3518
3625
|
return response.document_infos;
|
3519
3626
|
}
|
3520
3627
|
/**
|
3628
|
+
* @deprecated The method is deprecated and will be removed in a future version. Please use 'client.datasets.documents.delete' instead.
|
3629
|
+
*
|
3521
3630
|
* Delete text, images, sheets, and other files in the knowledge base, supporting batch deletion.
|
3522
3631
|
* | 删除知识库中的文本、图像、表格等文件,支持批量删除。
|
3523
3632
|
* @docs en: https://www.coze.com/docs/developer_guides/delete_knowledge_files?_lang=en
|
@@ -3526,11 +3635,13 @@
|
|
3526
3635
|
* @returns void | 无返回
|
3527
3636
|
*/ async delete(params, options) {
|
3528
3637
|
const apiUrl = '/open_api/knowledge/document/delete';
|
3529
|
-
await this._client.post(apiUrl, params, false,
|
3638
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3530
3639
|
headers: documents_headers
|
3531
3640
|
}));
|
3532
3641
|
}
|
3533
3642
|
/**
|
3643
|
+
* @deprecated The method is deprecated and will be removed in a future version. Please use 'client.datasets.documents.update' instead.
|
3644
|
+
*
|
3534
3645
|
* Modify the knowledge base file name and update strategy. | 调用接口修改知识库文件名称和更新策略。
|
3535
3646
|
* @docs en: https://www.coze.com/docs/developer_guides/modify_knowledge_files?_lang=en
|
3536
3647
|
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_knowledge_files?_lang=zh
|
@@ -3540,14 +3651,86 @@
|
|
3540
3651
|
* @returns void | 无返回
|
3541
3652
|
*/ async update(params, options) {
|
3542
3653
|
const apiUrl = '/open_api/knowledge/document/update';
|
3543
|
-
await this._client.post(apiUrl, params, false,
|
3654
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3544
3655
|
headers: documents_headers
|
3545
3656
|
}));
|
3546
3657
|
}
|
3547
3658
|
}
|
3548
3659
|
class Knowledge extends APIResource {
|
3549
3660
|
constructor(...args){
|
3550
|
-
super(...args),
|
3661
|
+
super(...args), /**
|
3662
|
+
* @deprecated
|
3663
|
+
*/ this.documents = new Documents(this._client);
|
3664
|
+
}
|
3665
|
+
}
|
3666
|
+
// Required header for knowledge APIs
|
3667
|
+
const documents_documents_headers = {
|
3668
|
+
'agw-js-conv': 'str'
|
3669
|
+
};
|
3670
|
+
class documents_Documents extends APIResource {
|
3671
|
+
/**
|
3672
|
+
* View the file list of a specified knowledge base, which includes lists of documents, spreadsheets, or images.
|
3673
|
+
* | 调用接口查看指定知识库的内容列表,即文件、表格或图像列表。
|
3674
|
+
* @docs en: https://www.coze.com/docs/developer_guides/list_knowledge_files?_lang=en
|
3675
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/list_knowledge_files?_lang=zh
|
3676
|
+
* @param params.dataset_id - Required The ID of the knowledge base. | 必选 待查看文件的知识库 ID。
|
3677
|
+
* @param params.page - Optional The page number for paginated queries. Default is 1. | 可选 分页查询时的页码。默认为 1。
|
3678
|
+
* @param params.page_size - Optional The size of pagination. Default is 10. | 可选 分页大小。默认为 10。
|
3679
|
+
* @returns ListDocumentData | 知识库文件列表
|
3680
|
+
*/ list(params, options) {
|
3681
|
+
const apiUrl = '/open_api/knowledge/document/list';
|
3682
|
+
const response = this._client.get(apiUrl, params, false, mergeConfig(options, {
|
3683
|
+
headers: documents_documents_headers
|
3684
|
+
}));
|
3685
|
+
return response;
|
3686
|
+
}
|
3687
|
+
/**
|
3688
|
+
* Upload files to the specific knowledge. | 调用此接口向指定知识库中上传文件。
|
3689
|
+
* @docs en: https://www.coze.com/docs/developer_guides/create_knowledge_files?_lang=en
|
3690
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/create_knowledge_files?_lang=zh
|
3691
|
+
* @param params.dataset_id - Required The ID of the knowledge. | 必选 知识库 ID。
|
3692
|
+
* @param params.document_bases - Required The metadata information of the files awaiting upload. | 必选 待上传文件的元数据信息。
|
3693
|
+
* @param params.chunk_strategy - Required when uploading files to a new knowledge for the first time. Chunk strategy.
|
3694
|
+
* | 向新知识库首次上传文件时必选 分段规则。
|
3695
|
+
* @returns DocumentInfo[] | 已上传文件的基本信息
|
3696
|
+
*/ async create(params, options) {
|
3697
|
+
const apiUrl = '/open_api/knowledge/document/create';
|
3698
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3699
|
+
headers: documents_documents_headers
|
3700
|
+
}));
|
3701
|
+
return response.document_infos;
|
3702
|
+
}
|
3703
|
+
/**
|
3704
|
+
* Delete text, images, sheets, and other files in the knowledge base, supporting batch deletion.
|
3705
|
+
* | 删除知识库中的文本、图像、表格等文件,支持批量删除。
|
3706
|
+
* @docs en: https://www.coze.com/docs/developer_guides/delete_knowledge_files?_lang=en
|
3707
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/delete_knowledge_files?_lang=zh
|
3708
|
+
* @param params.document_ids - Required The list of knowledge base files to be deleted. | 必选 待删除的文件 ID。
|
3709
|
+
* @returns void | 无返回
|
3710
|
+
*/ async delete(params, options) {
|
3711
|
+
const apiUrl = '/open_api/knowledge/document/delete';
|
3712
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3713
|
+
headers: documents_documents_headers
|
3714
|
+
}));
|
3715
|
+
}
|
3716
|
+
/**
|
3717
|
+
* Modify the knowledge base file name and update strategy. | 调用接口修改知识库文件名称和更新策略。
|
3718
|
+
* @docs en: https://www.coze.com/docs/developer_guides/modify_knowledge_files?_lang=en
|
3719
|
+
* @docs zh: https://www.coze.cn/docs/developer_guides/modify_knowledge_files?_lang=zh
|
3720
|
+
* @param params.document_id - Required The ID of the knowledge base file. | 必选 待修改的知识库文件 ID。
|
3721
|
+
* @param params.document_name - Optional The new name of the knowledge base file. | 可选 知识库文件的新名称。
|
3722
|
+
* @param params.update_rule - Optional The update strategy for online web pages. | 可选 在线网页更新策略。
|
3723
|
+
* @returns void | 无返回
|
3724
|
+
*/ async update(params, options) {
|
3725
|
+
const apiUrl = '/open_api/knowledge/document/update';
|
3726
|
+
await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3727
|
+
headers: documents_documents_headers
|
3728
|
+
}));
|
3729
|
+
}
|
3730
|
+
}
|
3731
|
+
class Datasets extends APIResource {
|
3732
|
+
constructor(...args){
|
3733
|
+
super(...args), this.documents = new documents_Documents(this._client);
|
3551
3734
|
}
|
3552
3735
|
}
|
3553
3736
|
class Voices extends APIResource {
|
@@ -3604,7 +3787,7 @@
|
|
3604
3787
|
* @returns Speech synthesis data
|
3605
3788
|
*/ async create(params, options) {
|
3606
3789
|
const apiUrl = '/v1/audio/speech';
|
3607
|
-
const response = await this._client.post(apiUrl, params, false,
|
3790
|
+
const response = await this._client.post(apiUrl, params, false, mergeConfig(options, {
|
3608
3791
|
responseType: 'arraybuffer'
|
3609
3792
|
}));
|
3610
3793
|
return response;
|
@@ -3617,42 +3800,102 @@
|
|
3617
3800
|
return response.data;
|
3618
3801
|
}
|
3619
3802
|
}
|
3620
|
-
class
|
3803
|
+
class audio_Audio extends APIResource {
|
3621
3804
|
constructor(...args){
|
3622
3805
|
super(...args), this.rooms = new Rooms(this._client), this.voices = new Voices(this._client), this.speech = new Speech(this._client);
|
3623
3806
|
}
|
3624
3807
|
}
|
3625
|
-
|
3808
|
+
// EXTERNAL MODULE: os (ignored)
|
3809
|
+
var os_ignored_ = __webpack_require__("?9050");
|
3810
|
+
var os_ignored_default = /*#__PURE__*/ __webpack_require__.n(os_ignored_);
|
3811
|
+
var package_namespaceObject = JSON.parse('{"name":"@coze/api","version":"1.0.10-alpha.576f79","description":"Official Coze Node.js SDK for seamless AI integration into your applications | 扣子官方 Node.js SDK,助您轻松集成 AI 能力到应用中","keywords":["coze","ai","nodejs","sdk","chatbot","typescript"],"homepage":"https://github.com/coze-dev/coze-js/tree/main/packages/coze-js","bugs":{"url":"https://github.com/coze-dev/coze-js/issues"},"repository":{"type":"git","url":"https://github.com/coze-dev/coze-js.git","directory":"packages/coze-js"},"license":"MIT","author":"Leeight <leeight@gmail.com>","type":"module","main":"src/index.ts","browser":{"crypto":false,"os":false,"jsonwebtoken":false},"types":"src/index.ts","files":["dist","LICENSE","README.md"],"scripts":{"build":"rm -rf dist && rslib build","format":"prettier --write .","lint":"eslint ./ --cache --quiet","start":"rm -rf dist && rslib build -w","test":"vitest","test:cov":"vitest --coverage --run"},"dependencies":{"jsonwebtoken":"^9.0.2"},"devDependencies":{"@coze-infra/eslint-config":"workspace:*","@coze-infra/ts-config":"workspace:*","@coze-infra/vitest-config":"workspace:*","@rslib/core":"0.0.18","@swc/core":"^1.3.14","@types/jsonwebtoken":"^9.0.0","@types/node":"^20","@types/uuid":"^9.0.1","@types/whatwg-fetch":"^0.0.33","@vitest/coverage-v8":"~2.1.4","axios":"^1.7.7","typescript":"^5.5.3","vitest":"~2.1.4"},"peerDependencies":{"axios":"^1.7.1"},"cozePublishConfig":{"exports":{".":{"require":"./dist/cjs/index.cjs","import":"./dist/esm/index.js","types":"./dist/types/index.d.ts"}},"main":"dist/cjs/index.cjs","module":"dist/esm/index.js","types":"dist/types/index.d.ts"}}'); // CONCATENATED MODULE: ../coze-js/src/version.ts
|
3812
|
+
const { version: version_version } = package_namespaceObject;
|
3813
|
+
const getEnv = ()=>{
|
3814
|
+
const nodeVersion = process.version.slice(1); // Remove 'v' prefix
|
3815
|
+
const { platform } = process;
|
3816
|
+
let osName = platform.toLowerCase();
|
3817
|
+
let osVersion = os_ignored_default().release();
|
3818
|
+
if ('darwin' === platform) {
|
3819
|
+
osName = 'macos';
|
3820
|
+
// Try to parse the macOS version
|
3821
|
+
try {
|
3822
|
+
const darwinVersion = os_ignored_default().release().split('.');
|
3823
|
+
if (darwinVersion.length >= 2) {
|
3824
|
+
const majorVersion = parseInt(darwinVersion[0], 10);
|
3825
|
+
if (!isNaN(majorVersion) && majorVersion >= 9) {
|
3826
|
+
const macVersion = majorVersion - 9;
|
3827
|
+
osVersion = `10.${macVersion}.${darwinVersion[1]}`;
|
3828
|
+
}
|
3829
|
+
}
|
3830
|
+
} catch (error) {
|
3831
|
+
// Keep the default os.release() value if parsing fails
|
3832
|
+
}
|
3833
|
+
} else if ('win32' === platform) {
|
3834
|
+
osName = 'windows';
|
3835
|
+
osVersion = os_ignored_default().release();
|
3836
|
+
} else if ('linux' === platform) {
|
3837
|
+
osName = 'linux';
|
3838
|
+
osVersion = os_ignored_default().release();
|
3839
|
+
}
|
3840
|
+
return {
|
3841
|
+
osName,
|
3842
|
+
osVersion,
|
3843
|
+
nodeVersion
|
3844
|
+
};
|
3845
|
+
};
|
3846
|
+
const getUserAgent = ()=>{
|
3847
|
+
const { nodeVersion, osName, osVersion } = getEnv();
|
3848
|
+
return `coze-js/${version_version} node/${nodeVersion} ${osName}/${osVersion}`.toLowerCase();
|
3849
|
+
};
|
3850
|
+
const getNodeClientUserAgent = ()=>{
|
3851
|
+
const { osVersion, nodeVersion, osName } = getEnv();
|
3852
|
+
const ua = {
|
3853
|
+
version: version_version,
|
3854
|
+
lang: 'node',
|
3855
|
+
lang_version: nodeVersion,
|
3856
|
+
os_name: osName,
|
3857
|
+
os_version: osVersion
|
3858
|
+
};
|
3859
|
+
return JSON.stringify(ua);
|
3860
|
+
};
|
3861
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ const fetcher_handleError = (error)=>{
|
3626
3862
|
if (!error.isAxiosError && (!error.code || !error.message)) return new CozeError(`Unexpected error: ${error.message}`);
|
3627
3863
|
if ('ECONNABORTED' === error.code && error.message.includes('timeout') || 'ETIMEDOUT' === error.code) {
|
3628
3864
|
var _error_response;
|
3629
3865
|
return new TimeoutError(408, void 0, `Request timed out: ${error.message}`, null === (_error_response = error.response) || void 0 === _error_response ? void 0 : _error_response.headers);
|
3630
3866
|
}
|
3631
3867
|
if ('ERR_CANCELED' === error.code) return new APIUserAbortError(error.message);
|
3632
|
-
|
3633
|
-
|
3868
|
+
else {
|
3869
|
+
var _error_response1, _error_response2, _error_response3;
|
3870
|
+
return error_APIError.generate((null === (_error_response1 = error.response) || void 0 === _error_response1 ? void 0 : _error_response1.status) || 500, null === (_error_response2 = error.response) || void 0 === _error_response2 ? void 0 : _error_response2.data, error.message, null === (_error_response3 = error.response) || void 0 === _error_response3 ? void 0 : _error_response3.headers);
|
3871
|
+
}
|
3634
3872
|
};
|
3635
3873
|
async function fetchAPI(url) {
|
3636
3874
|
let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
|
3637
3875
|
const axiosInstance = options.axiosInstance || lib_axios;
|
3876
|
+
// Add version check for streaming requests
|
3877
|
+
if (options.isStreaming && isAxiosStatic(axiosInstance)) {
|
3878
|
+
const axiosVersion = axiosInstance.VERSION || lib_axios.VERSION;
|
3879
|
+
if (!axiosVersion || compareVersions(axiosVersion, '1.7.1') < 0) throw new CozeError('Streaming requests require axios version 1.7.1 or higher. Please upgrade your axios version.');
|
3880
|
+
}
|
3638
3881
|
const response = await axiosInstance({
|
3639
3882
|
url,
|
3640
3883
|
responseType: options.isStreaming ? 'stream' : 'json',
|
3641
3884
|
adapter: options.isStreaming ? 'fetch' : void 0,
|
3642
3885
|
...options
|
3643
3886
|
}).catch((error)=>{
|
3644
|
-
throw
|
3887
|
+
throw fetcher_handleError(error);
|
3645
3888
|
});
|
3646
3889
|
return {
|
3647
3890
|
async *stream () {
|
3648
3891
|
try {
|
3649
3892
|
const stream = response.data;
|
3650
|
-
const reader = stream[Symbol.asyncIterator]();
|
3893
|
+
const reader = stream[Symbol.asyncIterator] ? stream[Symbol.asyncIterator]() : stream.getReader();
|
3651
3894
|
const decoder = new TextDecoder();
|
3652
3895
|
const fieldValues = {};
|
3653
3896
|
let buffer = '';
|
3654
3897
|
while(true){
|
3655
|
-
const { done, value } = await reader.next();
|
3898
|
+
const { done, value } = await (reader.next ? reader.next() : reader.read());
|
3656
3899
|
if (done) {
|
3657
3900
|
if (buffer) {
|
3658
3901
|
// If the stream ends without a newline, it means an error occurred
|
@@ -3679,26 +3922,46 @@
|
|
3679
3922
|
buffer = lines[lines.length - 1]; // Keep the last incomplete line in the buffer
|
3680
3923
|
}
|
3681
3924
|
} catch (error) {
|
3682
|
-
|
3925
|
+
fetcher_handleError(error);
|
3683
3926
|
}
|
3684
3927
|
},
|
3685
3928
|
json: ()=>response.data,
|
3686
3929
|
response
|
3687
3930
|
};
|
3688
3931
|
}
|
3932
|
+
// Add version comparison utility
|
3933
|
+
function compareVersions(v1, v2) {
|
3934
|
+
const v1Parts = v1.split('.').map(Number);
|
3935
|
+
const v2Parts = v2.split('.').map(Number);
|
3936
|
+
for(let i = 0; i < 3; i++){
|
3937
|
+
const part1 = v1Parts[i] || 0;
|
3938
|
+
const part2 = v2Parts[i] || 0;
|
3939
|
+
if (part1 > part2) return 1;
|
3940
|
+
if (part1 < part2) return -1;
|
3941
|
+
}
|
3942
|
+
return 0;
|
3943
|
+
}
|
3944
|
+
function isAxiosStatic(instance) {
|
3945
|
+
return !!(null == instance ? void 0 : instance.Axios);
|
3946
|
+
}
|
3689
3947
|
/**
|
3690
3948
|
* default coze base URL is api.coze.com
|
3691
|
-
*/ const
|
3692
|
-
/* eslint-disable max-params */ class
|
3693
|
-
|
3949
|
+
*/ const constant_COZE_COM_BASE_URL = 'https://api.coze.com';
|
3950
|
+
/* eslint-disable max-params */ class core_APIClient {
|
3951
|
+
async getToken() {
|
3952
|
+
if ('function' == typeof this.token) return await this.token();
|
3953
|
+
return this.token;
|
3954
|
+
}
|
3955
|
+
async buildOptions(method, body, options) {
|
3956
|
+
const token = await this.getToken();
|
3694
3957
|
const headers = {
|
3695
|
-
authorization: `Bearer ${
|
3958
|
+
authorization: `Bearer ${token}`
|
3696
3959
|
};
|
3697
|
-
|
3698
|
-
|
3699
|
-
|
3700
|
-
|
3701
|
-
const config =
|
3960
|
+
if (!utils_isBrowser()) {
|
3961
|
+
headers['User-Agent'] = getUserAgent();
|
3962
|
+
headers['X-Coze-Client-User-Agent'] = getNodeClientUserAgent();
|
3963
|
+
}
|
3964
|
+
const config = mergeConfig(this.axiosOptions, options, {
|
3702
3965
|
headers
|
3703
3966
|
});
|
3704
3967
|
config.method = method;
|
@@ -3707,19 +3970,22 @@
|
|
3707
3970
|
}
|
3708
3971
|
async makeRequest(apiUrl, method, body, isStream, options) {
|
3709
3972
|
const fullUrl = `${this.baseURL}${apiUrl}`;
|
3710
|
-
const fetchOptions = this.buildOptions(method, body, options);
|
3973
|
+
const fetchOptions = await this.buildOptions(method, body, options);
|
3711
3974
|
fetchOptions.isStreaming = isStream;
|
3975
|
+
fetchOptions.axiosInstance = this.axiosInstance;
|
3712
3976
|
this.debugLog(`--- request url: ${fullUrl}`);
|
3713
3977
|
this.debugLog('--- request options:', fetchOptions);
|
3714
3978
|
const { response, stream, json } = await fetchAPI(fullUrl, fetchOptions);
|
3715
3979
|
this.debugLog(`--- response status: ${response.status}`);
|
3716
3980
|
this.debugLog('--- response headers: ', response.headers);
|
3717
|
-
|
3981
|
+
var _response_headers;
|
3982
|
+
// Taro use `header`
|
3983
|
+
const contentType = (null !== (_response_headers = response.headers) && void 0 !== _response_headers ? _response_headers : response.header)['content-type'];
|
3718
3984
|
if (isStream) {
|
3719
3985
|
if (contentType && contentType.includes('application/json')) {
|
3720
3986
|
const result = await json();
|
3721
3987
|
const { code, msg } = result;
|
3722
|
-
if (0 !== code && void 0 !== code) throw
|
3988
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3723
3989
|
}
|
3724
3990
|
return stream();
|
3725
3991
|
}
|
@@ -3727,7 +3993,7 @@
|
|
3727
3993
|
{
|
3728
3994
|
const result = await json();
|
3729
3995
|
const { code, msg } = result;
|
3730
|
-
if (0 !== code && void 0 !== code) throw
|
3996
|
+
if (0 !== code && void 0 !== code) throw error_APIError.generate(response.status, result, msg, response.headers);
|
3731
3997
|
return result;
|
3732
3998
|
}
|
3733
3999
|
}
|
@@ -3759,30 +4025,35 @@
|
|
3759
4025
|
}
|
3760
4026
|
constructor(config){
|
3761
4027
|
this._config = config;
|
3762
|
-
this.baseURL = config.baseURL ||
|
4028
|
+
this.baseURL = config.baseURL || constant_COZE_COM_BASE_URL;
|
3763
4029
|
this.token = config.token;
|
3764
4030
|
this.axiosOptions = config.axiosOptions || {};
|
4031
|
+
this.axiosInstance = config.axiosInstance;
|
3765
4032
|
this.debug = config.debug || false;
|
3766
4033
|
this.allowPersonalAccessTokenInBrowser = config.allowPersonalAccessTokenInBrowser || false;
|
3767
4034
|
this.headers = config.headers;
|
3768
|
-
if (
|
3769
|
-
}
|
3770
|
-
}
|
3771
|
-
|
3772
|
-
|
3773
|
-
|
3774
|
-
|
3775
|
-
|
3776
|
-
|
3777
|
-
|
3778
|
-
|
3779
|
-
|
3780
|
-
|
4035
|
+
if (utils_isBrowser() && 'function' != typeof this.token && isPersonalAccessToken(this.token) && !this.allowPersonalAccessTokenInBrowser) throw new CozeError('Browser environments do not support authentication using Personal Access Token (PAT) by default.\nas it may expose secret API keys. \n\nPlease use OAuth2.0 authentication mechanism. see:\nhttps://www.coze.com/docs/developer_guides/oauth_apps?_lang=en \n\nIf you need to force use, please set the `allowPersonalAccessTokenInBrowser` option to `true`. \n\ne.g new CozeAPI({ token, allowPersonalAccessTokenInBrowser: true });\n\n');
|
4036
|
+
}
|
4037
|
+
}
|
4038
|
+
core_APIClient.APIError = error_APIError;
|
4039
|
+
core_APIClient.BadRequestError = BadRequestError;
|
4040
|
+
core_APIClient.AuthenticationError = AuthenticationError;
|
4041
|
+
core_APIClient.PermissionDeniedError = PermissionDeniedError;
|
4042
|
+
core_APIClient.NotFoundError = NotFoundError;
|
4043
|
+
core_APIClient.RateLimitError = RateLimitError;
|
4044
|
+
core_APIClient.InternalServerError = InternalServerError;
|
4045
|
+
core_APIClient.GatewayError = GatewayError;
|
4046
|
+
core_APIClient.TimeoutError = TimeoutError;
|
4047
|
+
core_APIClient.UserAbortError = APIUserAbortError;
|
3781
4048
|
// EXTERNAL MODULE: crypto (ignored)
|
3782
|
-
|
3783
|
-
|
4049
|
+
__webpack_require__("?666e");
|
4050
|
+
// EXTERNAL MODULE: jsonwebtoken (ignored)
|
4051
|
+
__webpack_require__("?79fd");
|
4052
|
+
class CozeAPI extends core_APIClient {
|
3784
4053
|
constructor(...args){
|
3785
|
-
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this),
|
4054
|
+
super(...args), this.bots = new Bots(this), this.chat = new Chat(this), this.conversations = new Conversations(this), this.files = new Files(this), /**
|
4055
|
+
* @deprecated
|
4056
|
+
*/ this.knowledge = new Knowledge(this), this.datasets = new Datasets(this), this.workflows = new Workflows(this), this.workspaces = new WorkSpaces(this), this.audio = new audio_Audio(this);
|
3786
4057
|
}
|
3787
4058
|
}
|
3788
4059
|
/**
|
@@ -9014,7 +9285,7 @@
|
|
9014
9285
|
}, stringPad = {
|
9015
9286
|
start: createMethod(!1),
|
9016
9287
|
end: createMethod(!0)
|
9017
|
-
},
|
9288
|
+
}, index_esm_min_userAgent = engineUserAgent, stringPadWebkitBug = /Version\/10(?:\.\d+){1,2}(?: [\w./]+)?(?: Mobile\/\w+)? Safari\//.test(index_esm_min_userAgent), $$F = _export, $padEnd = stringPad.end, WEBKIT_BUG$1 = stringPadWebkitBug;
|
9018
9289
|
$$F({
|
9019
9290
|
target: "String",
|
9020
9291
|
proto: !0,
|
@@ -12587,8 +12858,8 @@
|
|
12587
12858
|
}
|
12588
12859
|
var _navigator$userAgent$, isFirefox = "mozilla" === getBrowser(), isSafari = "safari" === getBrowser(), isChrome = "chrome-stable" === getBrowser(), isCriOS = !isSSR2() && /CriOS/i.test(userAgentString), isEdgeForDesktop = !isSSR2() && /Edg\//i.test(userAgentString), isEdgeForAndroid = !isSSR2() && /EdgA/i.test(userAgentString), isEdgeForIOS = !isSSR2() && /EdgiOS/i.test(userAgentString), isEdge = isEdgeForDesktop || isEdgeForAndroid || isEdgeForIOS, isDingTalk = !isSSR2() && /DingTalk/i.test(navigator.userAgent), isOpera = !isSSR2() && /OPR\//.test(navigator.userAgent), isIPad = !isSSR2() && (!!/(iPad)/i.exec(userAgentString) || /Macintosh/i.test(userAgentString) && "ontouchend" in document), isMac = !isSSR2() && /Macintosh/i.test(userAgentString), isWeChat = !isSSR2() && /MicroMessenger/i.test(userAgentString), isMobile = !isSSR2() && _includesInstanceProperty(_context$3 = userAgentString.toLowerCase()).call(_context$3, "mobile"), isIOS = !isSSR2() && !!/(iPhone|iPad|iPod)/i.exec(userAgentString), isAndroid = !isSSR2() && /Android/i.test(userAgentString), isWindows = !isSSR2() && /Windows/i.test(userAgentString), isOpenHarmony = !isSSR2() && /OpenHarmony/i.test(userAgentString), sv = 0, sv2 = "0", index_esm_min_v = !isSSR2() && (null === (_userAgentString$matc = userAgentString.match(/version\/(\d+)/i)) || void 0 === _userAgentString$matc ? void 0 : _userAgentString$matc[1]);
|
12589
12860
|
isSafari && index_esm_min_v && (sv = Number(index_esm_min_v), sv2 = null === (_navigator$userAgent$ = navigator.userAgent.match(/version\/(\d+\.\d+)/i)) || void 0 === _navigator$userAgent$ ? void 0 : _navigator$userAgent$[1]);
|
12590
|
-
var
|
12591
|
-
isFirefox &&
|
12861
|
+
var index_esm_min_v2 = !isSSR2() && (null === (_userAgentString$matc2 = userAgentString.match(/Firefox\/(\d+)/i)) || void 0 === _userAgentString$matc2 ? void 0 : _userAgentString$matc2[1]);
|
12862
|
+
isFirefox && index_esm_min_v2 && (sv = Number(index_esm_min_v2));
|
12592
12863
|
var safariVersion = sv, firefoxVersion = sv, safariMinorVersion = sv2, iOSVersion = null !== (_ref = !isSSR2() && (null === (_userAgentString$matc3 = userAgentString.match(/ ([\d_]+) like Mac OS X/i)) || void 0 === _userAgentString$matc3 || null === (_userAgentString$matc4 = _userAgentString$matc3[1]) || void 0 === _userAgentString$matc4 ? void 0 : _mapInstanceProperty(_context2 = _userAgentString$matc4.split("_")).call(_context2, function(e) {
|
12593
12864
|
return _parseInt$7(e);
|
12594
12865
|
}))) && void 0 !== _ref ? _ref : [], cv = 0, cvs = !isSSR2() && (null === (_userAgentString$matc5 = userAgentString.match(/Chrome\/(\d+)/i)) || void 0 === _userAgentString$matc5 ? void 0 : _userAgentString$matc5[1]);
|
@@ -38167,28 +38438,52 @@
|
|
38167
38438
|
+ * @param milliseconds The time to sleep in milliseconds
|
38168
38439
|
+ * @throws {Error} If milliseconds is negative
|
38169
38440
|
+ * @returns Promise that resolves after the specified duration
|
38170
|
-
+ */ const
|
38441
|
+
+ */ const src_utils_sleep = (milliseconds)=>{
|
38171
38442
|
if (milliseconds < 0) throw new Error('Sleep duration must be non-negative');
|
38172
38443
|
return new Promise((resolve)=>setTimeout(resolve, milliseconds));
|
38173
38444
|
};
|
38174
38445
|
/**
|
38446
|
+
* @deprecated use checkDevicePermission instead
|
38175
38447
|
* Check microphone permission,return boolean
|
38176
|
-
*/ const checkPermission = async ()
|
38448
|
+
*/ const checkPermission = async function() {
|
38449
|
+
let { audio = true, video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
38450
|
+
try {
|
38451
|
+
const result = await index_esm_min_index.enableDevices({
|
38452
|
+
audio,
|
38453
|
+
video
|
38454
|
+
});
|
38455
|
+
return result.audio;
|
38456
|
+
} catch (error) {
|
38457
|
+
console.error('Failed to check device permissions:', error);
|
38458
|
+
return false;
|
38459
|
+
}
|
38460
|
+
};
|
38461
|
+
const checkDevicePermission = async function() {
|
38462
|
+
let checkVideo = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
|
38463
|
+
return await index_esm_min_index.enableDevices({
|
38177
38464
|
audio: true,
|
38178
|
-
video:
|
38179
|
-
})
|
38465
|
+
video: checkVideo
|
38466
|
+
});
|
38467
|
+
};
|
38180
38468
|
/**
|
38181
38469
|
* Get audio devices
|
38182
38470
|
* @returns Promise<AudioDevices> Object containing arrays of audio input and output devices
|
38183
|
-
*/ const getAudioDevices = async ()
|
38184
|
-
|
38471
|
+
*/ const getAudioDevices = async function() {
|
38472
|
+
let { video = false } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
38473
|
+
let devices = [];
|
38474
|
+
devices = video ? await index_esm_min_index.enumerateDevices() : await [
|
38475
|
+
...await index_esm_min_index.enumerateAudioCaptureDevices(),
|
38476
|
+
...await index_esm_min_index.enumerateAudioPlaybackDevices()
|
38477
|
+
];
|
38185
38478
|
if (!(null == devices ? void 0 : devices.length)) return {
|
38186
38479
|
audioInputs: [],
|
38187
|
-
audioOutputs: []
|
38480
|
+
audioOutputs: [],
|
38481
|
+
videoInputs: []
|
38188
38482
|
};
|
38189
38483
|
return {
|
38190
38484
|
audioInputs: devices.filter((i)=>i.deviceId && 'audioinput' === i.kind),
|
38191
|
-
audioOutputs: devices.filter((i)=>i.deviceId && 'audiooutput' === i.kind)
|
38485
|
+
audioOutputs: devices.filter((i)=>i.deviceId && 'audiooutput' === i.kind),
|
38486
|
+
videoInputs: devices.filter((i)=>i.deviceId && 'videoinput' === i.kind)
|
38192
38487
|
};
|
38193
38488
|
};
|
38194
38489
|
var error_RealtimeError = /*#__PURE__*/ function(RealtimeError) {
|
@@ -38202,12 +38497,20 @@
|
|
38202
38497
|
RealtimeError["NETWORK_ERROR"] = "NETWORK_ERROR";
|
38203
38498
|
RealtimeError["INVALID_STATE"] = "INVALID_STATE";
|
38204
38499
|
RealtimeError["CREATE_ROOM_ERROR"] = "CREATE_ROOM_ERROR";
|
38500
|
+
RealtimeError["PARSE_MESSAGE_ERROR"] = "PARSE_MESSAGE_ERROR";
|
38501
|
+
RealtimeError["HANDLER_MESSAGE_ERROR"] = "HANDLER_MESSAGE_ERROR";
|
38205
38502
|
return RealtimeError;
|
38206
38503
|
}({});
|
38207
38504
|
class RealtimeAPIError extends Error {
|
38208
|
-
|
38209
|
-
|
38505
|
+
/**
|
38506
|
+
* @param code - Error code
|
38507
|
+
* @param message - Error message
|
38508
|
+
* @param error - Error object
|
38509
|
+
*/ constructor(code, message, error){
|
38510
|
+
super(`[${code}] ${message}`);
|
38210
38511
|
this.name = 'RealtimeAPIError';
|
38512
|
+
this.code = code;
|
38513
|
+
this.error = error;
|
38211
38514
|
}
|
38212
38515
|
}
|
38213
38516
|
var event_handler_EventNames = /*#__PURE__*/ function(EventNames) {
|
@@ -38244,6 +38547,18 @@
|
|
38244
38547
|
* zh: 客户端音频静音
|
38245
38548
|
*/ EventNames["AUDIO_MUTED"] = "client.audio.muted";
|
38246
38549
|
/**
|
38550
|
+
* en: Client video on
|
38551
|
+
* zh: 客户端视频开启
|
38552
|
+
*/ EventNames["VIDEO_ON"] = "client.video.on";
|
38553
|
+
/**
|
38554
|
+
* en: Client video off
|
38555
|
+
* zh: 客户端视频关闭
|
38556
|
+
*/ EventNames["VIDEO_OFF"] = "client.video.off";
|
38557
|
+
/**
|
38558
|
+
* en: Client video event
|
38559
|
+
* zh: 客户端视频事件
|
38560
|
+
*/ EventNames["PLAYER_EVENT"] = "client.video.event";
|
38561
|
+
/**
|
38247
38562
|
* en: Client error
|
38248
38563
|
* zh: 客户端错误
|
38249
38564
|
*/ EventNames["ERROR"] = "client.error";
|
@@ -38263,6 +38578,42 @@
|
|
38263
38578
|
* en: Audio output device changed
|
38264
38579
|
* zh: 音频输出设备改变
|
38265
38580
|
*/ EventNames["AUDIO_OUTPUT_DEVICE_CHANGED"] = "client.output.device.changed";
|
38581
|
+
/**
|
38582
|
+
* en: Bot joined
|
38583
|
+
* zh: Bot 加入
|
38584
|
+
*/ EventNames["BOT_JOIN"] = "server.bot.join";
|
38585
|
+
/**
|
38586
|
+
* en: Bot left
|
38587
|
+
* zh: Bot 离开
|
38588
|
+
*/ EventNames["BOT_LEAVE"] = "server.bot.leave";
|
38589
|
+
/**
|
38590
|
+
* en: Audio speech started
|
38591
|
+
* zh: 开始说话
|
38592
|
+
*/ EventNames["AUDIO_AGENT_SPEECH_STARTED"] = "server.audio.agent.speech_started";
|
38593
|
+
/**
|
38594
|
+
* en: Audio speech stopped
|
38595
|
+
* zh: 停止说话
|
38596
|
+
*/ EventNames["AUDIO_SPEECH_STOPPED"] = "server.audio.speech_stopped";
|
38597
|
+
/**
|
38598
|
+
* en: Server error
|
38599
|
+
* zh: 服务端错误
|
38600
|
+
*/ EventNames["SERVER_ERROR"] = "server.error";
|
38601
|
+
/**
|
38602
|
+
* en: User speech started
|
38603
|
+
* zh: 用户开始说话
|
38604
|
+
*/ EventNames["AUDIO_USER_SPEECH_STARTED"] = "server.audio.user.speech_started";
|
38605
|
+
/**
|
38606
|
+
* en: User speech stopped
|
38607
|
+
* zh: 用户停止说话
|
38608
|
+
*/ EventNames["AUDIO_USER_SPEECH_STOPPED"] = "server.audio.user.speech_stopped";
|
38609
|
+
/**
|
38610
|
+
* en: User successfully enters the room
|
38611
|
+
* zh: 用户成功进入房间后,会收到该事件
|
38612
|
+
*/ EventNames["SESSION_CREATED"] = "server.session.created";
|
38613
|
+
/**
|
38614
|
+
* en: Session updated
|
38615
|
+
* zh: 会话更新
|
38616
|
+
*/ EventNames["SESSION_UPDATE"] = "server.session.update";
|
38266
38617
|
return EventNames;
|
38267
38618
|
}({});
|
38268
38619
|
class RealtimeEventHandler {
|
@@ -38286,10 +38637,15 @@
|
|
38286
38637
|
}
|
38287
38638
|
// eslint-disable-next-line max-params
|
38288
38639
|
_dispatchToHandlers(eventName, event, handlers, prefix) {
|
38289
|
-
for (const handler of handlers)if (!prefix || eventName.startsWith(prefix))
|
38640
|
+
for (const handler of handlers)if (!prefix || eventName.startsWith(prefix)) try {
|
38641
|
+
handler(eventName, event);
|
38642
|
+
} catch (e) {
|
38643
|
+
throw new RealtimeAPIError(error_RealtimeError.HANDLER_MESSAGE_ERROR, `Failed to handle message: ${eventName}`);
|
38644
|
+
}
|
38290
38645
|
}
|
38291
38646
|
dispatch(eventName, event) {
|
38292
|
-
|
38647
|
+
let consoleLog = !(arguments.length > 2) || void 0 === arguments[2] || arguments[2];
|
38648
|
+
if (consoleLog) this._log(`dispatch ${eventName} event`);
|
38293
38649
|
const handlers = (this.eventHandlers[eventName] || []).slice();
|
38294
38650
|
this._dispatchToHandlers(eventName, event, handlers);
|
38295
38651
|
const allHandlers = (this.eventHandlers["realtime.event"] || []).slice();
|
@@ -41558,6 +41914,7 @@
|
|
41558
41914
|
this.engine.on(index_esm_min_index.events.onUserJoined, this.handleUserJoin);
|
41559
41915
|
this.engine.on(index_esm_min_index.events.onUserLeave, this.handleUserLeave);
|
41560
41916
|
this.engine.on(index_esm_min_index.events.onError, this.handleEventError);
|
41917
|
+
if (this._isSupportVideo) this.engine.on(index_esm_min_index.events.onPlayerEvent, this.handlePlayerEvent);
|
41561
41918
|
if (this._debug) {
|
41562
41919
|
this.engine.on(index_esm_min_index.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
41563
41920
|
this.engine.on(index_esm_min_index.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
@@ -41568,45 +41925,62 @@
|
|
41568
41925
|
this.engine.off(index_esm_min_index.events.onUserJoined, this.handleUserJoin);
|
41569
41926
|
this.engine.off(index_esm_min_index.events.onUserLeave, this.handleUserLeave);
|
41570
41927
|
this.engine.off(index_esm_min_index.events.onError, this.handleEventError);
|
41928
|
+
if (this._isSupportVideo) this.engine.off(index_esm_min_index.events.onPlayerEvent, this.handlePlayerEvent);
|
41571
41929
|
if (this._debug) {
|
41572
41930
|
this.engine.off(index_esm_min_index.events.onLocalAudioPropertiesReport, this.handleLocalAudioPropertiesReport);
|
41573
41931
|
this.engine.off(index_esm_min_index.events.onRemoteAudioPropertiesReport, this.handleRemoteAudioPropertiesReport);
|
41574
41932
|
}
|
41575
41933
|
}
|
41934
|
+
_parseMessage(event) {
|
41935
|
+
try {
|
41936
|
+
return JSON.parse(event.message);
|
41937
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
41938
|
+
} catch (e) {
|
41939
|
+
throw new RealtimeAPIError(error_RealtimeError.PARSE_MESSAGE_ERROR, (null == e ? void 0 : e.message) || 'Unknown error');
|
41940
|
+
}
|
41941
|
+
}
|
41576
41942
|
handleMessage(event) {
|
41577
41943
|
try {
|
41578
|
-
const message =
|
41944
|
+
const message = this._parseMessage(event);
|
41579
41945
|
this.dispatch(`server.${message.event_type}`, message);
|
41580
41946
|
} catch (e) {
|
41581
|
-
|
41582
|
-
|
41583
|
-
|
41584
|
-
|
41947
|
+
if (e instanceof RealtimeAPIError) {
|
41948
|
+
if (e.code === error_RealtimeError.PARSE_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
|
41949
|
+
message: `Failed to parse message: ${event.message}`,
|
41950
|
+
error: e
|
41951
|
+
});
|
41952
|
+
else if (e.code === error_RealtimeError.HANDLER_MESSAGE_ERROR) this.dispatch(event_handler_EventNames.ERROR, {
|
41953
|
+
message: `Failed to handle message: ${event.message}`,
|
41954
|
+
error: e
|
41955
|
+
});
|
41956
|
+
} else this.dispatch(event_handler_EventNames.ERROR, e);
|
41585
41957
|
}
|
41586
41958
|
}
|
41587
41959
|
handleEventError(e) {
|
41588
|
-
this.dispatch(
|
41960
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41589
41961
|
}
|
41590
41962
|
handleUserJoin(event) {
|
41591
41963
|
this.joinUserId = event.userInfo.userId;
|
41592
|
-
this.dispatch(
|
41964
|
+
this.dispatch(event_handler_EventNames.BOT_JOIN, event);
|
41593
41965
|
}
|
41594
41966
|
handleUserLeave(event) {
|
41595
|
-
this.dispatch(
|
41967
|
+
this.dispatch(event_handler_EventNames.BOT_LEAVE, event);
|
41968
|
+
}
|
41969
|
+
handlePlayerEvent(event) {
|
41970
|
+
this.dispatch(event_handler_EventNames.PLAYER_EVENT, event);
|
41596
41971
|
}
|
41597
41972
|
async joinRoom(options) {
|
41598
|
-
const { token, roomId, uid, audioMutedDefault
|
41973
|
+
const { token, roomId, uid, audioMutedDefault, videoOnDefault, isAutoSubscribeAudio } = options;
|
41599
41974
|
try {
|
41600
41975
|
await this.engine.joinRoom(token, roomId, {
|
41601
41976
|
userId: uid
|
41602
41977
|
}, {
|
41603
41978
|
isAutoPublish: !audioMutedDefault,
|
41604
|
-
isAutoSubscribeAudio
|
41605
|
-
isAutoSubscribeVideo:
|
41979
|
+
isAutoSubscribeAudio,
|
41980
|
+
isAutoSubscribeVideo: this._isSupportVideo && videoOnDefault
|
41606
41981
|
});
|
41607
41982
|
} catch (e) {
|
41608
41983
|
if (e instanceof Error) throw new RealtimeAPIError(error_RealtimeError.CONNECTION_ERROR, e.message);
|
41609
|
-
throw new RealtimeAPIError(error_RealtimeError.CONNECTION_ERROR, 'Unknown error');
|
41610
41984
|
}
|
41611
41985
|
}
|
41612
41986
|
async setAudioInputDevice(deviceId) {
|
@@ -41616,23 +41990,34 @@
|
|
41616
41990
|
await this.engine.startAudioCapture(deviceId);
|
41617
41991
|
}
|
41618
41992
|
async setAudioOutputDevice(deviceId) {
|
41619
|
-
const devices = await getAudioDevices(
|
41993
|
+
const devices = await getAudioDevices({
|
41994
|
+
video: false
|
41995
|
+
});
|
41620
41996
|
if (-1 === devices.audioOutputs.findIndex((i)=>i.deviceId === deviceId)) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, `Audio output device not found: ${deviceId}`);
|
41621
41997
|
await this.engine.setAudioPlaybackDevice(deviceId);
|
41622
41998
|
}
|
41623
|
-
async createLocalStream() {
|
41624
|
-
const devices = await getAudioDevices(
|
41625
|
-
|
41999
|
+
async createLocalStream(userId, videoConfig) {
|
42000
|
+
const devices = await getAudioDevices({
|
42001
|
+
video: this._isSupportVideo
|
42002
|
+
});
|
42003
|
+
if (!devices.audioInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get audio devices');
|
42004
|
+
if (this._isSupportVideo && !devices.videoInputs.length) throw new RealtimeAPIError(error_RealtimeError.DEVICE_ACCESS_ERROR, 'Failed to get video devices');
|
41626
42005
|
await this.engine.startAudioCapture(devices.audioInputs[0].deviceId);
|
42006
|
+
if (this._isSupportVideo && (null == videoConfig ? void 0 : videoConfig.videoOnDefault)) await this.engine.startVideoCapture(devices.videoInputs[0].deviceId);
|
42007
|
+
if (this._isSupportVideo) this.engine.setLocalVideoPlayer(StreamIndex$1.STREAM_INDEX_MAIN, {
|
42008
|
+
renderDom: (null == videoConfig ? void 0 : videoConfig.renderDom) || 'local-player',
|
42009
|
+
userId
|
42010
|
+
});
|
41627
42011
|
}
|
41628
42012
|
async disconnect() {
|
41629
42013
|
try {
|
42014
|
+
if (this._isSupportVideo) await this.engine.stopVideoCapture();
|
41630
42015
|
await this.engine.stopAudioCapture();
|
41631
42016
|
await this.engine.unpublishStream(MediaType$1.AUDIO);
|
41632
42017
|
await this.engine.leaveRoom();
|
41633
42018
|
this.removeEventListener();
|
41634
42019
|
} catch (e) {
|
41635
|
-
this.dispatch(
|
42020
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41636
42021
|
throw e;
|
41637
42022
|
}
|
41638
42023
|
}
|
@@ -41641,7 +42026,16 @@
|
|
41641
42026
|
if (isMicOn) await this.engine.publishStream(MediaType$1.AUDIO);
|
41642
42027
|
else await this.engine.unpublishStream(MediaType$1.AUDIO);
|
41643
42028
|
} catch (e) {
|
41644
|
-
this.dispatch(
|
42029
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
42030
|
+
throw e;
|
42031
|
+
}
|
42032
|
+
}
|
42033
|
+
async changeVideoState(isVideoOn) {
|
42034
|
+
try {
|
42035
|
+
if (isVideoOn) await this.engine.startVideoCapture();
|
42036
|
+
else await this.engine.stopVideoCapture();
|
42037
|
+
} catch (e) {
|
42038
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41645
42039
|
throw e;
|
41646
42040
|
}
|
41647
42041
|
}
|
@@ -41654,7 +42048,7 @@
|
|
41654
42048
|
}));
|
41655
42049
|
this._log(`interrupt ${this.joinUserId} ${result}`);
|
41656
42050
|
} catch (e) {
|
41657
|
-
this.dispatch(
|
42051
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41658
42052
|
throw e;
|
41659
42053
|
}
|
41660
42054
|
}
|
@@ -41663,7 +42057,7 @@
|
|
41663
42057
|
const result = await this.engine.sendUserMessage(this.joinUserId, JSON.stringify(message));
|
41664
42058
|
this._log(`sendMessage ${this.joinUserId} ${JSON.stringify(message)} ${result}`);
|
41665
42059
|
} catch (e) {
|
41666
|
-
this.dispatch(
|
42060
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41667
42061
|
throw e;
|
41668
42062
|
}
|
41669
42063
|
}
|
@@ -41704,7 +42098,7 @@
|
|
41704
42098
|
try {
|
41705
42099
|
await this.engine.startAudioPlaybackDeviceTest('audio-test.wav', 200);
|
41706
42100
|
} catch (e) {
|
41707
|
-
this.dispatch(
|
42101
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41708
42102
|
throw e;
|
41709
42103
|
}
|
41710
42104
|
}
|
@@ -41712,12 +42106,13 @@
|
|
41712
42106
|
try {
|
41713
42107
|
this.engine.stopAudioPlaybackDeviceTest();
|
41714
42108
|
} catch (e) {
|
41715
|
-
this.dispatch(
|
42109
|
+
this.dispatch(event_handler_EventNames.ERROR, e);
|
41716
42110
|
throw e;
|
41717
42111
|
}
|
41718
42112
|
}
|
41719
|
-
|
41720
|
-
|
42113
|
+
// eslint-disable-next-line max-params
|
42114
|
+
constructor(appId, debug = false, isTestEnv = false, isSupportVideo = false){
|
42115
|
+
super(debug), this.joinUserId = '', this._AIAnsExtension = null, this._isSupportVideo = false;
|
41721
42116
|
if (isTestEnv) index_esm_min_index.setParameter('ICE_CONFIG_REQUEST_URLS', [
|
41722
42117
|
'rtc-test.bytedance.com'
|
41723
42118
|
]);
|
@@ -41726,9 +42121,11 @@
|
|
41726
42121
|
this.handleUserJoin = this.handleUserJoin.bind(this);
|
41727
42122
|
this.handleUserLeave = this.handleUserLeave.bind(this);
|
41728
42123
|
this.handleEventError = this.handleEventError.bind(this);
|
42124
|
+
this.handlePlayerEvent = this.handlePlayerEvent.bind(this);
|
41729
42125
|
// Debug only
|
41730
42126
|
this.handleLocalAudioPropertiesReport = this.handleLocalAudioPropertiesReport.bind(this);
|
41731
42127
|
this.handleRemoteAudioPropertiesReport = this.handleRemoteAudioPropertiesReport.bind(this);
|
42128
|
+
this._isSupportVideo = isSupportVideo;
|
41732
42129
|
}
|
41733
42130
|
}
|
41734
42131
|
class RealtimeClient extends RealtimeEventHandler {
|
@@ -41737,6 +42134,7 @@
|
|
41737
42134
|
*
|
41738
42135
|
* zh: 建立与 Coze API 的连接并加入房间
|
41739
42136
|
*/ async connect() {
|
42137
|
+
var _this__config_videoConfig;
|
41740
42138
|
const { botId, conversationId, voiceId } = this._config;
|
41741
42139
|
let roomInfo;
|
41742
42140
|
try {
|
@@ -41749,15 +42147,14 @@
|
|
41749
42147
|
});
|
41750
42148
|
} catch (error) {
|
41751
42149
|
this.dispatch(event_handler_EventNames.ERROR, error);
|
41752
|
-
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error');
|
42150
|
+
throw new RealtimeAPIError(error_RealtimeError.CREATE_ROOM_ERROR, error instanceof Error ? error.message : 'Unknown error', error);
|
41753
42151
|
}
|
41754
|
-
this._roomInfo = roomInfo;
|
41755
42152
|
// Step2 create engine
|
41756
|
-
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv);
|
42153
|
+
this._client = new EngineClient(roomInfo.app_id, this._config.debug, this._isTestEnv, this._isSupportVideo);
|
41757
42154
|
// Step3 bind engine events
|
41758
42155
|
this._client.bindEngineEvents();
|
41759
42156
|
this._client.on(event_handler_EventNames.ALL, (eventName, data)=>{
|
41760
|
-
this.dispatch(eventName, data);
|
42157
|
+
this.dispatch(eventName, data, false);
|
41761
42158
|
});
|
41762
42159
|
if (this._config.suppressStationaryNoise) {
|
41763
42160
|
await this._client.enableAudioNoiseReduction();
|
@@ -41768,16 +42165,18 @@
|
|
41768
42165
|
this._client.changeAIAnsExtension(true);
|
41769
42166
|
this.dispatch(event_handler_EventNames.SUPPRESS_NON_STATIONARY_NOISE, {});
|
41770
42167
|
}
|
41771
|
-
var _this__config_audioMutedDefault;
|
42168
|
+
var _this__config_audioMutedDefault, _this__config_videoConfig_videoOnDefault, _this__config_isAutoSubscribeAudio;
|
41772
42169
|
// Step4 join room
|
41773
42170
|
await this._client.joinRoom({
|
41774
42171
|
token: roomInfo.token,
|
41775
42172
|
roomId: roomInfo.room_id,
|
41776
42173
|
uid: roomInfo.uid,
|
41777
|
-
audioMutedDefault: null !== (_this__config_audioMutedDefault = this._config.audioMutedDefault) && void 0 !== _this__config_audioMutedDefault && _this__config_audioMutedDefault
|
42174
|
+
audioMutedDefault: null !== (_this__config_audioMutedDefault = this._config.audioMutedDefault) && void 0 !== _this__config_audioMutedDefault && _this__config_audioMutedDefault,
|
42175
|
+
videoOnDefault: null === (_this__config_videoConfig_videoOnDefault = null === (_this__config_videoConfig = this._config.videoConfig) || void 0 === _this__config_videoConfig ? void 0 : _this__config_videoConfig.videoOnDefault) || void 0 === _this__config_videoConfig_videoOnDefault || _this__config_videoConfig_videoOnDefault,
|
42176
|
+
isAutoSubscribeAudio: null === (_this__config_isAutoSubscribeAudio = this._config.isAutoSubscribeAudio) || void 0 === _this__config_isAutoSubscribeAudio || _this__config_isAutoSubscribeAudio
|
41778
42177
|
});
|
41779
42178
|
// Step5 create local stream
|
41780
|
-
await this._client.createLocalStream();
|
42179
|
+
await this._client.createLocalStream(roomInfo.uid, this._config.videoConfig);
|
41781
42180
|
// step6 set connected and dispatch connected event
|
41782
42181
|
this.isConnected = true;
|
41783
42182
|
this.dispatch(event_handler_EventNames.CONNECTED, {
|
@@ -41786,7 +42185,6 @@
|
|
41786
42185
|
token: roomInfo.token,
|
41787
42186
|
appId: roomInfo.app_id
|
41788
42187
|
});
|
41789
|
-
this._log('dispatch client.connected event');
|
41790
42188
|
}
|
41791
42189
|
/**
|
41792
42190
|
* en: Interrupt the current conversation
|
@@ -41796,7 +42194,6 @@
|
|
41796
42194
|
var _this__client;
|
41797
42195
|
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.stop());
|
41798
42196
|
this.dispatch(event_handler_EventNames.INTERRUPTED, {});
|
41799
|
-
this._log('dispatch client.interrupted event');
|
41800
42197
|
}
|
41801
42198
|
/**
|
41802
42199
|
* en: Disconnect from the current session
|
@@ -41828,6 +42225,12 @@
|
|
41828
42225
|
if (isEnable) this.dispatch(event_handler_EventNames.AUDIO_UNMUTED, {});
|
41829
42226
|
else this.dispatch(event_handler_EventNames.AUDIO_MUTED, {});
|
41830
42227
|
}
|
42228
|
+
async setVideoEnable(isEnable) {
|
42229
|
+
var _this__client;
|
42230
|
+
await (null === (_this__client = this._client) || void 0 === _this__client ? void 0 : _this__client.changeVideoState(isEnable));
|
42231
|
+
if (isEnable) this.dispatch(event_handler_EventNames.VIDEO_ON, {});
|
42232
|
+
else this.dispatch(event_handler_EventNames.VIDEO_OFF, {});
|
42233
|
+
}
|
41831
42234
|
/**
|
41832
42235
|
* en: Enable audio properties reporting (debug mode only)
|
41833
42236
|
*
|
@@ -41912,8 +42315,9 @@
|
|
41912
42315
|
* 可选,默认是否抑制静态噪声,默认值为 false。
|
41913
42316
|
* @param config.suppressNonStationaryNoise - Optional, suppress non-stationary noise, defaults to false. |
|
41914
42317
|
* 可选,默认是否抑制非静态噪声,默认值为 false。
|
42318
|
+
* @param config.isAutoSubscribeAudio - Optional, whether to automatically subscribe to bot reply audio streams, defaults to true. |
|
41915
42319
|
*/ constructor(config){
|
41916
|
-
super(config.debug), this._client = null, this.
|
42320
|
+
super(config.debug), this._client = null, this.isConnected = false, this._isTestEnv = false, this._isSupportVideo = false;
|
41917
42321
|
this._config = config;
|
41918
42322
|
var _this__config_baseURL;
|
41919
42323
|
const defaultBaseURL = null !== (_this__config_baseURL = this._config.baseURL) && void 0 !== _this__config_baseURL ? _this__config_baseURL : 'https://api.coze.cn';
|
@@ -41925,6 +42329,7 @@
|
|
41925
42329
|
allowPersonalAccessTokenInBrowser: this._config.allowPersonalAccessTokenInBrowser
|
41926
42330
|
});
|
41927
42331
|
this._isTestEnv = 'https://api.coze.cn' !== defaultBaseURL;
|
42332
|
+
this._isSupportVideo = !!config.videoConfig;
|
41928
42333
|
}
|
41929
42334
|
}
|
41930
42335
|
return __webpack_exports__;
|