@mongoosejs/studio 0.3.6 → 0.3.8
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/Dashboard/getDashboard.js +2 -1
- package/backend/actions/Task/getTasksOverTime.js +66 -0
- package/backend/actions/Task/index.js +1 -0
- package/backend/integrations/callLLM.js +2 -1
- package/backend/integrations/streamLLM.js +2 -1
- package/backend/netlify.js +2 -1
- package/backend/next.js +2 -1
- package/constants.js +7 -0
- package/express.js +2 -1
- package/frontend/index.js +2 -1
- package/frontend/public/app.js +541 -88
- package/frontend/public/tw.css +14 -12
- package/frontend/src/api.js +6 -0
- 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/tasks/tasks.html +34 -20
- package/frontend/src/tasks/tasks.js +158 -5
- package/local.js +2 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const Archetype = require('archetype');
|
|
4
4
|
const vm = require('vm');
|
|
5
5
|
const authorize = require('../../authorize');
|
|
6
|
+
const { defaultMothershipURL } = require('../../../constants');
|
|
6
7
|
|
|
7
8
|
const GetDashboardParams = new Archetype({
|
|
8
9
|
dashboardId: {
|
|
@@ -26,7 +27,7 @@ const GetDashboardParams = new Archetype({
|
|
|
26
27
|
module.exports = ({ db, options }) => async function getDashboard(params) {
|
|
27
28
|
const { $workspaceId, authorization, dashboardId, evaluate, roles } = new GetDashboardParams(params);
|
|
28
29
|
const Dashboard = db.model('__Studio_Dashboard');
|
|
29
|
-
const mothershipUrl = options?._mothershipUrl ??
|
|
30
|
+
const mothershipUrl = options?._mothershipUrl ?? defaultMothershipURL;
|
|
30
31
|
|
|
31
32
|
await authorize('Dashboard.getDashboard', roles);
|
|
32
33
|
|
|
@@ -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');
|
|
@@ -4,6 +4,7 @@ const { createAnthropic } = require('@ai-sdk/anthropic');
|
|
|
4
4
|
const { createGoogleGenerativeAI } = require('@ai-sdk/google');
|
|
5
5
|
const { createOpenAI } = require('@ai-sdk/openai');
|
|
6
6
|
const { generateText } = require('ai');
|
|
7
|
+
const { defaultMothershipURL } = require('../../constants');
|
|
7
8
|
|
|
8
9
|
module.exports = async function callLLM(messages, system, options) {
|
|
9
10
|
let provider = null;
|
|
@@ -50,7 +51,7 @@ module.exports = async function callLLM(messages, system, options) {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
const headers = { 'Content-Type': 'application/json' };
|
|
53
|
-
const response = await fetch(
|
|
54
|
+
const response = await fetch(`${defaultMothershipURL}/getChatCompletion`, {
|
|
54
55
|
method: 'POST',
|
|
55
56
|
headers,
|
|
56
57
|
body: JSON.stringify({
|
|
@@ -4,6 +4,7 @@ const { createAnthropic } = require('@ai-sdk/anthropic');
|
|
|
4
4
|
const { createGoogleGenerativeAI } = require('@ai-sdk/google');
|
|
5
5
|
const { createOpenAI } = require('@ai-sdk/openai');
|
|
6
6
|
const { streamText } = require('ai');
|
|
7
|
+
const { defaultMothershipURL } = require('../../constants');
|
|
7
8
|
|
|
8
9
|
module.exports = async function* streamLLM(messages, system, options) {
|
|
9
10
|
let provider = null;
|
|
@@ -62,7 +63,7 @@ module.exports = async function* streamLLM(messages, system, options) {
|
|
|
62
63
|
|
|
63
64
|
// If not using OpenAI, Anthropic, or Google Gemini, fallback to Mongoose (no streaming)
|
|
64
65
|
const headers = { 'Content-Type': 'application/json' };
|
|
65
|
-
const response = await fetch(
|
|
66
|
+
const response = await fetch(`${defaultMothershipURL}/getChatCompletion`, {
|
|
66
67
|
method: 'POST',
|
|
67
68
|
headers,
|
|
68
69
|
body: JSON.stringify({
|
package/backend/netlify.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const Backend = require('./');
|
|
4
4
|
const { toNetlifyFunction } = require('extrovert');
|
|
5
|
+
const { defaultMothershipURL } = require('../constants');
|
|
5
6
|
|
|
6
7
|
module.exports = function netlify(conn, options) {
|
|
7
8
|
const backend = Backend(conn, options?.studioConnection, options);
|
|
8
|
-
const mothershipUrl = options?._mothershipUrl ||
|
|
9
|
+
const mothershipUrl = options?._mothershipUrl || defaultMothershipURL;
|
|
9
10
|
|
|
10
11
|
let workspace = null;
|
|
11
12
|
|
package/backend/next.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Backend = require('./');
|
|
4
|
+
const { defaultMothershipURL } = require('../constants');
|
|
4
5
|
|
|
5
6
|
module.exports = function next(conn, options) {
|
|
6
7
|
const backend = Backend(conn, options?.studioConnection, options);
|
|
7
8
|
|
|
8
|
-
const mothershipUrl = options?._mothershipUrl ||
|
|
9
|
+
const mothershipUrl = options?._mothershipUrl || defaultMothershipURL;
|
|
9
10
|
let workspace = null;
|
|
10
11
|
|
|
11
12
|
return async function wrappedNextJSFunction(req, res) {
|
package/constants.js
ADDED
package/express.js
CHANGED
|
@@ -4,12 +4,13 @@ const Backend = require('./backend');
|
|
|
4
4
|
const express = require('express');
|
|
5
5
|
const frontend = require('./frontend');
|
|
6
6
|
const { toRoute, objectRouter } = require('extrovert');
|
|
7
|
+
const { defaultMothershipURL } = require('./constants');
|
|
7
8
|
|
|
8
9
|
module.exports = async function mongooseStudioExpressApp(apiUrl, conn, options) {
|
|
9
10
|
const router = express.Router();
|
|
10
11
|
options = options ? { changeStream: true, ...options } : { changeStream: true };
|
|
11
12
|
|
|
12
|
-
const mothershipUrl = options._mothershipUrl ||
|
|
13
|
+
const mothershipUrl = options._mothershipUrl || defaultMothershipURL;
|
|
13
14
|
let workspace = null;
|
|
14
15
|
if (options?.apiKey) {
|
|
15
16
|
({ workspace } = await fetch(`${mothershipUrl}/getWorkspace`, {
|
package/frontend/index.js
CHANGED
|
@@ -4,10 +4,11 @@ const { execSync, exec } = require('child_process');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const webpack = require('webpack');
|
|
7
|
+
const { defaultMothershipURL } = require('../constants');
|
|
7
8
|
const webpackConfig = require('./webpack.config');
|
|
8
9
|
|
|
9
10
|
module.exports = async function frontend(apiUrl, isLambda, options, workspace) {
|
|
10
|
-
const mothershipUrl = options?._mothershipUrl ||
|
|
11
|
+
const mothershipUrl = options?._mothershipUrl || defaultMothershipURL;
|
|
11
12
|
|
|
12
13
|
if (workspace == null && options?.apiKey) {
|
|
13
14
|
({ workspace } = await fetch(`${mothershipUrl}/getWorkspace`, {
|