@surph_ai/cli 0.0.20 → 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 +1 -1
- package/scaffold/tool/examples/dealfinder/index.ts +4 -3
- package/scaffold/tool/examples/population/index.ts +1 -1
- package/scaffold/tool/examples/weather/index.ts +1 -1
- package/scaffold/tool/tools/index.ts +14 -11
- package/toolserver/middleware/board.js +11 -2
- package/toolserver/routes/index.js +1 -1
- package/toolserver/routes/tool.js +7 -8
package/package.json
CHANGED
|
@@ -6,19 +6,20 @@ type ToolArgs = {
|
|
|
6
6
|
preferences: string[]
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const handler: ToolHandler<ToolArgs> = async ({ args, user,
|
|
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 (!
|
|
16
|
-
throw new Error('
|
|
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,
|
|
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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
4
|
+
// your custom tool args goes here
|
|
5
|
+
type ToolArgs = {};
|
|
7
6
|
|
|
8
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
}
|