@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surph_ai/cli",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "./types.d.ts",
@@ -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, tides, tools } = session?.userId? await userConfiguration({ id: session.userId }) : null
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 tides = null
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
- tides = req.surph_board.tides
56
+ waves = req.surph_board.waves
55
57
  contexts = req.surph_board.contexts
56
58
  } else if (userConfig) {
57
59
  tools = userConfig.tools
58
- tides = userConfig.tides
60
+ waves = userConfig.waves
59
61
  contexts = userConfig.contexts
60
62
  } else { // no user logged in, set empty:
61
63
  tools = []
62
- tides = []
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 isTideTool = false
71
- tides.forEach(t => {
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
- isTideTool = true
78
+ isWaveTool = true
77
79
  }
78
80
  })
79
81
 
80
- return isTideTool ? { ...tool, creator, origin: 'tide' } : { ...tool, creator }
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
- tides,
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
- BOARD_CACHE[boardSlug] = payload;
36
- // console.log('PAYLOAD: ' + JSON.stringify(payload));
37
- const { board, contexts, tides, tools } = payload;
38
- return { board, contexts, tides, tools };
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
- // fetch user contexts, threads, tides, etc.
4
- const userConfiguration = async (user, includeTides = true) => {
5
- try {
6
- const userId = user?._id || user?.id || null;
7
- if (!userId) return null;
8
-
9
- const response = await fetch(`${REST_API_URL}/queries/user_configuration`, {
10
- method: 'POST',
11
- body: JSON.stringify({ user: userId}),
12
- headers: {
13
- 'Accept': 'application/json',
14
- 'Content-type': 'application/json',
15
- 'x-surph-client': 'surph-webapp',
16
- }
17
- })
18
-
19
- const { payload } = await response.json()
20
- const { user: _user, contexts, tides, tools } = payload
21
- // console.log('PAYLOAD: ' + JSON.stringify({ contexts, tides, tools }))
22
-
23
- return { user: _user, contexts, tides, tools }
24
- } catch (error) {
25
- throw error
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;