@mongoosejs/studio 0.3.5 → 0.3.7
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/ChatThread/createChatMessage.js +12 -2
- package/backend/actions/ChatThread/streamChatMessage.js +12 -2
- package/backend/actions/Model/createChatMessage.js +12 -2
- package/backend/actions/Model/streamChatMessage.js +13 -2
- package/backend/actions/Task/getTasksOverTime.js +66 -0
- package/backend/actions/Task/index.js +1 -0
- package/frontend/public/app.js +809 -110
- package/frontend/public/tw.css +19 -16
- package/frontend/src/api.js +6 -0
- package/frontend/src/chat/chat.html +19 -12
- package/frontend/src/chat/chat.js +9 -3
- package/frontend/src/create-document/create-document.js +3 -1
- package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.html +2 -2
- package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.js +13 -1
- package/frontend/src/dashboard-result/dashboard-result.html +1 -1
- package/frontend/src/dashboard-result/dashboard-table/dashboard-table.html +21 -1
- package/frontend/src/dashboard-result/dashboard-table/dashboard-table.js +52 -0
- package/frontend/src/detail-date/detail-date.html +1 -0
- package/frontend/src/detail-date/detail-date.js +123 -0
- package/frontend/src/document-details/date-view-mode-picker/date-view-mode-picker.html +26 -0
- package/frontend/src/document-details/date-view-mode-picker/date-view-mode-picker.js +41 -0
- package/frontend/src/document-details/document-property/document-property.html +13 -5
- package/frontend/src/document-details/document-property/document-property.js +14 -1
- package/frontend/src/getCurrentDateTimeContext.js +17 -0
- package/frontend/src/list-json/list-json.js +0 -7
- package/frontend/src/modal/modal.js +25 -1
- package/frontend/src/models/document-search/document-search.js +3 -0
- package/frontend/src/models/models.html +25 -5
- package/frontend/src/models/models.js +1 -1
- package/frontend/src/navbar/navbar.html +6 -1
- package/frontend/src/navbar/navbar.js +1 -6
- package/frontend/src/pro-upgrade-modal/pro-upgrade-modal.html +38 -0
- package/frontend/src/pro-upgrade-modal/pro-upgrade-modal.js +23 -0
- package/frontend/src/tasks/tasks.html +34 -20
- package/frontend/src/tasks/tasks.js +158 -5
- package/local.js +2 -1
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Archetype = require('archetype');
|
|
4
|
+
const assert = require('assert');
|
|
4
5
|
const authorize = require('../../authorize');
|
|
5
6
|
const callLLM = require('../../integrations/callLLM');
|
|
6
7
|
const getModelDescriptions = require('../../helpers/getModelDescriptions');
|
|
@@ -16,13 +17,17 @@ const CreateChatMessageParams = new Archetype({
|
|
|
16
17
|
content: {
|
|
17
18
|
$type: 'string'
|
|
18
19
|
},
|
|
20
|
+
currentDateTime: {
|
|
21
|
+
$type: 'string',
|
|
22
|
+
$validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
|
|
23
|
+
},
|
|
19
24
|
roles: {
|
|
20
25
|
$type: ['string']
|
|
21
26
|
}
|
|
22
27
|
}).compile('CreateChatMessageParams');
|
|
23
28
|
|
|
24
29
|
module.exports = ({ db, studioConnection, options }) => async function createChatMessage(params) {
|
|
25
|
-
const { chatThreadId, initiatedById, content, script, roles } = new CreateChatMessageParams(params);
|
|
30
|
+
const { chatThreadId, initiatedById, content, currentDateTime, script, roles } = new CreateChatMessageParams(params);
|
|
26
31
|
const ChatThread = studioConnection.model('__Studio_ChatThread');
|
|
27
32
|
const ChatMessage = studioConnection.model('__Studio_ChatMessage');
|
|
28
33
|
|
|
@@ -75,7 +80,12 @@ module.exports = ({ db, studioConnection, options }) => async function createCha
|
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
const modelDescriptions = getModelDescriptions(db);
|
|
78
|
-
const system =
|
|
83
|
+
const system = [
|
|
84
|
+
systemPrompt,
|
|
85
|
+
currentDateTime ? `Current date: ${currentDateTime}` : null,
|
|
86
|
+
modelDescriptions,
|
|
87
|
+
options?.context
|
|
88
|
+
].filter(Boolean).join('\n\n');
|
|
79
89
|
|
|
80
90
|
// Create the chat message and get LLM response in parallel
|
|
81
91
|
const chatMessages = await Promise.all([
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Archetype = require('archetype');
|
|
4
|
+
const assert = require('assert');
|
|
4
5
|
const authorize = require('../../authorize');
|
|
5
6
|
const callLLM = require('../../integrations/callLLM');
|
|
6
7
|
const streamLLM = require('../../integrations/streamLLM');
|
|
@@ -17,13 +18,17 @@ const CreateChatMessageParams = new Archetype({
|
|
|
17
18
|
content: {
|
|
18
19
|
$type: 'string'
|
|
19
20
|
},
|
|
21
|
+
currentDateTime: {
|
|
22
|
+
$type: 'string',
|
|
23
|
+
$validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
|
|
24
|
+
},
|
|
20
25
|
roles: {
|
|
21
26
|
$type: ['string']
|
|
22
27
|
}
|
|
23
28
|
}).compile('CreateChatMessageParams');
|
|
24
29
|
|
|
25
30
|
module.exports = ({ db, studioConnection, options }) => async function* createChatMessage(params) {
|
|
26
|
-
const { chatThreadId, initiatedById, content, script, roles } = new CreateChatMessageParams(params);
|
|
31
|
+
const { chatThreadId, initiatedById, content, currentDateTime, script, roles } = new CreateChatMessageParams(params);
|
|
27
32
|
const ChatThread = studioConnection.model('__Studio_ChatThread');
|
|
28
33
|
const ChatMessage = studioConnection.model('__Studio_ChatMessage');
|
|
29
34
|
|
|
@@ -76,7 +81,12 @@ module.exports = ({ db, studioConnection, options }) => async function* createCh
|
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
const modelDescriptions = getModelDescriptions(db);
|
|
79
|
-
const system =
|
|
84
|
+
const system = [
|
|
85
|
+
systemPrompt,
|
|
86
|
+
currentDateTime ? `Current date: ${currentDateTime}` : null,
|
|
87
|
+
modelDescriptions,
|
|
88
|
+
options?.context
|
|
89
|
+
].filter(Boolean).join('\n\n');
|
|
80
90
|
|
|
81
91
|
const userChatMessage = await ChatMessage.create({
|
|
82
92
|
chatThreadId,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Archetype = require('archetype');
|
|
4
|
+
const assert = require('assert');
|
|
4
5
|
const authorize = require('../../authorize');
|
|
5
6
|
const callLLM = require('../../integrations/callLLM');
|
|
6
7
|
const getModelDescriptions = require('../../helpers/getModelDescriptions');
|
|
@@ -17,13 +18,17 @@ const CreateChatMessageParams = new Archetype({
|
|
|
17
18
|
documentData: {
|
|
18
19
|
$type: 'string'
|
|
19
20
|
},
|
|
21
|
+
currentDateTime: {
|
|
22
|
+
$type: 'string',
|
|
23
|
+
$validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
|
|
24
|
+
},
|
|
20
25
|
roles: {
|
|
21
26
|
$type: ['string']
|
|
22
27
|
}
|
|
23
28
|
}).compile('CreateChatMessageParams');
|
|
24
29
|
|
|
25
30
|
module.exports = ({ db, options }) => async function createChatMessage(params) {
|
|
26
|
-
const { model, content, documentData, roles } = new CreateChatMessageParams(params);
|
|
31
|
+
const { model, content, documentData, currentDateTime, roles } = new CreateChatMessageParams(params);
|
|
27
32
|
|
|
28
33
|
await authorize('Model.createChatMessage', roles);
|
|
29
34
|
|
|
@@ -37,7 +42,12 @@ module.exports = ({ db, options }) => async function createChatMessage(params) {
|
|
|
37
42
|
modelDescriptions,
|
|
38
43
|
'Current draft document:\n' + (documentData || '')
|
|
39
44
|
].join('\n\n');
|
|
40
|
-
const system =
|
|
45
|
+
const system = [
|
|
46
|
+
systemPrompt,
|
|
47
|
+
currentDateTime ? `Current date: ${currentDateTime}` : null,
|
|
48
|
+
context,
|
|
49
|
+
options?.context
|
|
50
|
+
].filter(Boolean).join('\n\n');
|
|
41
51
|
|
|
42
52
|
const llmMessages = [{ role: 'user', content: [{ type: 'text', text: content }] }];
|
|
43
53
|
const res = await callLLM(llmMessages, system, options);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Archetype = require('archetype');
|
|
4
|
+
const assert = require('assert');
|
|
4
5
|
const authorize = require('../../authorize');
|
|
5
6
|
const streamLLM = require('../../integrations/streamLLM');
|
|
6
7
|
const getModelDescriptions = require('../../helpers/getModelDescriptions');
|
|
@@ -17,13 +18,18 @@ const StreamChatMessageParams = new Archetype({
|
|
|
17
18
|
documentData: {
|
|
18
19
|
$type: 'string'
|
|
19
20
|
},
|
|
21
|
+
currentDateTime: {
|
|
22
|
+
$type: 'string',
|
|
23
|
+
$transform: v => v == null ? null : decodeURIComponent(v),
|
|
24
|
+
$validate: v => assert.ok(v == null || v.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/))
|
|
25
|
+
},
|
|
20
26
|
roles: {
|
|
21
27
|
$type: ['string']
|
|
22
28
|
}
|
|
23
29
|
}).compile('StreamChatMessageParams');
|
|
24
30
|
|
|
25
31
|
module.exports = ({ db, options }) => async function* streamChatMessage(params) {
|
|
26
|
-
const { model, content, documentData, roles } = new StreamChatMessageParams(params);
|
|
32
|
+
const { model, content, documentData, currentDateTime, roles } = new StreamChatMessageParams(params);
|
|
27
33
|
|
|
28
34
|
await authorize('Model.streamChatMessage', roles);
|
|
29
35
|
|
|
@@ -37,7 +43,12 @@ module.exports = ({ db, options }) => async function* streamChatMessage(params)
|
|
|
37
43
|
modelDescriptions,
|
|
38
44
|
'Current draft document:\n' + (documentData || '')
|
|
39
45
|
].join('\n\n');
|
|
40
|
-
const system =
|
|
46
|
+
const system = [
|
|
47
|
+
systemPrompt,
|
|
48
|
+
currentDateTime ? `Current date: ${currentDateTime}` : null,
|
|
49
|
+
context,
|
|
50
|
+
options?.context
|
|
51
|
+
].filter(Boolean).join('\n\n');
|
|
41
52
|
|
|
42
53
|
const llmMessages = [{ role: 'user', content: [{ type: 'text', text: content }] }];
|
|
43
54
|
const textStream = streamLLM(llmMessages, system, options);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Archetype = require('archetype');
|
|
4
|
+
|
|
5
|
+
const GetTasksOverTimeParams = new Archetype({
|
|
6
|
+
start: { $type: Date },
|
|
7
|
+
end: { $type: Date },
|
|
8
|
+
bucketSizeMs: { $type: 'number' }
|
|
9
|
+
}).compile('GetTasksOverTimeParams');
|
|
10
|
+
|
|
11
|
+
const TRACKED_STATUSES = ['succeeded', 'failed', 'cancelled'];
|
|
12
|
+
|
|
13
|
+
module.exports = ({ db }) => async function getTasksOverTime(params) {
|
|
14
|
+
params = new GetTasksOverTimeParams(params);
|
|
15
|
+
const { Task } = db.models;
|
|
16
|
+
const { start, end, bucketSizeMs } = params;
|
|
17
|
+
|
|
18
|
+
const bucketMs = (bucketSizeMs != null && bucketSizeMs > 0) ? bucketSizeMs : 5 * 60 * 1000;
|
|
19
|
+
|
|
20
|
+
const match = { status: { $in: TRACKED_STATUSES } };
|
|
21
|
+
if (start != null && end != null) {
|
|
22
|
+
match.scheduledAt = { $gte: start, $lt: end };
|
|
23
|
+
} else if (start != null) {
|
|
24
|
+
match.scheduledAt = { $gte: start };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const pipeline = [
|
|
28
|
+
{ $match: match },
|
|
29
|
+
{
|
|
30
|
+
$project: {
|
|
31
|
+
status: 1,
|
|
32
|
+
bucket: {
|
|
33
|
+
$toDate: {
|
|
34
|
+
$multiply: [
|
|
35
|
+
{ $floor: { $divide: [{ $toLong: '$scheduledAt' }, bucketMs] } },
|
|
36
|
+
bucketMs
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
$group: {
|
|
44
|
+
_id: { bucket: '$bucket', status: '$status' },
|
|
45
|
+
count: { $sum: 1 }
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$group: {
|
|
50
|
+
_id: '$_id.bucket',
|
|
51
|
+
counts: { $push: { status: '$_id.status', count: '$count' } }
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{ $sort: { _id: 1 } }
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const results = await Task.aggregate(pipeline);
|
|
58
|
+
|
|
59
|
+
return results.map(r => {
|
|
60
|
+
const bucket = { timestamp: r._id, succeeded: 0, failed: 0, cancelled: 0 };
|
|
61
|
+
for (const { status, count } of r.counts) {
|
|
62
|
+
if (status in bucket) bucket[status] = count;
|
|
63
|
+
}
|
|
64
|
+
return bucket;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -4,5 +4,6 @@ exports.cancelTask = require('./cancelTask');
|
|
|
4
4
|
exports.createTask = require('./createTask');
|
|
5
5
|
exports.getTasks = require('./getTasks');
|
|
6
6
|
exports.getTaskOverview = require('./getTaskOverview');
|
|
7
|
+
exports.getTasksOverTime = require('./getTasksOverTime');
|
|
7
8
|
exports.rescheduleTask = require('./rescheduleTask');
|
|
8
9
|
exports.runTask = require('./runTask');
|