@base-web-kits/base-tools-web 1.3.5 → 1.3.8
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 +93 -0
- package/dist/base-tools-web.umd.global.js +7 -4
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/index.cjs +7 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -7
- package/dist/index.mjs +7 -4
- package/dist/index.mjs.map +1 -1
- package/dist/network/request.d.ts +14 -6
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/web/network/request.ts +21 -9
package/dist/index.d.cts
CHANGED
|
@@ -410,7 +410,16 @@ type RequestConfigBase<D extends RequestData = RequestData> = {
|
|
|
410
410
|
resMap?: (data: ResponseData) => ResponseData;
|
|
411
411
|
/** 获取请求对象, 用于取消请求 */
|
|
412
412
|
onTaskReady?: (task: RequestTask) => void;
|
|
413
|
-
/**
|
|
413
|
+
/**
|
|
414
|
+
* 流式数据接收事件回调 (已完成基础流式解析,返回消息对象)
|
|
415
|
+
* @example
|
|
416
|
+
* function onMessage(msg: SSEMessage) {
|
|
417
|
+
* console.log(msg);
|
|
418
|
+
* if(msg.type === 'DONE') { } // 流式传输结束
|
|
419
|
+
* if(msg.type === 'thinking') { } // 思考中
|
|
420
|
+
* if(msg.type === 'xx') { } // 各种消息类型
|
|
421
|
+
* }
|
|
422
|
+
*/
|
|
414
423
|
onMessage?: MessageCallback;
|
|
415
424
|
};
|
|
416
425
|
/** 请求任务对象 (用于取消请求) */
|
|
@@ -418,10 +427,6 @@ type RequestTask = {
|
|
|
418
427
|
/** 取消请求 */
|
|
419
428
|
abort: () => void;
|
|
420
429
|
};
|
|
421
|
-
/** 流式数据块接收事件回调 */
|
|
422
|
-
type ChunkCallback = (response: {
|
|
423
|
-
data: ArrayBuffer;
|
|
424
|
-
}) => void;
|
|
425
430
|
/**
|
|
426
431
|
* 基础请求 (返回 Promise 和 Task 对象)
|
|
427
432
|
* 基于 fetch API 封装,支持流式请求
|
|
@@ -493,13 +498,16 @@ type ChunkCallback = (response: {
|
|
|
493
498
|
* // 流式监听
|
|
494
499
|
* const onMessage = (msg: SSEMessage) => {
|
|
495
500
|
* console.log(msg);
|
|
501
|
+
* if(msg.type === 'DONE') { } // 流式传输结束
|
|
502
|
+
* if(msg.type === 'thinking') { } // 思考中
|
|
503
|
+
* if(msg.type === 'xx') { } // 各种消息类型
|
|
496
504
|
* }
|
|
497
505
|
*
|
|
498
506
|
* // 流式发起
|
|
499
507
|
* const data = { content: '你好', chatId: 123 };
|
|
500
508
|
* apiChatStream({ data, onTaskReady, onMessage });
|
|
501
509
|
*
|
|
502
|
-
* // 流式取消 (
|
|
510
|
+
* // 流式取消 (在组件销毁或页面关闭时调用)
|
|
503
511
|
* chatTask?.abort();
|
|
504
512
|
*/
|
|
505
513
|
declare function request<T, D extends RequestData = RequestData>(config: RequestConfigBase<D>): Promise<T>;
|
|
@@ -662,4 +670,4 @@ declare function getUrlNumber(key: string, url?: string): number | null;
|
|
|
662
670
|
*/
|
|
663
671
|
declare function getUrlParams(url?: string): Record<string, string>;
|
|
664
672
|
|
|
665
|
-
export { type AppConfig, type AppLogInfo, type
|
|
673
|
+
export { type AppConfig, type AppLogInfo, type OnUploadProgressUpdate, type RequestConfig, type RequestConfigBase, type RequestData, type RequestMethod, type RequestTask, type ResponseData, type UploadConfig, type UploadFail, type UploadFileOption, type UploadProgressEvent, type UploadTask, copyBlob, copyHtml, copyImage, copyNode, copyRtf, copyTable, copyText, copyUrl, download, filterRequestData, filterRequestHeader, getBaseToolsConfig, getBrowserName, getBrowserVersion, getCookie, getDevicePixelRatio, getDispositionFileName, getLocalStorage, getOS, getUA, getUrlNumber, getUrlParam, getUrlParams, getWindowHeight, getWindowScrollLeft, getWindowScrollTop, getWindowWidth, hasCss, hasJs, isAndroid, isChrome, isIOS, isInViewport, isMobile, isPC, isTablet, isTouchSupported, isWeChat, loadCss, loadJs, lockBodyScroll, preloadImage, removeCookie, removeLocalStorage, request, setBaseToolsConfig, setCookie, setLocalStorage, unlockBodyScroll, uploadFile, windowScrollTo };
|
package/dist/index.mjs
CHANGED
|
@@ -1403,7 +1403,8 @@ function request(config) {
|
|
|
1403
1403
|
reject(timeoutError);
|
|
1404
1404
|
return;
|
|
1405
1405
|
}
|
|
1406
|
-
if (!isAbortError && toastError)
|
|
1406
|
+
if (!isAbortError && toastError)
|
|
1407
|
+
(_h = appConfig2.toast) == null ? void 0 : _h.call(appConfig2, { status, msg: `\u8BF7\u6C42\u5931\u8D25,${String(e)}` });
|
|
1407
1408
|
logRequestInfo({ status, config: logConfig, startTime, e });
|
|
1408
1409
|
reject(e);
|
|
1409
1410
|
} finally {
|
|
@@ -1453,7 +1454,7 @@ function logRequestInfo(options) {
|
|
|
1453
1454
|
info.res = cloneDeep(res);
|
|
1454
1455
|
log("info", info);
|
|
1455
1456
|
} else {
|
|
1456
|
-
info.e = e;
|
|
1457
|
+
info.e = e instanceof Error ? { name: e.name, message: e.message, stack: e.stack } : String(e);
|
|
1457
1458
|
log("error", info);
|
|
1458
1459
|
}
|
|
1459
1460
|
}
|
|
@@ -1472,9 +1473,11 @@ function checkCache(cacheKey) {
|
|
|
1472
1473
|
}
|
|
1473
1474
|
function handleStreamResponse(response, sseTask) {
|
|
1474
1475
|
return __async(this, null, function* () {
|
|
1475
|
-
if (!response.body)
|
|
1476
|
+
if (!response.body) throw new Error("Response body is null");
|
|
1476
1477
|
if (sseTask.parser === void 0) {
|
|
1477
|
-
|
|
1478
|
+
throw new Error(
|
|
1479
|
+
"Stream parser missing: Please set config.onMessage when enableChunked is true"
|
|
1480
|
+
);
|
|
1478
1481
|
}
|
|
1479
1482
|
const reader = response.body.getReader();
|
|
1480
1483
|
while (true) {
|