@surph_ai/cli 0.0.19 → 0.0.21

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.19",
3
+ "version": "0.0.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "./types.d.ts",
@@ -6,19 +6,20 @@ type ToolArgs = {
6
6
  preferences: string[]
7
7
  };
8
8
 
9
- const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, board = null }: Record<string, any>) => {
9
+ const handler: ToolHandler<ToolArgs> = async ({ args, user, contexts = null, board = null }: Record<string, any>) => {
10
10
  try {
11
11
  if (!args) {
12
12
  throw new Error('Args required.')
13
13
  }
14
14
 
15
- if (!context) {
16
- throw new Error('Context required.')
15
+ if (!contexts) {
16
+ throw new Error('Contexts required.')
17
17
  }
18
18
 
19
19
  const { preferences } = args; // string[]
20
20
  const searchQuery = preferences.join(', ')
21
21
 
22
+ const context = contexts[0]
22
23
  const searchResults = await surph.search(searchQuery, context)
23
24
 
24
25
  const promptResponse = await surph.prompt({
@@ -11,7 +11,7 @@ type ToolArgs = {
11
11
  city: string
12
12
  };
13
13
 
14
- const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, board = null }: Record<string, any>) => {
14
+ const handler: ToolHandler<ToolArgs> = async ({ args, user, contexts = null, board = null }: Record<string, any>) => {
15
15
  try {
16
16
  // your custom tool code goes here
17
17
  const { city } = args
@@ -111,7 +111,7 @@ type ToolArgs = {
111
111
  location: string
112
112
  };
113
113
 
114
- const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, board = null }: Record<string, any>) => {
114
+ const handler: ToolHandler<ToolArgs> = async ({ args, user, contexts = null, board = null }: Record<string, any>) => {
115
115
  try {
116
116
  const { location } = args;
117
117
  if (!location) {
@@ -1,15 +1,12 @@
1
1
  import type { ToolHandler, ToolContext, User } from '@surph_ai/sdk';
2
2
  import { surph, SurphContext, SurphBoard } from '@surph_ai/sdk';
3
3
 
4
- type ToolArgs = {
5
- // your custom tool args goes here
6
- };
4
+ // your custom tool args goes here
5
+ type ToolArgs = {};
7
6
 
8
- const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, board = null }: Record<string, any>) => {
7
+ // your custom tool code goes here.
8
+ const handler: ToolHandler<ToolArgs> = async ({ args, user, contexts = null, board = null }: Record<string, any>) => {
9
9
  try {
10
-
11
- // your custom tool code goes here.
12
- //
13
10
  // pro tip: tell your coding agent to use "CHEATSHEET.md"
14
11
  // as a guide for working with this sdk. for example, tell
15
12
  // your coding agent "use CHEATSHEET.md to set up a fetch
@@ -17,11 +14,17 @@ const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, boar
17
14
  //
18
15
  // IMPORTANT: before testing your custom tool, remember to
19
16
  // populate the "manifest.json" file so surph knows when to
20
- // use it. To do so, run:
21
- //
22
- // npx @surph_ai/cli manifest
17
+ // use it. To do so, run: "npx @surph_ai/cli manifest".
18
+
19
+ // example payload:
20
+ // return {
21
+ // items: data,
22
+ // format_instructions: 'For each item, extract a formatted event listing with date, time, location,
23
+ // title, and description. If the item is a happening with a time and place, mark it as an event;
24
+ // otherwise still include it but mark isEvent=false. Pull fields from title/content/tags/source when
25
+ // present; use "" if unknown.'
26
+ // };
23
27
 
24
- // this is your tool final payload:
25
28
  return {}
26
29
  } catch (error: any) {
27
30
  throw error
@@ -1,5 +1,6 @@
1
1
  const { SURPH_S3_URL } = require('../../utils/constants.js')
2
2
  const boardConfiguration = require('../../utils/boardConfiguration.js')
3
+ const BOARD_CACHE = {}
3
4
 
4
5
  module.exports = async (req, res, next) => {
5
6
  const headers = req.headers;
@@ -19,7 +20,6 @@ module.exports = async (req, res, next) => {
19
20
  // surphBoard = process.env.SURPH_BOARD;
20
21
  // }
21
22
 
22
- // console.log('SURPH_BOARD_ENV: ', surphBoard);
23
23
  if (!surphBoard) {
24
24
  return next();
25
25
  }
@@ -28,8 +28,15 @@ module.exports = async (req, res, next) => {
28
28
  return next();
29
29
  }
30
30
 
31
+ if (BOARD_CACHE[surphBoard]) {
32
+ req.surph_board = { ...BOARD_CACHE[surphBoard] }
33
+ return next();
34
+ }
35
+
36
+ console.log('SURPH_BOARD_ENV: ', surphBoard);
37
+
31
38
  // const surph_board = await boardConfiguration(surphBoard);
32
- const { board, contexts, tides, tools } = await boardConfiguration(surphBoard);
39
+ const { board = {}, contexts, tides, tools } = await boardConfiguration(surphBoard);
33
40
 
34
41
  const tideTools = []
35
42
  tides.forEach(t => {
@@ -61,6 +68,8 @@ module.exports = async (req, res, next) => {
61
68
  relativePath: `${SURPH_S3_URL}/boards/${surphBoard}/`
62
69
  };
63
70
 
71
+ BOARD_CACHE[surphBoard] = { ...req.surph_board }
72
+
64
73
  // console.log('\n\nSURPH_BOARD: ', JSON.stringify(req.surph_board));
65
74
  next();
66
75
  }
@@ -53,14 +53,18 @@ router.get('/', async (req, res, next) => {
53
53
  tools = req.surph_board.tools
54
54
  tides = req.surph_board.tides
55
55
  contexts = req.surph_board.contexts
56
- } else {
56
+ } else if (userConfig) {
57
57
  tools = userConfig.tools
58
58
  tides = userConfig.tides
59
59
  contexts = userConfig.contexts
60
+ } else { // no user logged in, set empty:
61
+ tools = []
62
+ tides = []
63
+ contexts = []
60
64
  }
61
65
 
62
- const user = userConfig.user
63
- const creator = { _id: user._id, username: user.username, avatar: user.avatar }
66
+ const user = userConfig ? userConfig.user : { permissions: [] } // TODO: address this client side
67
+ const creator = userConfig ? { _id: user._id, username: user.username, avatar: user.avatar } : {}
64
68
  const localTools = toolSlugs.map(slug => {
65
69
  const tool = manifest[slug]
66
70
  let isTideTool = false
@@ -17,11 +17,12 @@ const loadTool = () => import(toolsPath).then((mod) => mod.default)
17
17
  const router = Router()
18
18
 
19
19
  const handler = async (event, tool) => {
20
- const { args, context, user, board } = event
20
+ // "context" will eventually be deprecated, "contexts" is primary now.
21
+ const { args, context, contexts, user, board } = event
21
22
  let payload = null
22
23
  let errorMsg = null
23
24
  try {
24
- payload = await tool({ args, context, user, board })
25
+ payload = await tool({ args, context, contexts, user, board })
25
26
  } catch (error) {
26
27
  errorMsg = error instanceof Error ? error.message : String(error)
27
28
  } finally {
@@ -94,13 +95,11 @@ router.get('/test', async (req, res, next) => {
94
95
 
95
96
  router.post('/custom', async (req, res, next) => {
96
97
  try {
97
- const { name, args, tool, user = null, context = null, board = null } = req.body;
98
- // if (process.env.SURPH_TOOL !== tool.slug) {
99
- // throw new Error(`Invalid tool ${tool.slug}. Check .env file.`)
100
- // }
101
-
98
+ // "context" will eventually be deprecated, "contexts" is primary now.
99
+ const { name, args, tool, user = null, context = null, contexts = null, board = null } = req.body;
102
100
  const toolRunner = await loadTool()
103
- const response = await handler({ args, context, user, board }, toolRunner)
101
+
102
+ const response = await handler({ args, context, contexts, user, board }, toolRunner)
104
103
  if (response.error) {
105
104
  throw new Error(response.error);
106
105
  }