@surph_ai/cli 0.0.27 → 0.0.28
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/package.json +1 -1
- package/toolserver/routes/index.js +12 -10
- package/utils/boardConfiguration.js +12 -4
- package/utils/userConfiguration.js +52 -25
package/package.json
CHANGED
|
@@ -29,20 +29,22 @@ const readSurphSession = () => {
|
|
|
29
29
|
|
|
30
30
|
router.get('/', async (req, res, next) => {
|
|
31
31
|
try {
|
|
32
|
+
// res.json({data: 'test'})
|
|
33
|
+
// return
|
|
32
34
|
const toolSlugs = Object.keys(manifest)
|
|
33
35
|
|
|
34
36
|
// Mirror `userId` to `_id` (and `id`) so preloaded.user matches the
|
|
35
37
|
// production shape the web app consumes — useSettings.js reads
|
|
36
38
|
// `preloaded.user` and downstream code branches on `_id`.
|
|
37
39
|
const session = readSurphSession()
|
|
38
|
-
// const { user, contexts,
|
|
40
|
+
// const { user, contexts, waves, tools } = session?.userId? await userConfiguration({ id: session.userId }) : null
|
|
39
41
|
const userConfig = session?.userId? await userConfiguration({ id: session.userId }) : null
|
|
40
42
|
|
|
41
43
|
let title = 'Surph AI'
|
|
42
44
|
let ctx = null
|
|
43
45
|
let board = null
|
|
44
46
|
let tools = null
|
|
45
|
-
let
|
|
47
|
+
let waves = null
|
|
46
48
|
let contexts = null
|
|
47
49
|
|
|
48
50
|
if (req.surph_board) {
|
|
@@ -51,15 +53,15 @@ router.get('/', async (req, res, next) => {
|
|
|
51
53
|
title = req.surph_board.name
|
|
52
54
|
|
|
53
55
|
tools = req.surph_board.tools
|
|
54
|
-
|
|
56
|
+
waves = req.surph_board.waves
|
|
55
57
|
contexts = req.surph_board.contexts
|
|
56
58
|
} else if (userConfig) {
|
|
57
59
|
tools = userConfig.tools
|
|
58
|
-
|
|
60
|
+
waves = userConfig.waves
|
|
59
61
|
contexts = userConfig.contexts
|
|
60
62
|
} else { // no user logged in, set empty:
|
|
61
63
|
tools = []
|
|
62
|
-
|
|
64
|
+
waves = []
|
|
63
65
|
contexts = []
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -67,17 +69,17 @@ router.get('/', async (req, res, next) => {
|
|
|
67
69
|
const creator = userConfig ? { _id: user._id, username: user.username, avatar: user.avatar } : {}
|
|
68
70
|
const localTools = toolSlugs.map(slug => {
|
|
69
71
|
const tool = manifest[slug]
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
+
let isWaveTool = false
|
|
73
|
+
waves.forEach(t => {
|
|
72
74
|
if (!t.tools)
|
|
73
75
|
return
|
|
74
76
|
|
|
75
77
|
if (t.tools.indexOf(slug) > -1) {
|
|
76
|
-
|
|
78
|
+
isWaveTool = true
|
|
77
79
|
}
|
|
78
80
|
})
|
|
79
81
|
|
|
80
|
-
return
|
|
82
|
+
return isWaveTool ? { ...tool, creator, origin: 'wave' } : { ...tool, creator }
|
|
81
83
|
})
|
|
82
84
|
|
|
83
85
|
const context = {
|
|
@@ -89,7 +91,7 @@ router.get('/', async (req, res, next) => {
|
|
|
89
91
|
user,
|
|
90
92
|
config: { ...req.config, entry: 'web' },
|
|
91
93
|
contexts,
|
|
92
|
-
|
|
94
|
+
waves,
|
|
93
95
|
tools: localTools // sdk mode is for local tool development only, do not clutter with live tools.
|
|
94
96
|
// tools: [ ...tools, ...localTools ]
|
|
95
97
|
}
|
|
@@ -32,10 +32,18 @@ const boardConfiguration = async (boardSlug) => {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
const { payload } = await response.json();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// console.log('PAYLOAD: ' + JSON.stringify(payload))
|
|
36
|
+
if (!payload)
|
|
37
|
+
return null;
|
|
38
|
+
if (!payload.board)
|
|
39
|
+
return null;
|
|
40
|
+
// Tides are retired: drop the board's legacy tide list (still on the
|
|
41
|
+
// Mongo record and in the query payload) so nothing downstream sees it.
|
|
42
|
+
const { tides: _tides, ...board } = payload.board;
|
|
43
|
+
const { tides: _boardTides, ...config } = payload;
|
|
44
|
+
const result = { ...config, board };
|
|
45
|
+
BOARD_CACHE[boardSlug] = result;
|
|
46
|
+
return result;
|
|
39
47
|
}
|
|
40
48
|
catch (error) {
|
|
41
49
|
console.error('Error fetching board: ', error.message);
|
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
const REST_API_URL = 'https://surph-mongo-http-19075ff8d93f.herokuapp.com'
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (!
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
3
|
+
// The user_configuration query also adds the tools attached to the user's
|
|
4
|
+
// waves, tagged `origin: 'wave'` (often a second copy of an installed tool).
|
|
5
|
+
// Keep only the ones the user created, untagged, and one entry per slug.
|
|
6
|
+
const withoutWaveTools = (tools, userId) => {
|
|
7
|
+
if (!Array.isArray(tools))
|
|
8
|
+
return tools;
|
|
9
|
+
const uid = String(userId);
|
|
10
|
+
const seen = new Set();
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const t of tools) {
|
|
13
|
+
if (!t)
|
|
14
|
+
continue;
|
|
15
|
+
if (t.origin === 'wave') {
|
|
16
|
+
const creatorId = t.creator?._id || t.creator?.id || null;
|
|
17
|
+
if (creatorId == null || String(creatorId) !== uid)
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const { origin: _origin, ...tool } = t;
|
|
21
|
+
const key = tool.slug || String(tool._id || '');
|
|
22
|
+
if (key && seen.has(key))
|
|
23
|
+
continue;
|
|
24
|
+
if (key)
|
|
25
|
+
seen.add(key);
|
|
26
|
+
out.push(tool);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
};
|
|
30
|
+
// fetch user contexts, waves, tools, boards, etc.
|
|
31
|
+
const userConfiguration = async (user) => {
|
|
32
|
+
try {
|
|
33
|
+
const userId = user?._id || user?.id || null;
|
|
34
|
+
if (!userId)
|
|
35
|
+
return null;
|
|
36
|
+
const response = await fetch(`${REST_API_URL}/queries/user_configuration`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body: JSON.stringify({ user: userId }),
|
|
39
|
+
headers: {
|
|
40
|
+
'Accept': 'application/json',
|
|
41
|
+
'Content-type': 'application/json',
|
|
42
|
+
'x-surph-client': 'surph-webapp',
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const { payload } = await response.json();
|
|
46
|
+
const { user: _user, contexts, waves, tools, boards, templates } = payload;
|
|
47
|
+
// Tides are retired: drop the user's legacy subscribed-tide list.
|
|
48
|
+
const { tides: _tides, ...userRecord } = _user || {};
|
|
49
|
+
return { user: _user ? userRecord : _user, contexts, waves, tools: withoutWaveTools(tools, userId), boards, templates };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
28
55
|
|
|
29
56
|
module.exports = userConfiguration;
|