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