@yh-ui/hooks 1.0.1 → 1.0.5
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/dist/use-ai/index.cjs +76 -20
- package/dist/use-ai/index.d.ts +4 -2
- package/dist/use-ai/index.mjs +12 -2
- package/dist/use-ai/use-ai-chat.cjs +5 -1
- package/dist/use-ai/use-ai-chat.d.ts +9 -0
- package/dist/use-ai/use-ai-chat.mjs +3 -0
- package/dist/use-ai/use-ai-stream.cjs +7 -4
- package/dist/use-ai/use-ai-stream.d.ts +20 -0
- package/dist/use-ai/use-ai-stream.mjs +5 -2
- package/dist/use-locale/dayjs-locale.cjs +1 -2
- package/dist/use-locale/dayjs-locale.d.ts +0 -1
- package/dist/use-locale/dayjs-locale.mjs +1 -2
- package/package.json +3 -3
package/dist/use-ai/index.cjs
CHANGED
|
@@ -3,31 +3,84 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
useAiChat: true,
|
|
8
|
+
aiChatTestUtils: true,
|
|
9
|
+
useAiStream: true,
|
|
10
|
+
openaiParser: true,
|
|
11
|
+
ernieParser: true,
|
|
12
|
+
qwenParser: true,
|
|
13
|
+
claudeParser: true,
|
|
14
|
+
geminiParser: true,
|
|
15
|
+
plainTextParser: true,
|
|
16
|
+
aiStreamTestUtils: true
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "aiChatTestUtils", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useAiChat.__test__;
|
|
22
|
+
}
|
|
16
23
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
Object.defineProperty(exports, "aiStreamTestUtils", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useAiStream.__test__;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "claudeParser", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _useAiStream.claudeParser;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "ernieParser", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _useAiStream.ernieParser;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "geminiParser", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _useAiStream.geminiParser;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "openaiParser", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _useAiStream.openaiParser;
|
|
52
|
+
}
|
|
27
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "plainTextParser", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _useAiStream.plainTextParser;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "qwenParser", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _useAiStream.qwenParser;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "useAiChat", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _useAiChat.useAiChat;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "useAiStream", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _useAiStream.useAiStream;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
var _useAiChat = require("./use-ai-chat.cjs");
|
|
79
|
+
var _useAiStream = require("./use-ai-stream.cjs");
|
|
28
80
|
var _useAiConversations = require("./use-ai-conversations.cjs");
|
|
29
81
|
Object.keys(_useAiConversations).forEach(function (key) {
|
|
30
82
|
if (key === "default" || key === "__esModule") return;
|
|
83
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
31
84
|
if (key in exports && exports[key] === _useAiConversations[key]) return;
|
|
32
85
|
Object.defineProperty(exports, key, {
|
|
33
86
|
enumerable: true,
|
|
@@ -39,6 +92,7 @@ Object.keys(_useAiConversations).forEach(function (key) {
|
|
|
39
92
|
var _useAiRequest = require("./use-ai-request.cjs");
|
|
40
93
|
Object.keys(_useAiRequest).forEach(function (key) {
|
|
41
94
|
if (key === "default" || key === "__esModule") return;
|
|
95
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
96
|
if (key in exports && exports[key] === _useAiRequest[key]) return;
|
|
43
97
|
Object.defineProperty(exports, key, {
|
|
44
98
|
enumerable: true,
|
|
@@ -50,6 +104,7 @@ Object.keys(_useAiRequest).forEach(function (key) {
|
|
|
50
104
|
var _useAiVoice = require("./use-ai-voice.cjs");
|
|
51
105
|
Object.keys(_useAiVoice).forEach(function (key) {
|
|
52
106
|
if (key === "default" || key === "__esModule") return;
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
53
108
|
if (key in exports && exports[key] === _useAiVoice[key]) return;
|
|
54
109
|
Object.defineProperty(exports, key, {
|
|
55
110
|
enumerable: true,
|
|
@@ -61,6 +116,7 @@ Object.keys(_useAiVoice).forEach(function (key) {
|
|
|
61
116
|
var _useAiPersistence = require("./use-ai-persistence.cjs");
|
|
62
117
|
Object.keys(_useAiPersistence).forEach(function (key) {
|
|
63
118
|
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
64
120
|
if (key in exports && exports[key] === _useAiPersistence[key]) return;
|
|
65
121
|
Object.defineProperty(exports, key, {
|
|
66
122
|
enumerable: true,
|
package/dist/use-ai/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { useAiChat, type AiChatMessage, type UseAiChatOptions } from './use-ai-chat';
|
|
2
|
+
export { __test__ as aiChatTestUtils } from './use-ai-chat';
|
|
3
|
+
export { useAiStream, openaiParser, ernieParser, qwenParser, claudeParser, geminiParser, plainTextParser, type StreamChunkParser, type AiStreamOptions, type UseAiStreamOptions } from './use-ai-stream';
|
|
4
|
+
export { __test__ as aiStreamTestUtils } from './use-ai-stream';
|
|
3
5
|
export * from './use-ai-conversations';
|
|
4
6
|
export * from './use-ai-request';
|
|
5
7
|
export * from './use-ai-voice';
|
package/dist/use-ai/index.mjs
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { useAiChat } from "./use-ai-chat.mjs";
|
|
2
|
+
export { __test__ as aiChatTestUtils } from "./use-ai-chat.mjs";
|
|
3
|
+
export {
|
|
4
|
+
useAiStream,
|
|
5
|
+
openaiParser,
|
|
6
|
+
ernieParser,
|
|
7
|
+
qwenParser,
|
|
8
|
+
claudeParser,
|
|
9
|
+
geminiParser,
|
|
10
|
+
plainTextParser
|
|
11
|
+
} from "./use-ai-stream.mjs";
|
|
12
|
+
export { __test__ as aiStreamTestUtils } from "./use-ai-stream.mjs";
|
|
3
13
|
export * from "./use-ai-conversations.mjs";
|
|
4
14
|
export * from "./use-ai-request.mjs";
|
|
5
15
|
export * from "./use-ai-voice.mjs";
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.__test__ = void 0;
|
|
6
7
|
exports.useAiChat = useAiChat;
|
|
7
8
|
var _vue = require("vue");
|
|
8
9
|
var _useAiStream = require("./use-ai-stream.cjs");
|
|
@@ -190,4 +191,7 @@ function useAiChat(options = {}) {
|
|
|
190
191
|
/** 重置清空所有会话 */
|
|
191
192
|
clear
|
|
192
193
|
};
|
|
193
|
-
}
|
|
194
|
+
}
|
|
195
|
+
const __test__ = exports.__test__ = {
|
|
196
|
+
createTypewriter
|
|
197
|
+
};
|
|
@@ -60,6 +60,11 @@ export interface UseAiChatOptions {
|
|
|
60
60
|
/** 消息发送完成回调 */
|
|
61
61
|
onFinish?: (message: AiChatMessage) => void;
|
|
62
62
|
}
|
|
63
|
+
declare function createTypewriter(onChar: (char: string) => void, charsPerFrame: number): {
|
|
64
|
+
push: (text: string) => void;
|
|
65
|
+
flush: () => void;
|
|
66
|
+
cancel: () => void;
|
|
67
|
+
};
|
|
63
68
|
/**
|
|
64
69
|
* useAiChat - 核心 AI 会话管理 Hook
|
|
65
70
|
*
|
|
@@ -113,3 +118,7 @@ export declare function useAiChat(options?: UseAiChatOptions): {
|
|
|
113
118
|
/** 重置清空所有会话 */
|
|
114
119
|
clear: () => void;
|
|
115
120
|
};
|
|
121
|
+
export declare const __test__: {
|
|
122
|
+
createTypewriter: typeof createTypewriter;
|
|
123
|
+
};
|
|
124
|
+
export {};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.qwenParser = exports.plainTextParser = exports.openaiParser = exports.geminiParser = exports.ernieParser = exports.claudeParser = void 0;
|
|
6
|
+
exports.qwenParser = exports.plainTextParser = exports.openaiParser = exports.geminiParser = exports.ernieParser = exports.claudeParser = exports.__test__ = void 0;
|
|
7
7
|
exports.useAiStream = useAiStream;
|
|
8
8
|
var _vue = require("vue");
|
|
9
9
|
const openaiParser = raw => {
|
|
@@ -168,7 +168,7 @@ function useAiStream(options) {
|
|
|
168
168
|
for await (const chunk of response) {
|
|
169
169
|
if (abortController.signal.aborted) break;
|
|
170
170
|
const parsed = parser(chunk);
|
|
171
|
-
if (parsed) pushText(parsed);
|
|
171
|
+
if (parsed !== null) pushText(parsed);
|
|
172
172
|
}
|
|
173
173
|
} else if (response instanceof Response && response.body) {
|
|
174
174
|
const reader = response.body.getReader();
|
|
@@ -187,7 +187,7 @@ function useAiStream(options) {
|
|
|
187
187
|
stream: true
|
|
188
188
|
});
|
|
189
189
|
const parsed = parser(chunkStr);
|
|
190
|
-
if (parsed) pushText(parsed);
|
|
190
|
+
if (parsed !== null) pushText(parsed);
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
if (!abortController.signal.aborted) {
|
|
@@ -220,4 +220,7 @@ function useAiStream(options) {
|
|
|
220
220
|
plainTextParser
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
|
-
}
|
|
223
|
+
}
|
|
224
|
+
const __test__ = exports.__test__ = {
|
|
225
|
+
TypewriterThrottle
|
|
226
|
+
};
|
|
@@ -28,6 +28,21 @@ export declare const geminiParser: StreamChunkParser;
|
|
|
28
28
|
* 纯文本流解析器(AsyncGenerator 输出的原始字符串)
|
|
29
29
|
*/
|
|
30
30
|
export declare const plainTextParser: StreamChunkParser;
|
|
31
|
+
/**
|
|
32
|
+
* 基于 requestAnimationFrame 的平滑打字机效果
|
|
33
|
+
* 将一次性的大量文字拆分为每帧若干字符的均匀输出
|
|
34
|
+
*/
|
|
35
|
+
declare class TypewriterThrottle {
|
|
36
|
+
private queue;
|
|
37
|
+
private rafId;
|
|
38
|
+
private onUpdate;
|
|
39
|
+
private charsPerFrame;
|
|
40
|
+
constructor(onUpdate: (content: string) => void, charsPerFrame?: number);
|
|
41
|
+
push(text: string): void;
|
|
42
|
+
private schedule;
|
|
43
|
+
flush(): void;
|
|
44
|
+
cancel(): void;
|
|
45
|
+
}
|
|
31
46
|
export interface AiStreamOptions {
|
|
32
47
|
/**
|
|
33
48
|
* 请求适配器,返回 AsyncGenerator 或 fetch Response
|
|
@@ -52,6 +67,7 @@ export interface AiStreamOptions {
|
|
|
52
67
|
onFinish?: (content: string) => void;
|
|
53
68
|
onError?: (err: Error) => void;
|
|
54
69
|
}
|
|
70
|
+
export type UseAiStreamOptions = AiStreamOptions;
|
|
55
71
|
/**
|
|
56
72
|
* useAiStream - 多厂商兼容流式请求引擎
|
|
57
73
|
*
|
|
@@ -74,3 +90,7 @@ export declare function useAiStream(options: AiStreamOptions): {
|
|
|
74
90
|
plainTextParser: StreamChunkParser;
|
|
75
91
|
};
|
|
76
92
|
};
|
|
93
|
+
export declare const __test__: {
|
|
94
|
+
TypewriterThrottle: typeof TypewriterThrottle;
|
|
95
|
+
};
|
|
96
|
+
export {};
|
|
@@ -160,7 +160,7 @@ export function useAiStream(options) {
|
|
|
160
160
|
for await (const chunk of response) {
|
|
161
161
|
if (abortController.signal.aborted) break;
|
|
162
162
|
const parsed = parser(chunk);
|
|
163
|
-
if (parsed) pushText(parsed);
|
|
163
|
+
if (parsed !== null) pushText(parsed);
|
|
164
164
|
}
|
|
165
165
|
} else if (response instanceof Response && response.body) {
|
|
166
166
|
const reader = response.body.getReader();
|
|
@@ -174,7 +174,7 @@ export function useAiStream(options) {
|
|
|
174
174
|
if (done) break;
|
|
175
175
|
const chunkStr = decoder.decode(value, { stream: true });
|
|
176
176
|
const parsed = parser(chunkStr);
|
|
177
|
-
if (parsed) pushText(parsed);
|
|
177
|
+
if (parsed !== null) pushText(parsed);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
if (!abortController.signal.aborted) {
|
|
@@ -208,3 +208,6 @@ export function useAiStream(options) {
|
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
+
export const __test__ = {
|
|
212
|
+
TypewriterThrottle
|
|
213
|
+
};
|
|
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.updateDayjsMonths = exports.setDayjsLocaleSync = exports.setDayjsLocale = exports.getDayjsLocale = void 0;
|
|
7
7
|
var _dayjs = _interopRequireDefault(require("../dayjs.cjs"));
|
|
8
|
-
require("dayjs/locale/en");
|
|
9
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
const dayjsLocales = import.meta.glob(["../../../../node_modules/dayjs/locale/*.js"
|
|
9
|
+
const dayjsLocales = import.meta.glob(["../../../../node_modules/dayjs/locale/*.js"], {
|
|
11
10
|
eager: false
|
|
12
11
|
});
|
|
13
12
|
const loadedLocales = /* @__PURE__ */new Set(["en"]);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import dayjs from "../dayjs.mjs";
|
|
2
|
-
import "dayjs/locale/en";
|
|
3
2
|
const dayjsLocales = import.meta.glob(
|
|
4
|
-
["../../../../node_modules/dayjs/locale/*.js"
|
|
3
|
+
["../../../../node_modules/dayjs/locale/*.js"],
|
|
5
4
|
{ eager: false }
|
|
6
5
|
);
|
|
7
6
|
const loadedLocales = /* @__PURE__ */ new Set(["en"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yh-ui/hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "YH-UI composition hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dist"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@yh-ui/locale": "^1.0.
|
|
27
|
-
"@yh-ui/utils": "^1.0.
|
|
26
|
+
"@yh-ui/locale": "^1.0.5",
|
|
27
|
+
"@yh-ui/utils": "^1.0.5",
|
|
28
28
|
"dayjs": "^1.11.19"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|