@amaster.ai/components-templates 1.3.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/README.md +193 -0
- package/bin/amaster.js +2 -0
- package/components/ai-assistant/example.md +34 -0
- package/components/ai-assistant/package.json +34 -0
- package/components/ai-assistant/template/ai-assistant.tsx +88 -0
- package/components/ai-assistant/template/components/Markdown.tsx +70 -0
- package/components/ai-assistant/template/components/chat-assistant-message.tsx +190 -0
- package/components/ai-assistant/template/components/chat-banner.tsx +17 -0
- package/components/ai-assistant/template/components/chat-display-mode-switcher.tsx +70 -0
- package/components/ai-assistant/template/components/chat-floating-button.tsx +56 -0
- package/components/ai-assistant/template/components/chat-floating-card.tsx +43 -0
- package/components/ai-assistant/template/components/chat-header.tsx +66 -0
- package/components/ai-assistant/template/components/chat-input.tsx +143 -0
- package/components/ai-assistant/template/components/chat-messages.tsx +81 -0
- package/components/ai-assistant/template/components/chat-recommends.tsx +36 -0
- package/components/ai-assistant/template/components/chat-speech-button.tsx +43 -0
- package/components/ai-assistant/template/components/chat-user-message.tsx +26 -0
- package/components/ai-assistant/template/components/ui-renderer-lazy.tsx +307 -0
- package/components/ai-assistant/template/components/ui-renderer.tsx +34 -0
- package/components/ai-assistant/template/components/voice-input.tsx +43 -0
- package/components/ai-assistant/template/hooks/useAssistantStore.tsx +36 -0
- package/components/ai-assistant/template/hooks/useAutoScroll.ts +90 -0
- package/components/ai-assistant/template/hooks/useConversationProcessor.ts +649 -0
- package/components/ai-assistant/template/hooks/useDisplayMode.tsx +74 -0
- package/components/ai-assistant/template/hooks/useDraggable.ts +125 -0
- package/components/ai-assistant/template/hooks/usePosition.ts +206 -0
- package/components/ai-assistant/template/hooks/useSpeak.ts +50 -0
- package/components/ai-assistant/template/hooks/useVoiceInput.ts +172 -0
- package/components/ai-assistant/template/i18n.ts +114 -0
- package/components/ai-assistant/template/index.ts +6 -0
- package/components/ai-assistant/template/inline-ai-assistant.tsx +78 -0
- package/components/ai-assistant/template/mock/mock-data.ts +643 -0
- package/components/ai-assistant/template/types.ts +72 -0
- package/index.js +13 -0
- package/package.json +67 -0
- package/packages/cli/dist/index.d.ts +3 -0
- package/packages/cli/dist/index.d.ts.map +1 -0
- package/packages/cli/dist/index.js +335 -0
- package/packages/cli/dist/index.js.map +1 -0
- package/packages/cli/package.json +35 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const getPreferredLanguage = (): "zh" | "en" => {
|
|
2
|
+
if (typeof navigator === "undefined") return "zh";
|
|
3
|
+
const lang =
|
|
4
|
+
navigator.language ||
|
|
5
|
+
(navigator as { userLanguage?: string }).userLanguage ||
|
|
6
|
+
"zh";
|
|
7
|
+
return lang.startsWith("zh") ? "zh" : "en";
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const i18nText = {
|
|
11
|
+
zh: {
|
|
12
|
+
greeting: "你好!我是你的AI助手,有什么可以帮你的吗?",
|
|
13
|
+
processing: "正在处理中...",
|
|
14
|
+
online: "在线",
|
|
15
|
+
thinking: "思考中",
|
|
16
|
+
thought: "思考过程",
|
|
17
|
+
resetConversation: "开始新对话",
|
|
18
|
+
fullscreen: "全屏显示",
|
|
19
|
+
exitFullscreen: "退出全屏",
|
|
20
|
+
typePlaceholder: "输入消息...",
|
|
21
|
+
footerAiWarning: "以上内容均由AI生成,仅供参考",
|
|
22
|
+
conversationReset: "对话已重置",
|
|
23
|
+
conversationCancelled: "对话已取消",
|
|
24
|
+
sendFailed: "发送消息失败,请重试",
|
|
25
|
+
errorMessage: "抱歉,我遇到了一些问题,请稍后再试。",
|
|
26
|
+
unknownTool: "未知工具",
|
|
27
|
+
displayMode: {
|
|
28
|
+
floating: "悬浮模式",
|
|
29
|
+
sideLeft: "侧边模式(左)",
|
|
30
|
+
sideRight: "侧边模式(右)",
|
|
31
|
+
fullscreen: "全屏模式",
|
|
32
|
+
},
|
|
33
|
+
voiceInput: "语音输入",
|
|
34
|
+
stopVoiceInput: "停止录音",
|
|
35
|
+
voiceInputStatus: {
|
|
36
|
+
idle: "点击开始语音输入",
|
|
37
|
+
starting: "启动中",
|
|
38
|
+
ready: "请说话",
|
|
39
|
+
speaking: "检测到语音",
|
|
40
|
+
recording: "识别中",
|
|
41
|
+
stopping: "停止中",
|
|
42
|
+
ended: "已结束",
|
|
43
|
+
error: "发生错误",
|
|
44
|
+
closed: "已关闭",
|
|
45
|
+
},
|
|
46
|
+
voiceInputError: {
|
|
47
|
+
microphoneAccessDenied: "麦克风访问被拒绝,请允许访问麦克风",
|
|
48
|
+
noSpeechDetected: "未检测到语音,请确保麦克风正常工作",
|
|
49
|
+
networkError: "网络错误,请检查你的网络连接",
|
|
50
|
+
permissionDenied: "权限被拒绝,请检查浏览器权限设置",
|
|
51
|
+
unknownError: "发生未知错误,请稍后再试",
|
|
52
|
+
},
|
|
53
|
+
defaultRecommendedQuestions: [
|
|
54
|
+
"你都有哪些技能?",
|
|
55
|
+
"今天北京天气如何?",
|
|
56
|
+
"如何使用这个系统?",
|
|
57
|
+
] as string[],
|
|
58
|
+
},
|
|
59
|
+
en: {
|
|
60
|
+
greeting: "Hello! I'm your AI assistant. How can I help you today?",
|
|
61
|
+
processing: "Processing...",
|
|
62
|
+
online: "Online",
|
|
63
|
+
thinking: "Thinking",
|
|
64
|
+
thought: "Thought process",
|
|
65
|
+
resetConversation: "Start a new chat",
|
|
66
|
+
fullscreen: "Fullscreen",
|
|
67
|
+
exitFullscreen: "Exit fullscreen",
|
|
68
|
+
typePlaceholder: "Type a message...",
|
|
69
|
+
footerAiWarning:
|
|
70
|
+
"The above content is generated by AI and is for reference only",
|
|
71
|
+
conversationReset: "Conversation reset",
|
|
72
|
+
conversationCancelled: "Conversation cancelled",
|
|
73
|
+
sendFailed: "Failed to send message, please try again",
|
|
74
|
+
errorMessage: "Sorry, I encountered an issue. Please try again later.",
|
|
75
|
+
unknownTool: "Unknown tool",
|
|
76
|
+
displayMode: {
|
|
77
|
+
floating: "Floating mode",
|
|
78
|
+
sideLeft: "Side mode (left)",
|
|
79
|
+
sideRight: "Side mode (right)",
|
|
80
|
+
fullscreen: "Fullscreen mode",
|
|
81
|
+
},
|
|
82
|
+
voiceInput: "Voice input",
|
|
83
|
+
stopVoiceInput: "Stop recording",
|
|
84
|
+
voiceInputStatus: {
|
|
85
|
+
idle: "Click to start voice input",
|
|
86
|
+
starting: "Starting",
|
|
87
|
+
ready: "Please speak",
|
|
88
|
+
speaking: "Voice detected",
|
|
89
|
+
recording: "Recognizing",
|
|
90
|
+
stopping: "Stopping",
|
|
91
|
+
ended: "Ended",
|
|
92
|
+
error: "Error",
|
|
93
|
+
closed: "Connection closed",
|
|
94
|
+
},
|
|
95
|
+
voiceInputError: {
|
|
96
|
+
microphoneAccessDenied:
|
|
97
|
+
"Microphone access denied, please allow access to the microphone",
|
|
98
|
+
noSpeechDetected:
|
|
99
|
+
"No speech detected, please make sure your microphone is working",
|
|
100
|
+
networkError: "Network error, please check your internet connection",
|
|
101
|
+
permissionDenied:
|
|
102
|
+
"Permission denied, please check your browser permission settings",
|
|
103
|
+
unknownError: "An unknown error occurred, please try again later",
|
|
104
|
+
},
|
|
105
|
+
defaultRecommendedQuestions: [
|
|
106
|
+
"What can you do?",
|
|
107
|
+
"What's the weather like in Beijing today?",
|
|
108
|
+
"How do I use this system?",
|
|
109
|
+
] as string[],
|
|
110
|
+
},
|
|
111
|
+
} as const;
|
|
112
|
+
|
|
113
|
+
export const getText = () => i18nText[getPreferredLanguage()];
|
|
114
|
+
export { getPreferredLanguage };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import { getText } from "./i18n";
|
|
3
|
+
import type { InlineAIAssistantProps } from "./types";
|
|
4
|
+
import ChatMessages from "./components/chat-messages";
|
|
5
|
+
import ChatInput from "./components/chat-input";
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
import { useAssistantStore } from "./hooks/useAssistantStore";
|
|
8
|
+
import ChatBanner from "./components/chat-banner";
|
|
9
|
+
import ChatRecommends from "./components/chat-recommends";
|
|
10
|
+
import { useEffect } from "react";
|
|
11
|
+
|
|
12
|
+
const InlineAIAssistant: React.FC<InlineAIAssistantProps> = ({
|
|
13
|
+
showBanner = true,
|
|
14
|
+
bannerText,
|
|
15
|
+
className,
|
|
16
|
+
style,
|
|
17
|
+
greeting,
|
|
18
|
+
}) => {
|
|
19
|
+
const {
|
|
20
|
+
conversations,
|
|
21
|
+
isLoading,
|
|
22
|
+
inputValue,
|
|
23
|
+
setInputValue,
|
|
24
|
+
scrollAreaRef,
|
|
25
|
+
messagesEndRef,
|
|
26
|
+
sendMessage,
|
|
27
|
+
reset,
|
|
28
|
+
} = useAssistantStore();
|
|
29
|
+
|
|
30
|
+
const handleReset = () => {
|
|
31
|
+
reset(greeting);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
conversations.length === 0 && reset(greeting);
|
|
36
|
+
}, [conversations.length, greeting]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div
|
|
40
|
+
className={cn(
|
|
41
|
+
"w-full h-full max-h-screen relative flex flex-col justify-center overflow-hidden max-w-[1000px] mx-auto",
|
|
42
|
+
className,
|
|
43
|
+
)}
|
|
44
|
+
style={style}
|
|
45
|
+
>
|
|
46
|
+
{showBanner && (
|
|
47
|
+
<ChatBanner
|
|
48
|
+
text={bannerText}
|
|
49
|
+
hidden={conversations.length > 0}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
<ChatMessages
|
|
53
|
+
conversations={conversations}
|
|
54
|
+
isLoading={isLoading}
|
|
55
|
+
scrollAreaRef={scrollAreaRef}
|
|
56
|
+
messagesEndRef={messagesEndRef}
|
|
57
|
+
className={showBanner ? "" : "flex-1"}
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
<ChatRecommends
|
|
61
|
+
hidden={!conversations.length || isLoading}
|
|
62
|
+
onSend={sendMessage}
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
<ChatInput
|
|
66
|
+
conversations={conversations}
|
|
67
|
+
isLoading={isLoading}
|
|
68
|
+
inputValue={inputValue}
|
|
69
|
+
onInputChange={setInputValue}
|
|
70
|
+
onSendMessage={sendMessage}
|
|
71
|
+
onReset={handleReset}
|
|
72
|
+
/>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { InlineAIAssistant };
|
|
78
|
+
export default InlineAIAssistant;
|