@yimou6/common-ui 1.7.8 → 1.9.0
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/cdn/index.cdn.js +10 -9
- package/cdn/index.cdn.js.map +1 -1
- package/cdn/index.cdn.mjs +10 -9
- package/cdn/index.cdn.mjs.map +1 -1
- package/cdn/index.css +1 -1
- package/es/components/concise-logger/index.d.ts +2 -0
- package/es/components/concise-logger/index.mjs +9 -0
- package/es/components/concise-logger/index.mjs.map +1 -0
- package/es/components/concise-logger/src/concise-logger.d.ts +5 -0
- package/es/components/concise-logger/src/concise-logger.mjs +4 -0
- package/es/components/concise-logger/src/concise-logger.mjs.map +1 -0
- package/es/components/concise-logger/src/concise-logger.vue.d.ts +2 -0
- package/es/components/concise-logger/src/concise-logger.vue.mjs +6 -0
- package/es/components/concise-logger/src/concise-logger.vue.mjs.map +1 -0
- package/es/components/concise-logger/src/concise-logger.vue2.mjs +18 -0
- package/es/components/concise-logger/src/concise-logger.vue2.mjs.map +1 -0
- package/es/components/index.d.ts +2 -1
- package/es/components/index.mjs +3 -2
- package/es/components/index.mjs.map +1 -1
- package/es/components/text-button/index.d.ts +238 -1
- package/es/components/text-button/index.mjs +8 -1
- package/es/components/text-button/index.mjs.map +1 -1
- package/es/components/text-button/src/text-button-group.vue.d.ts +92 -0
- package/es/components/text-button/src/text-button-group.vue.mjs +6 -0
- package/es/components/text-button/src/text-button-group.vue.mjs.map +1 -0
- package/es/components/text-button/src/text-button-group.vue2.mjs +56 -0
- package/es/components/text-button/src/text-button-group.vue2.mjs.map +1 -0
- package/es/components/text-button/src/text-button.d.ts +11 -0
- package/es/components/text-button/src/text-button.mjs +7 -1
- package/es/components/text-button/src/text-button.mjs.map +1 -1
- package/es/components/wisdom-chat/index.d.ts +941 -0
- package/es/components/wisdom-chat/index.mjs +8 -0
- package/es/components/wisdom-chat/index.mjs.map +1 -0
- package/es/components/wisdom-chat/src/wisdom-chat.d.ts +82 -0
- package/es/components/wisdom-chat/src/wisdom-chat.mjs +139 -0
- package/es/components/wisdom-chat/src/wisdom-chat.mjs.map +1 -0
- package/es/components/wisdom-chat/src/wisdom-chat.vue.d.ts +941 -0
- package/es/components/wisdom-chat/src/wisdom-chat.vue.mjs +6 -0
- package/es/components/wisdom-chat/src/wisdom-chat.vue.mjs.map +1 -0
- package/es/components/wisdom-chat/src/wisdom-chat.vue2.mjs +393 -0
- package/es/components/wisdom-chat/src/wisdom-chat.vue2.mjs.map +1 -0
- package/es/index.mjs +3 -2
- package/es/index.mjs.map +1 -1
- package/es/installer.mjs +6 -3
- package/es/installer.mjs.map +1 -1
- package/es/utils/provide.d.ts +6 -2
- package/es/utils/provide.mjs.map +1 -1
- package/global.d.ts +2 -0
- package/lib/components/concise-logger/index.d.ts +2 -0
- package/lib/components/concise-logger/index.js +14 -0
- package/lib/components/concise-logger/index.js.map +1 -0
- package/lib/components/concise-logger/src/concise-logger.d.ts +5 -0
- package/lib/components/concise-logger/src/concise-logger.js +6 -0
- package/lib/components/concise-logger/src/concise-logger.js.map +1 -0
- package/lib/components/concise-logger/src/concise-logger.vue.d.ts +2 -0
- package/lib/components/concise-logger/src/concise-logger.vue.js +10 -0
- package/lib/components/concise-logger/src/concise-logger.vue.js.map +1 -0
- package/lib/components/concise-logger/src/concise-logger.vue2.js +22 -0
- package/lib/components/concise-logger/src/concise-logger.vue2.js.map +1 -0
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +8 -5
- package/lib/components/index.js.map +1 -1
- package/lib/components/text-button/index.d.ts +238 -1
- package/lib/components/text-button/index.js +9 -1
- package/lib/components/text-button/index.js.map +1 -1
- package/lib/components/text-button/src/text-button-group.vue.d.ts +92 -0
- package/lib/components/text-button/src/text-button-group.vue.js +10 -0
- package/lib/components/text-button/src/text-button-group.vue.js.map +1 -0
- package/lib/components/text-button/src/text-button-group.vue2.js +60 -0
- package/lib/components/text-button/src/text-button-group.vue2.js.map +1 -0
- package/lib/components/text-button/src/text-button.d.ts +11 -0
- package/lib/components/text-button/src/text-button.js +7 -0
- package/lib/components/text-button/src/text-button.js.map +1 -1
- package/lib/components/wisdom-chat/index.d.ts +941 -0
- package/lib/components/wisdom-chat/index.js +13 -0
- package/lib/components/wisdom-chat/index.js.map +1 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.d.ts +82 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.js +142 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.js.map +1 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.vue.d.ts +941 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.vue.js +10 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.vue.js.map +1 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.vue2.js +397 -0
- package/lib/components/wisdom-chat/src/wisdom-chat.vue2.js.map +1 -0
- package/lib/index.js +12 -9
- package/lib/index.js.map +1 -1
- package/lib/installer.js +5 -2
- package/lib/installer.js.map +1 -1
- package/lib/utils/provide.d.ts +6 -2
- package/lib/utils/provide.js.map +1 -1
- package/package.json +3 -2
- package/theme-default/i-table.css +1 -1
- package/theme-default/i-text-button.css +1 -1
- package/theme-default/i-wisdom-chat.css +1 -0
- package/theme-default/index.css +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var install = require('../../utils/install.js');
|
|
6
|
+
require('./src/wisdom-chat.vue.js');
|
|
7
|
+
var wisdomChat_vue_vue_type_script_setup_true_lang = require('./src/wisdom-chat.vue2.js');
|
|
8
|
+
|
|
9
|
+
const IWisdomChat = install.withInstall(wisdomChat_vue_vue_type_script_setup_true_lang.default);
|
|
10
|
+
|
|
11
|
+
exports.IWisdomChat = IWisdomChat;
|
|
12
|
+
exports.default = IWisdomChat;
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../packages/components/wisdom-chat/index.ts"],"sourcesContent":["import { withInstall } from '../../utils/install';\nimport WisdomChat from './src/wisdom-chat.vue';\nimport type {\n ChatMessageItemType,\n ChatMessageType,\n ModelType,\n SSEEvent,\n SSEOptions,\n WisdomChatInstance,\n WisdomChatPropsType,\n WisdomChatRobotType,\n WisdomChatSelfType,\n} from './src/wisdom-chat';\n\n// 导出组件\nexport const IWisdomChat = withInstall(WisdomChat);\n\n// 导出类型\nexport {\n ChatMessageItemType,\n ChatMessageType,\n ModelType,\n SSEEvent,\n SSEOptions,\n WisdomChatInstance,\n WisdomChatPropsType,\n WisdomChatRobotType,\n WisdomChatSelfType,\n};\n\n// 默认导出\nexport default IWisdomChat;\n"],"names":["withInstall","WisdomChat"],"mappings":";;;;;;;;AAea,MAAA,WAAA,GAAcA,oBAAYC,sDAAU;;;;;"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ExtractPropTypes, PropType } from 'vue';
|
|
2
|
+
import type WisdomChat from './wisdom-chat.vue';
|
|
3
|
+
export interface WisdomChatSelfType {
|
|
4
|
+
name: string;
|
|
5
|
+
avatar?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface WisdomChatRobotType {
|
|
8
|
+
name: string;
|
|
9
|
+
avatar?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ChatMessageType {
|
|
12
|
+
role: 'user' | 'assistant' | 'error' | 'model-change';
|
|
13
|
+
content: string;
|
|
14
|
+
images?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface ChatMessageItemType {
|
|
17
|
+
avatar?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
datetime: string;
|
|
20
|
+
content: string;
|
|
21
|
+
role: 'assistant' | 'user' | 'model-change' | 'error' | 'system' | undefined;
|
|
22
|
+
image?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ModelType {
|
|
25
|
+
label: string;
|
|
26
|
+
value: string;
|
|
27
|
+
type: 'chat' | 'chat-image';
|
|
28
|
+
description?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const WisdomChatProps: {
|
|
31
|
+
self: {
|
|
32
|
+
type: PropType<WisdomChatSelfType>;
|
|
33
|
+
default: () => {
|
|
34
|
+
name: string;
|
|
35
|
+
avatar: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
robot: {
|
|
39
|
+
type: PropType<WisdomChatRobotType>;
|
|
40
|
+
default: () => {
|
|
41
|
+
name: string;
|
|
42
|
+
avatar: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
models: {
|
|
46
|
+
type: PropType<ModelType[]>;
|
|
47
|
+
default: () => never[];
|
|
48
|
+
};
|
|
49
|
+
apiUrl: {
|
|
50
|
+
type: StringConstructor;
|
|
51
|
+
default: string;
|
|
52
|
+
};
|
|
53
|
+
welcomeMessage: {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
default: string;
|
|
56
|
+
};
|
|
57
|
+
showModelSelector: {
|
|
58
|
+
type: BooleanConstructor;
|
|
59
|
+
default: boolean;
|
|
60
|
+
};
|
|
61
|
+
showClearButton: {
|
|
62
|
+
type: BooleanConstructor;
|
|
63
|
+
default: boolean;
|
|
64
|
+
};
|
|
65
|
+
maxImageSize: {
|
|
66
|
+
type: NumberConstructor;
|
|
67
|
+
default: number;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export type WisdomChatPropsType = ExtractPropTypes<typeof WisdomChatProps>;
|
|
71
|
+
export type WisdomChatInstance = InstanceType<typeof WisdomChat>;
|
|
72
|
+
export interface SSEEvent {
|
|
73
|
+
type: 'delta' | 'finish' | null;
|
|
74
|
+
data: string | null;
|
|
75
|
+
}
|
|
76
|
+
export interface SSEOptions {
|
|
77
|
+
success?: (event: SSEEvent) => void;
|
|
78
|
+
fail?: () => void;
|
|
79
|
+
complete?: (isOk: boolean, msg?: string) => void;
|
|
80
|
+
cancel?: (controller: AbortController) => void;
|
|
81
|
+
}
|
|
82
|
+
export declare const fetchSSE: (messages: ChatMessageType[], model: string, options: SSEOptions, apiUrl?: string) => Promise<void>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const WisdomChatProps = {
|
|
6
|
+
/** 用户配置 */
|
|
7
|
+
self: {
|
|
8
|
+
type: Object,
|
|
9
|
+
default: /* @__PURE__ */ __name(() => ({
|
|
10
|
+
name: "",
|
|
11
|
+
avatar: ""
|
|
12
|
+
}), "default")
|
|
13
|
+
},
|
|
14
|
+
/** 智能助手配置 */
|
|
15
|
+
robot: {
|
|
16
|
+
type: Object,
|
|
17
|
+
default: /* @__PURE__ */ __name(() => ({
|
|
18
|
+
name: "\u667A\u80FD\u5C0F\u73C8",
|
|
19
|
+
avatar: "https://3119.tzj-iot.cn/tezhijia/login.png"
|
|
20
|
+
}), "default")
|
|
21
|
+
},
|
|
22
|
+
/** 可用模型列表 */
|
|
23
|
+
models: {
|
|
24
|
+
type: Array,
|
|
25
|
+
default: /* @__PURE__ */ __name(() => [], "default")
|
|
26
|
+
},
|
|
27
|
+
/** 聊天API地址,默认为/api/chat */
|
|
28
|
+
apiUrl: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: "/api/chat"
|
|
31
|
+
},
|
|
32
|
+
/** 初始欢迎消息 */
|
|
33
|
+
welcomeMessage: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: "\u65E9\u4E0A\u597D"
|
|
36
|
+
},
|
|
37
|
+
/** 是否显示模型选择器 */
|
|
38
|
+
showModelSelector: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: true
|
|
41
|
+
},
|
|
42
|
+
/** 是否显示清空历史按钮 */
|
|
43
|
+
showClearButton: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
/** 最大图片上传大小(MB) */
|
|
48
|
+
maxImageSize: {
|
|
49
|
+
type: Number,
|
|
50
|
+
default: 5
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const fetchSSE = /* @__PURE__ */ __name(async (messages, model, options, apiUrl = "/api/chat") => {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
const { success, fail, complete, cancel } = options;
|
|
56
|
+
const controller = new AbortController();
|
|
57
|
+
const { signal } = controller;
|
|
58
|
+
cancel == null ? void 0 : cancel(controller);
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(apiUrl, {
|
|
61
|
+
method: "POST",
|
|
62
|
+
mode: "no-cors",
|
|
63
|
+
credentials: "include",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json"
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
messages,
|
|
69
|
+
model,
|
|
70
|
+
stream: true
|
|
71
|
+
}),
|
|
72
|
+
signal
|
|
73
|
+
});
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
const errorMsg = `HTTP error! status: ${response.status} ${response.statusText}`;
|
|
76
|
+
complete == null ? void 0 : complete(false, errorMsg);
|
|
77
|
+
fail == null ? void 0 : fail();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const reader = (_a = response.body) == null ? void 0 : _a.getReader();
|
|
81
|
+
if (!reader) {
|
|
82
|
+
complete == null ? void 0 : complete(false, "\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u6D41");
|
|
83
|
+
fail == null ? void 0 : fail();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const decoder = new TextDecoder("utf-8");
|
|
87
|
+
let buffer = "";
|
|
88
|
+
const event = {
|
|
89
|
+
type: null,
|
|
90
|
+
data: null
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
while (true) {
|
|
94
|
+
const { done, value } = await reader.read();
|
|
95
|
+
if (done) {
|
|
96
|
+
complete == null ? void 0 : complete(true);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
buffer += decoder.decode(value, { stream: true });
|
|
100
|
+
const lines = buffer.split("\n");
|
|
101
|
+
buffer = lines.pop() || "";
|
|
102
|
+
for (const line of lines) {
|
|
103
|
+
if (line.trim() === "") continue;
|
|
104
|
+
try {
|
|
105
|
+
const chunk = JSON.parse(line);
|
|
106
|
+
if (chunk.done) {
|
|
107
|
+
event.type = "finish";
|
|
108
|
+
event.data = "";
|
|
109
|
+
success == null ? void 0 : success(event);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (chunk.message && ((_b = chunk.message) == null ? void 0 : _b.content)) {
|
|
113
|
+
event.type = "delta";
|
|
114
|
+
event.data = (_c = chunk.message) == null ? void 0 : _c.content;
|
|
115
|
+
if (event.type && event.data) {
|
|
116
|
+
success == null ? void 0 : success(event);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("Error parsing JSON:", error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error.name !== "AbortError") {
|
|
126
|
+
const errorMsg = error.toString() || "\u6D41\u5F0F\u6570\u636E\u5904\u7406\u5F02\u5E38";
|
|
127
|
+
complete == null ? void 0 : complete(false, errorMsg);
|
|
128
|
+
fail == null ? void 0 : fail();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error.name !== "AbortError") {
|
|
133
|
+
const errorMsg = error.toString() || "\u6D41\u5F0F\u63A5\u53E3\u5F02\u5E38";
|
|
134
|
+
complete == null ? void 0 : complete(false, errorMsg);
|
|
135
|
+
fail == null ? void 0 : fail();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}, "fetchSSE");
|
|
139
|
+
|
|
140
|
+
exports.WisdomChatProps = WisdomChatProps;
|
|
141
|
+
exports.fetchSSE = fetchSSE;
|
|
142
|
+
//# sourceMappingURL=wisdom-chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wisdom-chat.js","sources":["../../../../../../../packages/components/wisdom-chat/src/wisdom-chat.ts"],"sourcesContent":["import type { ExtractPropTypes, PropType } from 'vue';\nimport type WisdomChat from './wisdom-chat.vue';\n\n/**\n * 用户配置接口\n */\nexport interface WisdomChatSelfType {\n /** 用户名称 */\n name: string;\n /** 用户头像URL */\n avatar?: string;\n}\n\n/**\n * 机器人配置接口\n */\nexport interface WisdomChatRobotType {\n /** 机器人名称 */\n name: string;\n /** 机器人头像URL */\n avatar?: string;\n}\n\n/**\n * 聊天消息类型\n */\nexport interface ChatMessageType {\n /** 消息角色: user-用户, assistant-助手, error-错误, model-change-模型变更 */\n role: 'user' | 'assistant' | 'error' | 'model-change';\n /** 消息内容 */\n content: string;\n /** 图片数据(Base64) */\n images?: string[];\n}\n\n/**\n * 聊天消息列表项\n */\nexport interface ChatMessageItemType {\n /** 头像 */\n avatar?: string;\n /** 昵称 */\n name?: string;\n /** 时间 */\n datetime: string;\n /** 对话内容 */\n content: string;\n /** 角色 */\n role: 'assistant' | 'user' | 'model-change' | 'error' | 'system' | undefined;\n /** 图片 */\n image?: string;\n}\n\n/**\n * 模型类型接口\n */\nexport interface ModelType {\n /** 显示名称 */\n label: string;\n /** 模型名称,要与后端模型名称一致 */\n value: string;\n /** 模型类型: chat-仅支持文本, chat-image-支持图像 */\n type: 'chat' | 'chat-image';\n /** 模型描述 */\n description?: string;\n}\n\n/**\n * WisdomChat组件属性定义\n */\nexport const WisdomChatProps = {\n /** 用户配置 */\n self: {\n type: Object as PropType<WisdomChatSelfType>,\n default: () => ({\n name: '',\n avatar: '',\n }),\n },\n /** 智能助手配置 */\n robot: {\n type: Object as PropType<WisdomChatRobotType>,\n default: () => ({\n name: '智能小珈',\n avatar: 'https://3119.tzj-iot.cn/tezhijia/login.png',\n }),\n },\n /** 可用模型列表 */\n models: {\n type: Array as PropType<ModelType[]>,\n default: () => [],\n },\n /** 聊天API地址,默认为/api/chat */\n apiUrl: {\n type: String,\n default: '/api/chat',\n },\n /** 初始欢迎消息 */\n welcomeMessage: {\n type: String,\n default: '早上好',\n },\n /** 是否显示模型选择器 */\n showModelSelector: {\n type: Boolean,\n default: true,\n },\n /** 是否显示清空历史按钮 */\n showClearButton: {\n type: Boolean,\n default: true,\n },\n /** 最大图片上传大小(MB) */\n maxImageSize: {\n type: Number,\n default: 5,\n },\n};\n\nexport type WisdomChatPropsType = ExtractPropTypes<typeof WisdomChatProps>;\nexport type WisdomChatInstance = InstanceType<typeof WisdomChat>;\n\n/**\n * SSE事件类型\n */\nexport interface SSEEvent {\n /** 事件类型: delta-增量内容, finish-完成 */\n type: 'delta' | 'finish' | null;\n /** 事件数据 */\n data: string | null;\n}\n\n/**\n * SSE回调选项\n */\nexport interface SSEOptions {\n /** 成功回调,接收增量内容 */\n success?: (event: SSEEvent) => void;\n /** 失败回调 */\n fail?: () => void;\n /** 完成回调,isOk表示是否成功,msg为错误信息 */\n complete?: (isOk: boolean, msg?: string) => void;\n /** 取消回调,接收AbortController实例 */\n cancel?: (controller: AbortController) => void;\n}\n\n/**\n * 发送SSE请求并处理流式响应\n * @param messages 消息列表\n * @param model 模型名称\n * @param options 回调选项\n * @param apiUrl API地址\n */\nexport const fetchSSE = async (\n messages: ChatMessageType[],\n model: string,\n options: SSEOptions,\n apiUrl: string = '/api/chat',\n) => {\n const { success, fail, complete, cancel } = options;\n const controller = new AbortController();\n const { signal } = controller;\n\n // 提供取消方法\n cancel?.(controller);\n\n try {\n const response = await fetch(apiUrl, {\n method: 'POST',\n mode: 'no-cors',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n messages,\n model,\n stream: true,\n }),\n signal,\n });\n\n if (!response.ok) {\n const errorMsg = `HTTP error! status: ${response.status} ${response.statusText}`;\n complete?.(false, errorMsg);\n fail?.();\n return;\n }\n\n const reader = response.body?.getReader();\n if (!reader) {\n complete?.(false, '无法获取响应流');\n fail?.();\n return;\n }\n\n const decoder = new TextDecoder('utf-8');\n let buffer = '';\n const event: SSEEvent = {\n type: null,\n data: null,\n };\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n complete?.(true);\n return;\n }\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split('\\n');\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim() === '') continue;\n\n try {\n const chunk = JSON.parse(line);\n\n if (chunk.done) {\n event.type = 'finish';\n event.data = '';\n success?.(event);\n break;\n }\n\n if (chunk.message && chunk.message?.content) {\n event.type = 'delta';\n event.data = chunk.message?.content;\n\n if (event.type && event.data) {\n success?.(event);\n }\n }\n } catch (error) {\n console.error('Error parsing JSON:', error);\n }\n }\n }\n } catch (error) {\n // 处理读取流时的错误,但忽略AbortError(用户取消)\n if ((error as any).name !== 'AbortError') {\n const errorMsg = (error as any).toString() || '流式数据处理异常';\n complete?.(false, errorMsg);\n fail?.();\n }\n }\n } catch (error) {\n // 处理fetch请求错误,但忽略AbortError(用户取消)\n if ((error as any).name !== 'AbortError') {\n const errorMsg = (error as any).toString() || '流式接口异常';\n complete?.(false, errorMsg);\n fail?.();\n }\n }\n};\n"],"names":[],"mappings":";;;;AAsEO,MAAM,eAAkB,GAAA;AAAA;AAAA,EAE7B,IAAM,EAAA;AAAA,IACJ,IAAM,EAAA,MAAA;AAAA,IACN,yBAAgB,MAAA,CAAA,OAAA;AAAA,MACd,IAAM,EAAA,EAAA;AAAA,MACN,MAAQ,EAAA;AAAA,KAFD,CAAA,EAAA,SAAA;AAAA,GAIX;AAAA;AAAA,EAEA,KAAO,EAAA;AAAA,IACL,IAAM,EAAA,MAAA;AAAA,IACN,yBAAgB,MAAA,CAAA,OAAA;AAAA,MACd,IAAM,EAAA,0BAAA;AAAA,MACN,MAAQ,EAAA;AAAA,KAFD,CAAA,EAAA,SAAA;AAAA,GAIX;AAAA;AAAA,EAEA,MAAQ,EAAA;AAAA,IACN,IAAM,EAAA,KAAA;AAA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