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