@surph_ai/cli 0.0.20 → 0.0.22

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.20",
3
+ "version": "0.0.22",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "./types.d.ts",
@@ -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
  }
@@ -63,7 +63,7 @@ router.get('/', async (req, res, next) => {
63
63
  contexts = []
64
64
  }
65
65
 
66
- const user = userConfig ? userConfig.user : { permissions: [] }
66
+ const user = userConfig ? userConfig.user : { permissions: [] } // TODO: address this client side
67
67
  const creator = userConfig ? { _id: user._id, username: user.username, avatar: user.avatar } : {}
68
68
  const localTools = toolSlugs.map(slug => {
69
69
  const tool = manifest[slug]
@@ -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
  }
@@ -1,45 +0,0 @@
1
- import type { ToolHandler } from '@surph_ai/sdk';
2
- import { surph } from '@surph_ai/sdk';
3
-
4
- // your custom tool args goes here
5
- type ToolArgs = {
6
- preferences: string[]
7
- };
8
-
9
- const handler: ToolHandler<ToolArgs> = async ({ args, user, context = null, board = null }: Record<string, any>) => {
10
- try {
11
- if (!args) {
12
- throw new Error('Args required.')
13
- }
14
-
15
- if (!context) {
16
- throw new Error('Context required.')
17
- }
18
-
19
- const { preferences } = args; // string[]
20
- const searchQuery = preferences.join(', ')
21
-
22
- const searchResults = await surph.search(searchQuery, context)
23
-
24
- const promptResponse = await surph.prompt({
25
- instructions: `searchResults is a JSON array data feed of events and announcements. Your job is to sort each item into one of three categories: offering free food, free event, or free giveaway (such as raffles, prizes, etc.).`,
26
- prompt: `Given this list of items, separate them into free food, free event, or free giveaway:\n\n${JSON.stringify(searchResults)}`,
27
- output: {
28
- name: 'deal_search_results',
29
- description: 'The deal search results',
30
- fields: [
31
- { name: 'food', type: 'array', description: 'a list of events and announcements with free food.' },
32
- { name: 'event', type: 'array', description: 'a list of events that are free to attend.' },
33
- { name: 'items', type: 'array', description: 'a list of events and announcements with free items.' }
34
- ]
35
- }
36
- })
37
-
38
- return promptResponse
39
- } catch (error) {
40
- throw error
41
- }
42
- };
43
-
44
- export default handler;
45
-
@@ -1,21 +0,0 @@
1
- {
2
- "deal-finder-q9je7jou": {
3
- "name": "deal-finder",
4
- "slug": "deal-finder-q9je7jou",
5
- "type": "custom",
6
- "description": "Search the user's active Surph context for local deals, discounts, promotions, specials, sales, and related opportunities across food, drinks, restaurants, shops, events, entertainment, and other businesses or venues covered by the context. Use whenever the user asks to find, compare, filter, or recommend current or upcoming local deals—including requests for happy hours, meal specials, event discounts, retail sales, coupons, or promotions. Prefer this instead of webSearch when the requested local businesses, venues, events, or listings are represented in the active Surph context.",
7
- "parameters": {
8
- "type": "object",
9
- "properties": {
10
- "preferences": {
11
- "type": "array",
12
- "description": "Optional free-form preferences, categories, constraints, or deal criteria to prioritize, such as food, drinks, events, retail sales, happy hour, nearby neighborhoods, budget, dates, or specific businesses.",
13
- "items": {
14
- "type": "string"
15
- }
16
- }
17
- },
18
- "required": []
19
- }
20
- }
21
- }