@surph_ai/sdk 0.0.16 → 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.
@@ -1,19 +1,15 @@
1
- const tool = require('./dist/tools')
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
- payload = await tool(args);
7
+ payload = await tool(args);
8
+ } catch (error) {
9
+ payload = error instanceof Error ? error.message : String(error);
8
10
  }
9
- catch (error) {
10
- payload = error instanceof Error ? error.message : String(error);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surph_ai/sdk",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
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
- utils.write('tsconfig.json', JSON.stringify({
122
+ const tsConfig = {
123
123
  "compilerOptions": {
124
124
  "target": "ES2022",
125
- "module": "commonjs",
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
- }, null, 2) + '\n')
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,10 +2,11 @@
2
2
  "name": "tool-template",
3
3
  "version": "0.0.0",
4
4
  "private": true,
5
+ "type": "module",
5
6
  "scripts": {
6
- "dev": "npm run build && npm run watch && surph toolserver & surph chatserver",
7
+ "dev": "npm run build && concurrently \"npm run watch\" \"surph toolserver\" \"surph chatserver\"",
7
8
  "test": "",
8
- "build": "rm -rf dist && tsc",
9
+ "build": "rimraf dist && tsc",
9
10
  "watch": "tsc -w",
10
11
  "publish": "npm run build && surph publish",
11
12
  "deploy": "npm run build && surph deploy"
@@ -14,9 +15,11 @@
14
15
  "@vinely-ai/sdk": "^0.0.6"
15
16
  },
16
17
  "devDependencies": {
17
- "@surph_ai/sdk": "^0.0.13",
18
+ "@surph_ai/sdk": "^0.0.17",
18
19
  "@types/node": "^20.11.0",
20
+ "concurrently": "^10.0.5",
19
21
  "nodemon": "^2.0.2",
22
+ "rimraf": "^6.1.3",
20
23
  "typescript": "^5.3.3"
21
24
  }
22
25
  }
@@ -1,8 +1,14 @@
1
1
  const { Router, response } = require('express')
2
- // const tools = require('../../../../../tools')
3
- const tools = require('../../../../../dist/tools')
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
- // const tool = tools[req.params.tool]
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({