@mongoosejs/studio 0.0.73 → 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.
@@ -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
+ });
@@ -12,43 +12,28 @@ const app = Vue.createApp({
12
12
  template: '<app-component />'
13
13
  });
14
14
 
15
- require('./async-button/async-button')(app);
16
- require('./clone-document/clone-document')(app);
17
- require('./create-dashboard/create-dashboard')(app);
18
- require('./create-document/create-document')(app);
19
- require('./dashboards/dashboards')(app);
20
- require('./dashboard/dashboard')(app);
21
- require('./dashboard-result/dashboard-result')(app);
22
- require('./dashboard-result/dashboard-chart/dashboard-chart')(app);
23
- require('./dashboard-result/dashboard-document/dashboard-document')(app);
24
- require('./dashboard-result/dashboard-primitive/dashboard-primitive')(app);
25
- require('./dashboard-result/dashboard-text/dashboard-text')(app);
26
- require('./dashboard/edit-dashboard/edit-dashboard')(app)
27
- require('./detail-array/detail-array')(app);
28
- require('./detail-default/detail-default')(app);
29
- require('./document/document')(app);
30
- require('./document/confirm-changes/confirm-changes')(app);
31
- require('./document/confirm-delete/confirm-delete')(app);
32
- require('./document-details/document-details')(app);
33
- require('./document-details/document-property/document-property')(app);
34
- require('./edit-array/edit-array')(app);
35
- require('./edit-default/edit-default')(app);
36
- require('./edit-number/edit-number')(app);
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>
@@ -6,5 +6,6 @@ const template = require('./modal.html');
6
6
  appendCSS(require('./modal.css'));
7
7
 
8
8
  module.exports = app => app.component('modal', {
9
- template
10
- });
9
+ template,
10
+ props: ['containerClass']
11
+ });
@@ -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
  },
@@ -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.73",
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",