@mongoosejs/studio 0.0.74 → 0.0.75
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/backend/actions/ChatMessage/executeScript.js +74 -0
- package/backend/actions/ChatMessage/index.js +3 -0
- package/backend/actions/ChatThread/createChatMessage.js +253 -0
- package/backend/actions/ChatThread/createChatThread.js +19 -0
- package/backend/actions/ChatThread/getChatThread.js +36 -0
- package/backend/actions/ChatThread/index.js +6 -0
- package/backend/actions/ChatThread/listChatThreads.js +24 -0
- package/backend/actions/index.js +2 -0
- package/backend/db/chatMessageSchema.js +30 -0
- package/backend/db/chatThreadSchema.js +15 -0
- package/backend/index.js +6 -2
- package/express.js +1 -0
- package/frontend/public/app.js +2902 -196
- package/frontend/public/tw.css +146 -0
- package/frontend/src/api.js +38 -3
- package/frontend/src/async-button/async-button.html +12 -2
- package/frontend/src/chat/chat-message/chat-message.html +16 -0
- package/frontend/src/chat/chat-message/chat-message.js +66 -0
- package/frontend/src/chat/chat-message-script/chat-message-script.html +52 -0
- package/frontend/src/chat/chat-message-script/chat-message-script.js +35 -0
- package/frontend/src/chat/chat.html +69 -0
- package/frontend/src/chat/chat.js +89 -0
- package/frontend/src/index.js +22 -37
- package/frontend/src/modal/modal.html +2 -2
- package/frontend/src/modal/modal.js +3 -2
- package/frontend/src/navbar/navbar.html +4 -0
- package/frontend/src/navbar/navbar.js +3 -0
- package/frontend/src/routes.js +19 -3
- package/package.json +2 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const api = require('../api');
|
|
4
|
+
const template = require('./chat.html');
|
|
5
|
+
|
|
6
|
+
module.exports = app => app.component('chat', {
|
|
7
|
+
template: template,
|
|
8
|
+
props: ['threadId'],
|
|
9
|
+
data: () => ({
|
|
10
|
+
status: 'loading',
|
|
11
|
+
sendingMessage: false,
|
|
12
|
+
newMessage: '',
|
|
13
|
+
chatThreadId: null,
|
|
14
|
+
chatThreads: [],
|
|
15
|
+
chatMessages: []
|
|
16
|
+
}),
|
|
17
|
+
methods: {
|
|
18
|
+
async sendMessage() {
|
|
19
|
+
this.sendingMessage = true;
|
|
20
|
+
try {
|
|
21
|
+
if (!this.chatThreadId) {
|
|
22
|
+
const { chatThread } = await api.ChatThread.createChatThread();
|
|
23
|
+
this.chatThreads.unshift(chatThread);
|
|
24
|
+
this.chatThreadId = chatThread._id;
|
|
25
|
+
this.chatMessages = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.chatMessages.push({
|
|
29
|
+
content: this.newMessage,
|
|
30
|
+
role: 'user'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.$nextTick(() => {
|
|
34
|
+
if (this.$refs.messagesContainer) {
|
|
35
|
+
this.$refs.messagesContainer.scrollTop = this.$refs.messagesContainer.scrollHeight;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const { chatMessages } = await api.ChatThread.createChatMessage({
|
|
40
|
+
chatThreadId: this.chatThreadId,
|
|
41
|
+
content: this.newMessage
|
|
42
|
+
});
|
|
43
|
+
this.chatMessages.push(chatMessages[1]);
|
|
44
|
+
|
|
45
|
+
this.newMessage = '';
|
|
46
|
+
|
|
47
|
+
this.$nextTick(() => {
|
|
48
|
+
if (this.$refs.messagesContainer) {
|
|
49
|
+
this.$refs.messagesContainer.scrollTop = this.$refs.messagesContainer.scrollHeight;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
} finally {
|
|
53
|
+
this.sendingMessage = false;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
selectThread(threadId) {
|
|
57
|
+
this.$router.push('/chat/' + threadId);
|
|
58
|
+
},
|
|
59
|
+
styleForMessage(message) {
|
|
60
|
+
return message.role === 'user' ? 'bg-gray-100' : '';
|
|
61
|
+
},
|
|
62
|
+
async createNewThread() {
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
async mounted() {
|
|
67
|
+
this.chatThreadId = this.threadId;
|
|
68
|
+
const { chatThreads } = await api.ChatThread.listChatThreads();
|
|
69
|
+
this.chatThreads = chatThreads;
|
|
70
|
+
if (this.chatThreadId) {
|
|
71
|
+
const { chatMessages } = await api.ChatThread.getChatThread({ chatThreadId: this.chatThreadId });
|
|
72
|
+
this.chatMessages = chatMessages;
|
|
73
|
+
}
|
|
74
|
+
this.status = 'loaded';
|
|
75
|
+
|
|
76
|
+
if (this.chatThreadId) {
|
|
77
|
+
// Scroll to bottom of messages container after messages are loaded
|
|
78
|
+
this.$nextTick(() => {
|
|
79
|
+
if (this.$refs.messagesContainer) {
|
|
80
|
+
this.$refs.messagesContainer.scrollTop = this.$refs.messagesContainer.scrollHeight;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.$refs.messagesContainer.querySelectorAll('code').forEach(el => {
|
|
84
|
+
Prism.highlightElement(el);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
package/frontend/src/index.js
CHANGED
|
@@ -12,43 +12,28 @@ const app = Vue.createApp({
|
|
|
12
12
|
template: '<app-component />'
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
require(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
require('./edit-date/edit-date')(app);
|
|
38
|
-
require('./edit-subdocument/edit-subdocument')(app);
|
|
39
|
-
require('./export-query-results/export-query-results')(app);
|
|
40
|
-
require('./list-array/list-array')(app);
|
|
41
|
-
require('./list-default/list-default')(app);
|
|
42
|
-
require('./list-json/list-json')(app)
|
|
43
|
-
require('./list-mixed/list-mixed')(app);
|
|
44
|
-
require('./list-string/list-string')(app);
|
|
45
|
-
require('./list-subdocument/list-subdocument')(app);
|
|
46
|
-
require('./modal/modal')(app);
|
|
47
|
-
require('./models/models')(app);
|
|
48
|
-
require('./navbar/navbar')(app);
|
|
49
|
-
require('./splash/splash')(app);
|
|
50
|
-
require('./team/team')(app);
|
|
51
|
-
require('./team/new-invitation/new-invitation')(app);
|
|
15
|
+
// Import all components
|
|
16
|
+
const requireComponents = require.context(
|
|
17
|
+
'.', // Relative path (current directory)
|
|
18
|
+
true // Include subdirectories
|
|
19
|
+
);
|
|
20
|
+
// Object to store the imported modules
|
|
21
|
+
const components = {};
|
|
22
|
+
// Iterate over the matched keys (file paths)
|
|
23
|
+
requireComponents.keys().forEach((filePath) => {
|
|
24
|
+
// Extract directory name and file name from the path
|
|
25
|
+
const pieces = filePath.split('/');
|
|
26
|
+
const directoryName = pieces[pieces.length - 2];
|
|
27
|
+
const fileName = pieces[pieces.length - 1].replace('.js', '');
|
|
28
|
+
|
|
29
|
+
// Check if the file name matches the directory name
|
|
30
|
+
if (directoryName === fileName) {
|
|
31
|
+
components[directoryName] = requireComponents(filePath);
|
|
32
|
+
components[directoryName](app);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
console.log('Loaded components', Object.keys(components).sort());
|
|
52
37
|
|
|
53
38
|
app.component('app-component', {
|
|
54
39
|
template: `
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<transition name="modal">
|
|
2
2
|
<div class="modal-mask">
|
|
3
3
|
<div class="modal-wrapper">
|
|
4
|
-
<div class="modal-container">
|
|
4
|
+
<div class="modal-container" :class="containerClass">
|
|
5
5
|
<div class="modal-body">
|
|
6
6
|
<slot name="body">
|
|
7
7
|
</slot>
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
</div>
|
|
10
10
|
</div>
|
|
11
11
|
</div>
|
|
12
|
-
</transition>
|
|
12
|
+
</transition>
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
href="#/dashboards"
|
|
18
18
|
class="inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium"
|
|
19
19
|
:class="dashboardView ? 'text-gray-900 border-ultramarine-500' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700'">Dashboards</a>
|
|
20
|
+
<a v-if="hasAccess(roles, 'chat')"
|
|
21
|
+
href="#/chat"
|
|
22
|
+
class="inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium"
|
|
23
|
+
:class="chatView ? 'text-gray-900 border-ultramarine-500' : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700'">Chat</a>
|
|
20
24
|
|
|
21
25
|
<div class="h-full flex items-center" v-if="!user && hasAPIKey">
|
|
22
26
|
<button
|
|
@@ -30,6 +30,9 @@ module.exports = app => app.component('navbar', {
|
|
|
30
30
|
documentView() {
|
|
31
31
|
return ['root', 'model', 'document'].includes(this.$route.name);
|
|
32
32
|
},
|
|
33
|
+
chatView() {
|
|
34
|
+
return ['chat index', 'chat'].includes(this.$route.name);
|
|
35
|
+
},
|
|
33
36
|
routeName() {
|
|
34
37
|
return this.$route.name;
|
|
35
38
|
},
|
package/frontend/src/routes.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// Role-based access control configuration
|
|
4
4
|
const roleAccess = {
|
|
5
|
-
owner: ['root', 'model', 'document', 'dashboards', 'dashboard', 'team'],
|
|
6
|
-
admin: ['root', 'model', 'document', 'dashboards', 'dashboard', 'team'],
|
|
7
|
-
member: ['root', 'model', 'document', 'dashboards', 'dashboard'],
|
|
5
|
+
owner: ['root', 'model', 'document', 'dashboards', 'dashboard', 'team', 'chat'],
|
|
6
|
+
admin: ['root', 'model', 'document', 'dashboards', 'dashboard', 'team', 'chat'],
|
|
7
|
+
member: ['root', 'model', 'document', 'dashboards', 'dashboard', 'chat'],
|
|
8
8
|
readonly: ['root', 'model', 'document'],
|
|
9
9
|
dashboards: ['dashboards', 'dashboard']
|
|
10
10
|
};
|
|
@@ -65,6 +65,22 @@ module.exports = {
|
|
|
65
65
|
meta: {
|
|
66
66
|
authorized: true
|
|
67
67
|
}
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
path: '/chat',
|
|
71
|
+
name: 'chat index',
|
|
72
|
+
component: 'chat',
|
|
73
|
+
meta: {
|
|
74
|
+
authorized: true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
path: '/chat/:threadId',
|
|
79
|
+
name: 'chat',
|
|
80
|
+
component: 'chat',
|
|
81
|
+
meta: {
|
|
82
|
+
authorized: true
|
|
83
|
+
}
|
|
68
84
|
}
|
|
69
85
|
],
|
|
70
86
|
roleAccess,
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongoosejs/studio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.75",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"archetype": "0.13.1",
|
|
6
6
|
"csv-stringify": "6.3.0",
|
|
7
7
|
"ejson": "^2.2.3",
|
|
8
8
|
"extrovert": "0.0.26",
|
|
9
|
+
"marked": "15.0.12",
|
|
9
10
|
"node-inspect-extracted": "3.x",
|
|
10
11
|
"tailwindcss": "3.4.0",
|
|
11
12
|
"vanillatoasts": "^1.6.0",
|