Skip to content

Commit 3d920a0

Browse files
committed
Merge branch 'main' into IslandRhythms/task-visualizer
2 parents d32696c + deeda35 commit 3d920a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+933
-247
lines changed

.github/workflows/lint.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
push:
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Setting up the node version
11+
uses: actions/setup-node@v3
12+
with:
13+
node-version: 20.19.0
14+
- name: setup project
15+
run: npm i
16+
- name: run lint
17+
run: |
18+
npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ zevo.js
114114
tv.js
115115
stratos.js
116116
osogolf.js
117+
astra.js

backend/actions/ChatMessage/executeScript.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
45
const mongoose = require('mongoose');
56
const vm = require('vm');
67

@@ -12,13 +13,18 @@ const ExecuteScriptParams = new Archetype({
1213
$type: mongoose.Types.ObjectId
1314
},
1415
script: {
15-
$type: String
16+
$type: 'string'
17+
},
18+
roles: {
19+
$type: ['string']
1620
}
1721
}).compile('ExecuteScriptParams');
1822

19-
module.exports = ({ db }) => async function executeScript(params) {
20-
const { userId, chatMessageId, script } = new ExecuteScriptParams(params);
21-
const ChatMessage = db.model('__Studio_ChatMessage');
23+
module.exports = ({ db, studioConnection }) => async function executeScript(params) {
24+
const { userId, chatMessageId, script, roles } = new ExecuteScriptParams(params);
25+
const ChatMessage = studioConnection.model('__Studio_ChatMessage');
26+
27+
await authorize('ChatMessage.executeScript', roles);
2228

2329
const chatMessage = await ChatMessage.findById(chatMessageId);
2430
if (!chatMessage) {

backend/actions/ChatThread/createChatMessage.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
45
const getModelDescriptions = require('../../helpers/getModelDescriptions');
56
const mongoose = require('mongoose');
67

@@ -17,6 +18,9 @@ const CreateChatMessageParams = new Archetype({
1718
authorization: {
1819
$type: 'string',
1920
$required: true
21+
},
22+
roles: {
23+
$type: ['string']
2024
}
2125
}).compile('CreateChatMessageParams');
2226

@@ -55,10 +59,12 @@ return { numUsers: users.length };
5559
Here is a description of the user's models. Assume these are the only models available in the system unless explicitly instructed otherwise by the user.
5660
`.trim();
5761

58-
module.exports = ({ db }) => async function createChatMessage(params) {
59-
const { chatThreadId, userId, content, script, authorization } = new CreateChatMessageParams(params);
60-
const ChatThread = db.model('__Studio_ChatThread');
61-
const ChatMessage = db.model('__Studio_ChatMessage');
62+
module.exports = ({ db, studioConnection, options }) => async function createChatMessage(params) {
63+
const { chatThreadId, userId, content, script, authorization, roles } = new CreateChatMessageParams(params);
64+
const ChatThread = studioConnection.model('__Studio_ChatThread');
65+
const ChatMessage = studioConnection.model('__Studio_ChatMessage');
66+
67+
await authorize('ChatThread.createChatMessage', roles);
6268

6369
// Check that the user owns the thread
6470
const chatThread = await ChatThread.findOne({ _id: chatThreadId });
@@ -91,6 +97,12 @@ module.exports = ({ db }) => async function createChatMessage(params) {
9197
role: 'system',
9298
content: systemPrompt + getModelDescriptions(db)
9399
});
100+
if (options.context) {
101+
llmMessages.unshift({
102+
role: 'system',
103+
content: options.context
104+
});
105+
}
94106

95107
// Create the chat message and get OpenAI response in parallel
96108
const chatMessages = await Promise.all([
@@ -111,7 +123,7 @@ module.exports = ({ db }) => async function createChatMessage(params) {
111123
})
112124
]);
113125

114-
return { chatMessages };
126+
return { chatMessages, chatThread };
115127
};
116128

117129
async function getChatCompletion(messages, authorization) {

backend/actions/ChatThread/createChatThread.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
45
const mongoose = require('mongoose');
56

67
const CreateChatThreadParams = new Archetype({
78
userId: {
89
$type: mongoose.Types.ObjectId
10+
},
11+
roles: {
12+
$type: ['string']
913
}
1014
}).compile('CreateChatThreadParams');
1115

12-
module.exports = ({ db }) => async function createChatThread(params) {
13-
const { userId } = new CreateChatThreadParams(params);
14-
const ChatThread = db.model('__Studio_ChatThread');
16+
module.exports = ({ studioConnection }) => async function createChatThread(params) {
17+
const { userId, roles } = new CreateChatThreadParams(params);
18+
const ChatThread = studioConnection.model('__Studio_ChatThread');
19+
20+
await authorize('ChatThread.createChatThread', roles);
1521

1622
const chatThread = await ChatThread.create({ userId });
1723

backend/actions/ChatThread/getChatThread.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
45
const mongoose = require('mongoose');
56

67
const GetChatThreadParams = new Archetype({
@@ -9,20 +10,25 @@ const GetChatThreadParams = new Archetype({
910
},
1011
userId: {
1112
$type: mongoose.Types.ObjectId
13+
},
14+
roles: {
15+
$type: ['string']
1216
}
1317
}).compile('GetChatThreadParams');
1418

15-
module.exports = ({ db }) => async function getChatThread(params) {
16-
const { chatThreadId, userId } = new GetChatThreadParams(params);
17-
const ChatThread = db.model('__Studio_ChatThread');
18-
const ChatMessage = db.model('__Studio_ChatMessage');
19+
module.exports = ({ db, studioConnection }) => async function getChatThread(params) {
20+
const { chatThreadId, userId, roles } = new GetChatThreadParams(params);
21+
const ChatThread = studioConnection.model('__Studio_ChatThread');
22+
const ChatMessage = studioConnection.model('__Studio_ChatMessage');
23+
24+
await authorize('ChatThread.getChatThread', roles);
1925

2026
const chatThread = await ChatThread.findById(chatThreadId);
2127

2228
if (!chatThread) {
2329
throw new Error('Chat thread not found');
2430
}
25-
if (userId && chatThread.userId.toString() !== userId.toString()) {
31+
if (userId && chatThread.userId?.toString() !== userId.toString()) {
2632
throw new Error('Not authorized');
2733
}
2834

backend/actions/ChatThread/listChatThreads.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
45
const mongoose = require('mongoose');
56

67
const ListChatThreadsParams = new Archetype({
78
userId: {
89
$type: mongoose.Types.ObjectId
10+
},
11+
roles: {
12+
$type: ['string']
913
}
1014
}).compile('ListChatThreadsParams');
1115

12-
module.exports = ({ db }) => async function listChatThreads(params) {
13-
// Just validate the params object, but no actual parameters needed
14-
const { userId } = new ListChatThreadsParams(params);
15-
const ChatThread = db.model('__Studio_ChatThread');
16+
module.exports = ({ db, studioConnection }) => async function listChatThreads(params) {
17+
// Validate the params object
18+
const { userId, roles } = new ListChatThreadsParams(params);
19+
const ChatThread = studioConnection.model('__Studio_ChatThread');
20+
21+
await authorize('ChatThread.listChatThreads', roles);
1622

1723
// Get all chat threads
1824
const chatThreads = await ChatThread.find(userId ? { userId } : {})
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
2+
23
const Archetype = require('archetype');
4+
const authorize = require('../../authorize');
35

46
const CreateDashboardParams = new Archetype({
57
title: {
@@ -9,14 +11,19 @@ const CreateDashboardParams = new Archetype({
911
code: {
1012
$type: 'string',
1113
$required: true
14+
},
15+
roles: {
16+
$type: ['string']
1217
}
1318
}).compile('CreateDashboardParams');
1419

1520
module.exports = ({ db }) => async function createDashboard(params) {
16-
const { title, code } = new CreateDashboardParams(params);
21+
const { title, code, roles } = new CreateDashboardParams(params);
1722
const Dashboard = db.model('__Studio_Dashboard');
1823

24+
await authorize('Dashboard.createDashboard', roles);
25+
1926
const dashboard = await Dashboard.create({ title, code });
2027

2128
return { dashboard };
22-
};
29+
};
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
'use strict';
22

33
const Archetype = require('archetype');
4-
const vm = require('vm');
4+
const authorize = require('../../authorize');
55

66
const DeleteDashboardParams = new Archetype({
77
dashboardId: {
88
$type: 'string',
99
$required: true
1010
},
11+
roles: {
12+
$type: ['string']
13+
}
1114
}).compile('DeleteDashboardParams');
1215

1316
module.exports = ({ db }) => async function deleteDashboard(params) {
14-
const { dashboardId } = new DeleteDashboardParams(params);
17+
const { dashboardId, roles } = new DeleteDashboardParams(params);
1518
const Dashboard = db.model('__Studio_Dashboard');
1619

20+
await authorize('Dashboard.deleteDashboard', roles);
21+
1722
const result = await Dashboard.deleteOne({ _id: dashboardId }).orFail();
1823
return { result };
19-
};
24+
};

backend/actions/Dashboard/getDashboard.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Archetype = require('archetype');
44
const vm = require('vm');
5+
const authorize = require('../../authorize');
56

67
const GetDashboardParams = new Archetype({
78
dashboardId: {
@@ -10,13 +11,18 @@ const GetDashboardParams = new Archetype({
1011
},
1112
evaluate: {
1213
$type: 'boolean'
14+
},
15+
roles: {
16+
$type: ['string']
1317
}
1418
}).compile('GetDashboardParams');
1519

1620
module.exports = ({ db }) => async function getDashboard(params) {
17-
const { dashboardId, evaluate } = new GetDashboardParams(params);
21+
const { dashboardId, evaluate, roles } = new GetDashboardParams(params);
1822
const Dashboard = db.model('__Studio_Dashboard');
1923

24+
await authorize('Dashboard.getDashboard', roles);
25+
2026
const dashboard = await Dashboard.findOne({ _id: dashboardId });
2127
if (evaluate) {
2228
let result = null;
@@ -25,9 +31,9 @@ module.exports = ({ db }) => async function getDashboard(params) {
2531
} catch (error) {
2632
return { dashboard, error: { message: error.message } };
2733
}
28-
34+
2935
return { dashboard, result };
3036
}
3137

3238
return { dashboard };
33-
};
39+
};

0 commit comments

Comments
 (0)