@surph_ai/sdk 0.0.17 → 0.0.18
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/deploy/tool-handler.js +8 -12
- package/package.json +1 -1
- package/scaffold/index.js +6 -3
- package/scaffold/tool/package.json +2 -1
- package/toolserver/routes/tool.js +10 -11
package/deploy/tool-handler.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import tool from './dist/tools/index.js';
|
|
2
2
|
|
|
3
|
-
const handler = async (event) => {
|
|
3
|
+
export const handler = async (event) => {
|
|
4
4
|
const { args = {} } = event;
|
|
5
5
|
let payload = null;
|
|
6
6
|
try {
|
|
7
|
-
|
|
7
|
+
payload = await tool(args);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
payload = error instanceof Error ? error.message : String(error);
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const response = {
|
|
13
|
-
statusCode: 200,
|
|
14
|
-
body: JSON.stringify(payload),
|
|
11
|
+
return {
|
|
12
|
+
statusCode: 200,
|
|
13
|
+
body: JSON.stringify(payload),
|
|
15
14
|
};
|
|
16
|
-
return response;
|
|
17
15
|
};
|
|
18
|
-
|
|
19
|
-
exports.handler = handler;
|
package/package.json
CHANGED
package/scaffold/index.js
CHANGED
|
@@ -119,10 +119,11 @@ module.exports = (name, type = 'app') => {
|
|
|
119
119
|
const envStr = utils.readFile(path.join(__dirname, 'tool/env.txt'))
|
|
120
120
|
utils.write('.env', envStr.replace('<SURPH_TOOL>', slug))
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
const tsConfig = {
|
|
123
123
|
"compilerOptions": {
|
|
124
124
|
"target": "ES2022",
|
|
125
|
-
"module": "
|
|
125
|
+
"module": "Node16",
|
|
126
|
+
"moduleResolution": "Node16",
|
|
126
127
|
"lib": ["ES2022"],
|
|
127
128
|
"types": ["node"],
|
|
128
129
|
"outDir": "./dist",
|
|
@@ -135,7 +136,9 @@ module.exports = (name, type = 'app') => {
|
|
|
135
136
|
},
|
|
136
137
|
"include": ["tools/**/*.ts"],
|
|
137
138
|
"exclude": ["node_modules", "dist"]
|
|
138
|
-
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
utils.write('tsconfig.json', JSON.stringify(tsConfig, null, 2) + '\n')
|
|
139
142
|
|
|
140
143
|
console.log('\n- - - - - Next Steps - - - - - ')
|
|
141
144
|
console.log('1. $ cd ' + name)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"name": "tool-template",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"private": true,
|
|
5
|
+
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"dev": "npm run build && concurrently \"npm run watch\" \"surph toolserver\" \"surph chatserver\"",
|
|
7
8
|
"test": "",
|
|
@@ -14,7 +15,7 @@
|
|
|
14
15
|
"@vinely-ai/sdk": "^0.0.6"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
|
-
"@surph_ai/sdk": "^0.0.
|
|
18
|
+
"@surph_ai/sdk": "^0.0.17",
|
|
18
19
|
"@types/node": "^20.11.0",
|
|
19
20
|
"concurrently": "^10.0.5",
|
|
20
21
|
"nodemon": "^2.0.2",
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const { Router, response } = require('express')
|
|
2
|
-
|
|
3
|
-
const
|
|
2
|
+
const path = require('path')
|
|
3
|
+
const { pathToFileURL } = require('url')
|
|
4
4
|
const manifest = require('../../../../../manifest.json')
|
|
5
5
|
|
|
6
|
+
const toolsPath = pathToFileURL(
|
|
7
|
+
path.resolve(__dirname, '../../../../../dist/tools/index.js')
|
|
8
|
+
).href
|
|
9
|
+
|
|
10
|
+
const loadTool = () => import(toolsPath).then((mod) => mod.default)
|
|
11
|
+
|
|
6
12
|
const router = Router()
|
|
7
13
|
|
|
8
14
|
const handler = async (args, tool) => {
|
|
@@ -40,11 +46,7 @@ router.get('/', async (req, res, next) => {
|
|
|
40
46
|
|
|
41
47
|
router.get('/:tool', async (req, res, next) => {
|
|
42
48
|
try {
|
|
43
|
-
|
|
44
|
-
// if (!tool) {
|
|
45
|
-
// throw new Error(`Tool ${req.params.tool} not found.`)
|
|
46
|
-
// }
|
|
47
|
-
|
|
49
|
+
const tools = await loadTool()
|
|
48
50
|
const response = await handler(req.query, tools)
|
|
49
51
|
res.json({ response })
|
|
50
52
|
} catch (error) {
|
|
@@ -58,18 +60,15 @@ router.get('/:tool', async (req, res, next) => {
|
|
|
58
60
|
})
|
|
59
61
|
|
|
60
62
|
router.post('/custom', async (req, res, next) => {
|
|
61
|
-
// console.log('TOOL CALL: ' + JSON.stringify(req.body))
|
|
62
63
|
try {
|
|
63
64
|
const { name, args, tool, user = null } = req.body;
|
|
64
|
-
// console.log('TOOL CALL: ' + name)
|
|
65
|
-
// console.log('TOOL ARGS: ' + JSON.stringify(args))
|
|
66
65
|
|
|
67
66
|
if (process.env.SURPH_TOOL !== tool.slug) {
|
|
68
67
|
throw new Error(`Invalid tool ${tool.slug}. Check .env file.`)
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
const tools = await loadTool()
|
|
71
71
|
const response = await handler(args, tools)
|
|
72
|
-
// console.log('TOOL RESP: ' + JSON.stringify(response))
|
|
73
72
|
res.json({ response })
|
|
74
73
|
} catch (error) {
|
|
75
74
|
res.json({
|