openkbs 0.0.53 → 0.0.55
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 +1490 -202
- package/package.json +2 -1
- package/src/actions.js +345 -1
- package/src/index.js +17 -1
- package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/app/instructions.txt +44 -9
- package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Events/actions.js +43 -42
- package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Events/handler.js +14 -8
- package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Frontend/contentRender.js +95 -12
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/README.md +64 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/app/instructions.txt +160 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/app/settings.json +7 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/actions.js +258 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onRequest.js +13 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onRequest.json +3 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onResponse.js +13 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onResponse.json +3 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Frontend/contentRender.js +170 -0
- package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Frontend/contentRender.json +3 -0
- package/templates/.openkbs/knowledge/metadata.json +1 -1
- package/templates/CLAUDE.md +593 -222
- package/templates/app/instructions.txt +13 -1
- package/templates/app/settings.json +5 -6
- package/templates/src/Events/actions.js +43 -9
- package/templates/src/Events/handler.js +24 -25
- package/templates/webpack.contentRender.config.js +8 -2
- package/version.json +3 -3
- package/MODIFY.md +0 -132
package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Frontend/contentRender.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Box, Tooltip, Chip } from '@mui/material';
|
|
3
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
4
|
+
import ImageIcon from '@mui/icons-material/Image';
|
|
5
|
+
import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
|
|
6
|
+
import LanguageIcon from '@mui/icons-material/Language';
|
|
7
|
+
import EmailIcon from '@mui/icons-material/Email';
|
|
8
|
+
import ScheduleIcon from '@mui/icons-material/Schedule';
|
|
9
|
+
import MemoryIcon from '@mui/icons-material/Memory';
|
|
10
|
+
import PublishIcon from '@mui/icons-material/Publish';
|
|
11
|
+
|
|
12
|
+
// Command patterns to detect
|
|
13
|
+
const COMMAND_PATTERNS = [
|
|
14
|
+
/<createAIImage>[\s\S]*?<\/createAIImage>/,
|
|
15
|
+
/<createAIVideo>[\s\S]*?<\/createAIVideo>/,
|
|
16
|
+
/<continueVideoPolling>[\s\S]*?<\/continueVideoPolling>/,
|
|
17
|
+
/<googleSearch>[\s\S]*?<\/googleSearch>/,
|
|
18
|
+
/<googleImageSearch>[\s\S]*?<\/googleImageSearch>/,
|
|
19
|
+
/<viewImage>[\s\S]*?<\/viewImage>/,
|
|
20
|
+
/<webpageToText>[\s\S]*?<\/webpageToText>/,
|
|
21
|
+
/<sendMail>[\s\S]*?<\/sendMail>/,
|
|
22
|
+
/<scheduleTask>[\s\S]*?<\/scheduleTask>/,
|
|
23
|
+
/<getScheduledTasks\s*\/>/,
|
|
24
|
+
/<setMemory>[\s\S]*?<\/setMemory>/,
|
|
25
|
+
/<deleteItem>[\s\S]*?<\/deleteItem>/,
|
|
26
|
+
/<publishWebPage>[\s\S]*?<\/publishWebPage>/
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// Icon mapping for commands
|
|
30
|
+
const commandIcons = {
|
|
31
|
+
createAIImage: ImageIcon,
|
|
32
|
+
createAIVideo: VideoLibraryIcon,
|
|
33
|
+
continueVideoPolling: VideoLibraryIcon,
|
|
34
|
+
googleSearch: SearchIcon,
|
|
35
|
+
googleImageSearch: SearchIcon,
|
|
36
|
+
viewImage: ImageIcon,
|
|
37
|
+
webpageToText: LanguageIcon,
|
|
38
|
+
sendMail: EmailIcon,
|
|
39
|
+
scheduleTask: ScheduleIcon,
|
|
40
|
+
getScheduledTasks: ScheduleIcon,
|
|
41
|
+
setMemory: MemoryIcon,
|
|
42
|
+
deleteItem: MemoryIcon,
|
|
43
|
+
publishWebPage: PublishIcon
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Parse commands from content
|
|
47
|
+
const parseCommands = (content) => {
|
|
48
|
+
const commands = [];
|
|
49
|
+
const regex = /<(\w+)>([\s\S]*?)<\/\1>|<(\w+)\s*\/>/g;
|
|
50
|
+
let match;
|
|
51
|
+
while ((match = regex.exec(content)) !== null) {
|
|
52
|
+
const name = match[1] || match[3];
|
|
53
|
+
let data = match[2] || '';
|
|
54
|
+
try {
|
|
55
|
+
data = data.trim() ? JSON.parse(data.trim()) : {};
|
|
56
|
+
} catch (e) {
|
|
57
|
+
data = data.trim();
|
|
58
|
+
}
|
|
59
|
+
commands.push({ name, data });
|
|
60
|
+
}
|
|
61
|
+
return commands;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Render command as icon with tooltip
|
|
65
|
+
const CommandIcon = ({ command }) => {
|
|
66
|
+
const Icon = commandIcons[command.name] || SearchIcon;
|
|
67
|
+
return (
|
|
68
|
+
<Tooltip
|
|
69
|
+
title={
|
|
70
|
+
<Box sx={{ p: 1 }}>
|
|
71
|
+
<Box sx={{ fontWeight: 'bold', color: '#4CAF50', mb: 0.5 }}>{command.name}</Box>
|
|
72
|
+
<pre style={{ margin: 0, fontSize: '10px', maxWidth: 300, overflow: 'auto' }}>
|
|
73
|
+
{typeof command.data === 'object' ? JSON.stringify(command.data, null, 2) : command.data}
|
|
74
|
+
</pre>
|
|
75
|
+
</Box>
|
|
76
|
+
}
|
|
77
|
+
arrow
|
|
78
|
+
>
|
|
79
|
+
<Box sx={{
|
|
80
|
+
display: 'inline-flex',
|
|
81
|
+
width: 32, height: 32,
|
|
82
|
+
borderRadius: '50%',
|
|
83
|
+
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
|
84
|
+
border: '2px solid rgba(76, 175, 80, 0.3)',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
justifyContent: 'center',
|
|
87
|
+
mx: 0.5,
|
|
88
|
+
cursor: 'pointer',
|
|
89
|
+
'&:hover': { backgroundColor: 'rgba(76, 175, 80, 0.2)', transform: 'scale(1.1)' },
|
|
90
|
+
transition: 'all 0.2s'
|
|
91
|
+
}}>
|
|
92
|
+
<Icon sx={{ fontSize: 16, color: '#4CAF50' }} />
|
|
93
|
+
</Box>
|
|
94
|
+
</Tooltip>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Image renderer
|
|
99
|
+
const ImageWithDownload = ({ imageUrl }) => (
|
|
100
|
+
<Box sx={{ position: 'relative', display: 'inline-block' }}>
|
|
101
|
+
<img
|
|
102
|
+
src={imageUrl}
|
|
103
|
+
alt="Generated"
|
|
104
|
+
style={{ maxWidth: '100%', borderRadius: 8 }}
|
|
105
|
+
/>
|
|
106
|
+
</Box>
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// do NOT useState() directly in this function, it is not a React component
|
|
110
|
+
const onRenderChatMessage = async (params) => {
|
|
111
|
+
let { content, role } = params.messages[params.msgIndex];
|
|
112
|
+
const { msgIndex, messages } = params;
|
|
113
|
+
|
|
114
|
+
let JSONData;
|
|
115
|
+
try {
|
|
116
|
+
JSONData = JSON.parse(content);
|
|
117
|
+
} catch (e) {}
|
|
118
|
+
|
|
119
|
+
// Hide CONTINUE type system messages
|
|
120
|
+
if (JSONData?.type === 'CONTINUE') {
|
|
121
|
+
return JSON.stringify({ type: 'HIDDEN_MESSAGE' });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Handle CHAT_IMAGE type
|
|
125
|
+
if (JSONData?.type === 'CHAT_IMAGE' && JSONData?.data?.imageUrl) {
|
|
126
|
+
return <ImageWithDownload imageUrl={JSONData.data.imageUrl} />;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Hide system response if previous message had a command
|
|
130
|
+
if (role === 'system' && JSONData &&
|
|
131
|
+
(JSONData._meta_type === 'EVENT_STARTED' || JSONData._meta_type === 'EVENT_FINISHED')) {
|
|
132
|
+
const hasSpecialRendering = JSONData.type === 'CHAT_IMAGE' || JSONData.type === 'CHAT_VIDEO';
|
|
133
|
+
if (!hasSpecialRendering && msgIndex > 0) {
|
|
134
|
+
const prevMessage = messages[msgIndex - 1];
|
|
135
|
+
const prevHasCommand = COMMAND_PATTERNS.some(p => p.test(prevMessage.content));
|
|
136
|
+
if (prevHasCommand) return JSON.stringify({ type: 'HIDDEN_MESSAGE' });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Render commands as icons
|
|
141
|
+
const hasCommand = COMMAND_PATTERNS.some(p => p.test(content));
|
|
142
|
+
if (hasCommand) {
|
|
143
|
+
const commands = parseCommands(content);
|
|
144
|
+
return (
|
|
145
|
+
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
|
|
146
|
+
{commands.map((cmd, i) => <CommandIcon key={i} command={cmd} />)}
|
|
147
|
+
</Box>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return null; // Use default rendering
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const Header = ({ setRenderSettings }) => {
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
setRenderSettings({
|
|
157
|
+
inputLabelsQuickSend: true,
|
|
158
|
+
disableBalanceView: false,
|
|
159
|
+
disableEmojiButton: true,
|
|
160
|
+
disableChatModelsSelect: false,
|
|
161
|
+
backgroundOpacity: 0.02
|
|
162
|
+
});
|
|
163
|
+
}, [setRenderSettings]);
|
|
164
|
+
|
|
165
|
+
return null;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const exports = { onRenderChatMessage, Header };
|
|
169
|
+
window.contentRender = exports;
|
|
170
|
+
export default exports;
|