@surph_ai/sdk 0.0.12 → 0.0.13

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.
Files changed (59) hide show
  1. package/deploy/index.js +50 -140
  2. package/deploy/tool-main.js +19 -0
  3. package/index.js +97 -34
  4. package/package.json +4 -5
  5. package/scaffold/index.js +11 -11
  6. package/scaffold/tool/package.json +5 -4
  7. package/scaffold/tool/tools/index.js +1 -1
  8. package/toolserver/routes/tool.js +18 -16
  9. package/utils/index.js +0 -1
  10. package/base/vinely-base/.nvmrc +0 -1
  11. package/base/vinely-base/README.md +0 -30
  12. package/base/vinely-base/app.js +0 -5
  13. package/base/vinely-base/declarations.d.ts +0 -1
  14. package/base/vinely-base/package.json +0 -103
  15. package/base/vinely-base/public/css/globals-2.css +0 -3699
  16. package/base/vinely-base/public/css/globals.css +0 -3695
  17. package/base/vinely-base/public/js/app.js +0 -1
  18. package/base/vinely-base/public/js/jquery.js +0 -2
  19. package/base/vinely-base/scratch.js +0 -21
  20. package/base/vinely-base/src/client/components/app-sidebar.tsx +0 -59
  21. package/base/vinely-base/src/client/components/assistant-ui/markdown-text.tsx +0 -153
  22. package/base/vinely-base/src/client/components/assistant-ui/thread-list.tsx +0 -67
  23. package/base/vinely-base/src/client/components/assistant-ui/thread.tsx +0 -666
  24. package/base/vinely-base/src/client/components/assistant-ui/tool-fallback.tsx +0 -44
  25. package/base/vinely-base/src/client/components/assistant-ui/tooltip-icon-button.tsx +0 -44
  26. package/base/vinely-base/src/client/components/ui/breadcrumb.tsx +0 -109
  27. package/base/vinely-base/src/client/components/ui/button.tsx +0 -59
  28. package/base/vinely-base/src/client/components/ui/input.tsx +0 -21
  29. package/base/vinely-base/src/client/components/ui/separator.tsx +0 -28
  30. package/base/vinely-base/src/client/components/ui/sheet.tsx +0 -139
  31. package/base/vinely-base/src/client/components/ui/sidebar.tsx +0 -726
  32. package/base/vinely-base/src/client/components/ui/skeleton.tsx +0 -14
  33. package/base/vinely-base/src/client/components/ui/tooltip.tsx +0 -61
  34. package/base/vinely-base/src/client/components/vines-sidebar.tsx +0 -182
  35. package/base/vinely-base/src/client/contexts/SessionContext.tsx +0 -28
  36. package/base/vinely-base/src/client/contexts/SessionReducer.tsx +0 -32
  37. package/base/vinely-base/src/client/hooks/use-mobile.ts +0 -19
  38. package/base/vinely-base/src/client/index.tsx +0 -154
  39. package/base/vinely-base/src/client/lib/API.ts +0 -155
  40. package/base/vinely-base/src/client/lib/RPC.ts +0 -49
  41. package/base/vinely-base/src/client/lib/utils.ts +0 -96
  42. package/base/vinely-base/src/server/index.ts +0 -63
  43. package/base/vinely-base/src/server/routes/api.ts +0 -38
  44. package/base/vinely-base/src/server/routes/chat.ts +0 -133
  45. package/base/vinely-base/src/server/routes/main.ts +0 -36
  46. package/base/vinely-base/src/server/routes/mcp.ts +0 -52
  47. package/base/vinely-base/src/server/routes/rpc.ts +0 -64
  48. package/base/vinely-base/src/server/routes/thread.ts +0 -44
  49. package/base/vinely-base/src/server/utils/APIMgr.ts +0 -156
  50. package/base/vinely-base/src/server/utils/Auth.ts +0 -235
  51. package/base/vinely-base/src/server/utils/fetchManifest.ts +0 -15
  52. package/base/vinely-base/src/server/utils/mcp-auth.ts +0 -251
  53. package/base/vinely-base/tsconfig.json +0 -16
  54. package/base/vinely-base/views/landing.html +0 -187
  55. package/base/vinely-base/views/partials/imports.dev.html +0 -3
  56. package/base/vinely-base/webpack.config.js +0 -112
  57. package/deploy/Dockerfile +0 -9
  58. package/utils/Realm.js +0 -60
  59. package/utils/http.js +0 -22
package/deploy/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs')
3
- const axios = require('axios')
3
+ // const axios = require('axios')
4
4
  const shell = require('shelljs')
5
5
  const colors = require('colors/safe') // https://www.npmjs.com/package/colors
6
6
  const bestzip = require('bestzip')
7
7
 
8
- // const PORTAL_URL = 'https://portal.turbo360.co'
9
-
10
- const RPC_URL = 'https://e3lunom2hka3u6iiotrlzrcez40uwdnk.lambda-url.us-east-1.on.aws'
8
+ // const RPC_URL = 'https://e3lunom2hka3u6iiotrlzrcez40uwdnk.lambda-url.us-east-1.on.aws'
9
+ const RPC_URL = 'https://rpc.surph.ai'
11
10
  const ZIP_NAME = 'LATEST.zip'
12
11
  const STATIC_ARCHIVE_NAME = 'Archive.zip'
13
12
  const DEFAULT_HEADERS = {
@@ -16,34 +15,40 @@ const DEFAULT_HEADERS = {
16
15
  }
17
16
 
18
17
  const rpcCall = async (action, args, headers = DEFAULT_HEADERS) => {
18
+ let path = null
19
+ if (action === 'uploadUrl') {
20
+ path = 's3/upload_url'
21
+ }
22
+ if (action === 'deployTool') {
23
+ path = 'tools/deploy'
24
+ }
25
+
19
26
  try {
20
- const resp = await axios({
21
- url: RPC_URL,
22
- method: 'post',
23
- headers,
24
- data: {
25
- action,
26
- args
27
- },
27
+ if (action === null) {
28
+ throw new Error(`Invalid action: ${action}`)
29
+ }
30
+
31
+ const resp = await fetch(`${RPC_URL}/${path}`, {
32
+ method: 'POST',
33
+ body: JSON.stringify(args),
34
+ headers: {
35
+ 'Accept': 'application/json',
36
+ 'Content-Type': 'application/json',
37
+ 'x-surph-client': 'surph-sdk'
38
+ }
28
39
  })
29
40
 
30
- return resp
41
+ const { response } = await resp.json()
42
+ if (response.error) {
43
+ throw new Error(response.error)
44
+ }
45
+
46
+ return response
31
47
  } catch (error) {
32
48
  throw error
33
49
  }
34
50
  }
35
51
 
36
- const getUploadUrl = async (folder, filename, filetype = 'application/zip') => {
37
- const resp = await rpcCall('uploadUrl', { folder, filename, filetype })
38
-
39
- if (resp.data.confirmation !== 'success') {
40
- throw new Error(resp.data.message)
41
- }
42
-
43
- const uploadUrl = resp.data.data.upload
44
- return uploadUrl
45
- }
46
-
47
52
  /*
48
53
  // 09/17/2019 - this did not cover all scenarios. Windows worked fine (confirmed
49
54
  // by Marianne) but if on a funky linux distro, the "else" block failed.
@@ -81,12 +86,8 @@ const zipDirectory = (name = 'package.zip') => {
81
86
  }
82
87
 
83
88
  const compile = async (deployDir, name = 'package.zip', dir = null) => {
84
- // let data = utils.readFile('package.json')
85
- // const json = JSON.parse(data)
86
-
87
- // delete json.devDependencies // prevent these from deploying
88
-
89
89
  shell.mkdir('-p', `${deployDir}/`)
90
+ shell.cp('-R', `node_modules/@surph_ai/sdk/deploy/tool-main.js`, `${deployDir}/main.js`)
90
91
 
91
92
  if (dir === null) {
92
93
  shell.cp('-R', '!(node_modules|deploy)', `${deployDir}/`) // copy everything but node_modules and deploy
@@ -98,6 +99,7 @@ const compile = async (deployDir, name = 'package.zip', dir = null) => {
98
99
  }
99
100
 
100
101
  shell.cd(deployDir)
102
+ shell.exec('npm install --production --silent')
101
103
 
102
104
  await zipDirectory(name) // package it up!
103
105
 
@@ -115,130 +117,38 @@ const compile = async (deployDir, name = 'package.zip', dir = null) => {
115
117
  }
116
118
 
117
119
  module.exports = {
118
- project: async ({ TURBO_PROJECT_SLUG }) => {
119
- if (!TURBO_PROJECT_SLUG) {
120
- throw new Error(colors.white('Project undefined. Please check .env file.'))
120
+ tool: async ({ SURPH_TOOL_SLUG }) => {
121
+ if (!SURPH_TOOL_SLUG) {
122
+ throw new Error(colors.white('Tool undefined. Please check .env file.'))
121
123
  }
122
124
 
123
- shell.cp('-R', path.join(__dirname, 'Dockerfile'), 'Dockerfile')
125
+ const { uploadUrl } = await rpcCall('uploadUrl', {
126
+ collection: 'tools',
127
+ folder: SURPH_TOOL_SLUG,
128
+ filename: `uploads/${ZIP_NAME}`,
129
+ filetype: 'application/zip'
130
+ })
124
131
 
125
- const uploadUrl = await getUploadUrl('projects', `${TURBO_PROJECT_SLUG}/container/${ZIP_NAME}`)
132
+ // console.log('UPLOAD URL: ' + uploadUrl)
133
+ console.log(`\n${colors.white('Deploying tool. This usually takes a few minutes...')}\n`)
126
134
 
127
- console.log(`\n${colors.white('Deploying project code. This usually takes a few minutes...')}\n`)
128
135
  await compile('.deploy', ZIP_NAME)
129
136
 
130
- await axios({
131
- url: uploadUrl,
132
- method: 'put',
133
- data: fs.readFileSync(ZIP_NAME),
137
+ await fetch(uploadUrl, {
138
+ method: 'PUT',
139
+ body: fs.readFileSync(ZIP_NAME),
134
140
  headers: {
141
+ 'Accept': 'application/json',
135
142
  'Content-Type': 'application/zip'
136
- }
143
+ }
137
144
  })
138
145
 
139
146
  shell.rm('-rf', ZIP_NAME)
140
- shell.rm('-rf', 'Dockerfile')
141
-
142
- // trigger docker build in the cloud:
143
- await rpcCall('deploy', { project: TURBO_PROJECT_SLUG })
144
147
 
145
148
  // connect container image to function:
146
- await rpcCall('bind-image', { project: TURBO_PROJECT_SLUG })
147
-
148
- console.log(colors.white('\nDeploy complete! To view your site, navigate to\n'))
149
- console.log(colors.white(`https://${TURBO_PROJECT_SLUG}.vinely.site\n\n`))
150
- },
151
-
152
- static: async ({ TURBO_PROJECT_SLUG }) => {
153
- if (!TURBO_PROJECT_SLUG) {
154
- throw new Error(colors.white('Project undefined. Please check .env file.'))
155
- }
156
-
157
- const uploadUrl = await getUploadUrl('projects', `${TURBO_PROJECT_SLUG}/static/${STATIC_ARCHIVE_NAME}`)
158
- await compile('.deploy', STATIC_ARCHIVE_NAME, 'public')
159
-
160
- await axios({
161
- url: uploadUrl,
162
- method: 'put',
163
- data: fs.readFileSync(STATIC_ARCHIVE_NAME),
164
- headers: {
165
- 'Content-Type': 'application/zip'
166
- }
167
- })
168
-
169
- shell.rm('-rf', STATIC_ARCHIVE_NAME)
170
-
171
- try {
172
- await rpcCall('sync', {
173
- project: TURBO_PROJECT_SLUG,
174
- folder: 'static',
175
- file: STATIC_ARCHIVE_NAME
176
- })
177
- } catch (error) {
178
- console.warn('FAIL: ' + error)
179
- return
180
- }
181
-
182
- console.log(colors.white('\nStatic deployment complete! To view, navigate to\n'))
183
- console.log(colors.white(`https://${TURBO_PROJECT_SLUG}.turbo360-static-sites.com\n\n`))
184
- },
185
-
186
- /*
187
- // deploy app:
188
- app: async ({ TURBO_APP_SLUG }) => {
189
- let resp = await axios({
190
- url: RPC_URL,
191
- method: 'post',
192
- data: {
193
- action: 'appDeployments',
194
- args: {
195
- app: TURBO_APP_SLUG
196
- }
197
- },
198
- headers: { Accept: 'application/json' }
199
- })
200
-
201
- const { confirmation, message, data } = resp.data
202
- if (confirmation !== 'success') {
203
- throw new Error(message)
204
- }
205
-
206
- const { deployments } = data
207
- const deployment = `${deployments.length + 1}.zip`
208
-
209
- resp = await axios({
210
- url: RPC_URL,
211
- method: 'post',
212
- data: {
213
- action: 'uploadUrl',
214
- args: {
215
- folder: 'apps',
216
- // filename: `${TURBO_APP_SLUG}/${deployment}`,
217
- filename: `${TURBO_APP_SLUG}/builds/${deployment}`,
218
- filetype: 'application/zip'
219
- }
220
- },
221
- })
222
-
223
- if (resp.data.confirmation !== 'success') {
224
- throw new Error(resp.data.message)
225
- }
226
-
227
- const uploadUrl = resp.data.data.upload
228
-
229
- console.log('\nUploading app code...\n')
230
- await compile('.deploy', deployment)
231
-
232
- await axios({
233
- url: uploadUrl,
234
- method: 'put',
235
- data: fs.readFileSync(deployment),
236
- headers: {
237
- 'Content-Type': 'application/zip'
238
- }
239
- })
149
+ await rpcCall('deployTool', { tool: SURPH_TOOL_SLUG })
240
150
 
241
- shell.rm('-rf', deployment)
151
+ console.log(colors.white('\nDeploy complete! To view your tool, navigate to\n'))
152
+ console.log(colors.white(`https://surph.ai/tool/${SURPH_TOOL_SLUG}\n\n`))
242
153
  }
243
- */
244
154
  }
@@ -0,0 +1,19 @@
1
+ const tool = require('./tools')
2
+
3
+ const handler = async (event) => {
4
+ const { args = {} } = event;
5
+ let payload = null;
6
+ try {
7
+ payload = await tool(args);
8
+ }
9
+ catch (error) {
10
+ payload = error instanceof Error ? error.message : String(error);
11
+ }
12
+ const response = {
13
+ statusCode: 200,
14
+ body: JSON.stringify(payload),
15
+ };
16
+ return response;
17
+ };
18
+
19
+ exports.handler = handler;
package/index.js CHANGED
@@ -6,11 +6,10 @@
6
6
  // https://github.com/expressjs/generator/blob/master/bin/express-cli.js
7
7
  // https://developer.atlassian.com/blog/2015/11/scripting-with-node/
8
8
 
9
+ const { Command } = require('commander')
9
10
  const path = require('path')
10
11
  const dotenv = require('dotenv')
11
- const axios = require('axios')
12
12
  const prompt = require('prompt')
13
- const { Command } = require('commander')
14
13
  const shell = require('shelljs')
15
14
  const colors = require('colors/safe')
16
15
  const AdmZip = require('adm-zip')
@@ -18,12 +17,10 @@ const auth = require('./auth')
18
17
  const deploy = require('./deploy')
19
18
  const scaffold = require('./scaffold')
20
19
  const utils = require('./utils')
21
- const Realm = require('./utils/Realm')
22
20
  const packageJson = require('./package.json')
23
21
 
24
22
  const VERSION = packageJson.version
25
-
26
- const PORTAL_URL = 'https://portal.turbo360.co'
23
+ const SURPH_REST_URL = 'https://surph-mongo-http-19075ff8d93f.herokuapp.com'
27
24
  // const RPC_URL = 'https://e3lunom2hka3u6iiotrlzrcez40uwdnk.lambda-url.us-east-1.on.aws'
28
25
 
29
26
  // FUTURE: Export as a referenceable type
@@ -74,6 +71,7 @@ program.command('profile')
74
71
  console.log(text)
75
72
  })
76
73
 
74
+ /*
77
75
  program.command('login')
78
76
  .description('login to Surph')
79
77
  .action(async (cmd, options) => {
@@ -100,21 +98,22 @@ program.command('login')
100
98
  }
101
99
  })
102
100
 
103
- // program.command('dev')
104
- // .description('run dev server')
105
- // .action(async (cmd, options) => {
106
- // try {
107
- // // shell.cp('-R', path.join(__dirname, '../default/lambda/js/index.js'), 'vectors/js/index.js')
108
- // shell.cd(path.join(__dirname, 'base/Surph-base'))
109
- // shell.exec('npm run dev')
110
- // // shell.cd('Surph-base')
101
+ program.command('dev')
102
+ .description('run dev server')
103
+ .action(async (cmd, options) => {
104
+ try {
105
+ // shell.cp('-R', path.join(__dirname, '../default/lambda/js/index.js'), 'vectors/js/index.js')
106
+ shell.cd(path.join(__dirname, 'base/Surph-base'))
107
+ shell.exec('npm run dev')
108
+ // shell.cd('Surph-base')
111
109
 
112
- // // shell.exec('gulp build --gulpfile node_modules/@turbo360/turbo-sdk/src/gulpfile.js --silent')
110
+ // shell.exec('gulp build --gulpfile node_modules/@turbo360/turbo-sdk/src/gulpfile.js --silent')
113
111
 
114
- // } catch (error) {
115
- // utils.printError(error)
116
- // }
117
- // })
112
+ } catch (error) {
113
+ utils.printError(error)
114
+ }
115
+ })
116
+ */
118
117
 
119
118
  program.command('new <name>')
120
119
  .description('create new Surph app')
@@ -144,6 +143,7 @@ program.command('tool <name>')
144
143
  .description('create new Surph tool')
145
144
  .action(name => scaffold(name, 'tool'))
146
145
 
146
+ /*
147
147
  program.command('connect')
148
148
  .description('Connect to Surph project')
149
149
  .action(async (cmd, options) => {
@@ -224,12 +224,81 @@ program.command('connect')
224
224
  utils.printError(error)
225
225
  }
226
226
  })
227
+ */
228
+
229
+ program.command('publish')
230
+ .description('Publish Surph tool')
231
+ .action(async (cmd, options) => {
232
+ try {
233
+ const manifest = require('../../../tools/manifest.json')
234
+
235
+ // TODO: if not found try root directory.
236
+ if (!manifest) {
237
+ throw new Error('manifest.json not found')
238
+ }
239
+
240
+ const keys = Object.keys(manifest)
241
+ if (keys.length === 0) {
242
+ throw new Error('invalide manifest.json')
243
+ }
244
+
245
+ const slug = keys[0]
246
+
247
+ // console.log('Publish Surph tool: ' + JSON.stringify(manifest[slug]))
248
+
249
+ const url = `${SURPH_REST_URL}/rest/tool?slug=${slug}`
250
+ let resp = await fetch(url, {
251
+ method: 'GET',
252
+ headers: {
253
+ Accept: 'application/json',
254
+ 'x-surph-client': 'surph-sdk'
255
+ }
256
+ })
257
+
258
+ const { payload } = await resp.json()
259
+
260
+ // tool not registered yet, create:
261
+ if (payload.length === 0) {
262
+ const resp = await fetch(url, {
263
+ method: 'POST',
264
+ body: JSON.stringify(manifest[slug]),
265
+ headers: {
266
+ Accept: 'application/json',
267
+ 'Content-Type': 'application/json',
268
+ 'x-surph-client': 'surph-sdk'
269
+ }
270
+ })
271
+
272
+ const { payload } = await resp.json()
273
+ console.log('\nSurph tool registered: ' + JSON.stringify(payload))
274
+ return
275
+ }
276
+
277
+ resp = await fetch(`${SURPH_REST_URL}/rest/tool/${payload[0]._id}`, {
278
+ method: 'PUT',
279
+ body: JSON.stringify(manifest[slug]),
280
+ headers: {
281
+ Accept: 'application/json',
282
+ 'Content-Type': 'application/json',
283
+ 'x-surph-client': 'surph-sdk'
284
+ }
285
+ })
286
+
287
+ const data = await resp.json()
288
+ console.log('\nSurph tool updated: ' + JSON.stringify(data.payload))
289
+
290
+
291
+ } catch (error) {
292
+
293
+ }
294
+ })
295
+
227
296
 
228
297
  program.command('deploy')
229
- .option('-t, --type <default_or_static>', 'deployment type | static or default', 'default') // https://www.npmjs.com/package/commander#default-option-value
230
298
  .description('Deploy to Surph')
231
299
  .action(async (cmd, options) => {
232
300
  try {
301
+ /*
233
302
  const { type } = cmd
234
303
  if (type !== 'default' && type !== 'static') {
235
304
  const msg = colors.red(`\nError: Invalid deployment type ${type}.\n`) +
@@ -243,16 +312,9 @@ program.command('deploy')
243
312
  ERRORS.NOT_LOGGED_IN);
244
313
  }
245
314
 
246
- const {
247
- TURBO_PROJECT = null,
248
- TURBO_PROJECT_SLUG = null
249
- } = dotenv.parse(utils.readFile('.env') ?? '')
250
-
251
- if (TURBO_PROJECT === null || TURBO_PROJECT_SLUG === null) {
252
- program.error('Surph project not connected. To connect, run:\n\n$ vly connect',
253
- ERRORS.PROJECT_NOT_CONNECTED)
254
- }
315
+ */
255
316
 
317
+ /*
256
318
  const apps = await Realm.restQuery('project', 'get', { slug: TURBO_PROJECT_SLUG })
257
319
  if (apps.length === 0) {
258
320
  program.error(`App ${TURBO_PROJECT} not found.`, ERRORS.PROJECT_NOT_FOUND)
@@ -262,14 +324,15 @@ program.command('deploy')
262
324
  if (!members.find(member => (member.id === user.id))) {
263
325
  program.error('Unauthorized', ERRORS.NOT_AUTHORIZED)
264
326
  }
327
+ */
265
328
 
266
- // console.log('DEPLOY: ' + type)
267
- // if (type === 'static') {
268
- // await deploy.static({ TURBO_PROJECT_SLUG })
269
- // return
270
- // }
329
+ const { SURPH_TOOL = null } = dotenv.parse(utils.readFile('.env') ?? '')
330
+
331
+ if (SURPH_TOOL === null) {
332
+ program.error('Surph project not connected. To connect, run:\n\n$ surph connect', ERRORS.PROJECT_NOT_CONNECTED)
333
+ }
271
334
 
272
- await deploy.project({ TURBO_PROJECT_SLUG })
335
+ await deploy.tool({ SURPH_TOOL_SLUG: SURPH_TOOL })
273
336
  } catch (error) {
274
337
  utils.printError(error)
275
338
  program.error(`Unexpected error: ${error}`, ERRORS.UNSPECIFIED)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@surph_ai/sdk",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -18,18 +18,17 @@
18
18
  "dependencies": {
19
19
  "@aws-sdk/client-bedrock-runtime": "^3.1096.0",
20
20
  "adm-zip": "^0.5.10",
21
- "axios": "^1.12.2",
22
21
  "bestzip": "^2.2.1",
23
22
  "cheerio": "^1.2.0",
24
23
  "colors": "^1.4.0",
25
- "cookie": "^0.5.0",
26
24
  "commander": "^14.0.1",
25
+ "cookie": "^0.5.0",
27
26
  "cors": "^2.8.6",
28
27
  "dotenv": "^16.0.3",
29
28
  "express": "^4.18.1",
30
29
  "impit": "^0.14.0",
30
+ "mustache": "^4.2.0",
31
31
  "prompt": "^1.3.0",
32
- "shelljs": "^0.8.5",
33
- "mustache": "^4.2.0"
32
+ "shelljs": "^0.8.5"
34
33
  }
35
34
  }
package/scaffold/index.js CHANGED
@@ -100,17 +100,17 @@ module.exports = (name, type = 'app') => {
100
100
  } , null, 2) + '\n')
101
101
 
102
102
  const slug = slugify(name, 8)
103
- const manifest = {
104
- slug: {
105
- name,
106
- slug,
107
- type: 'custom',
108
- description: '',
109
- parameters: {
110
- type: "object",
111
- properties: {},
112
- required: []
113
- }
103
+
104
+ const manifest = {}
105
+ manifest[slug] = {
106
+ name,
107
+ slug,
108
+ type: 'custom',
109
+ description: '',
110
+ parameters: {
111
+ type: "object",
112
+ properties: {},
113
+ required: []
114
114
  }
115
115
  }
116
116
 
@@ -1,17 +1,18 @@
1
1
  {
2
- "name": "base-template",
2
+ "name": "tool-template",
3
3
  "version": "0.0.0",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "surph toolserver & surph chatserver",
7
- "test": "",
8
- "build": ""
7
+ "deploy": "surph deploy",
8
+ "build": "",
9
+ "test": ""
9
10
  },
10
11
  "dependencies": {
11
- "@surph_ai/sdk": "latest",
12
12
  "@vinely-ai/sdk": "^0.0.6"
13
13
  },
14
14
  "devDependencies": {
15
+ "@surph_ai/sdk": "latest",
15
16
  "nodemon": "^2.0.2"
16
17
  }
17
18
  }
@@ -3,6 +3,6 @@
3
3
 
4
4
  module.exports = {
5
5
  demo: (args) => {
6
- return `this is a sample tool: ${JSON.stringify(args)}`
6
+ return `This is a sample tool: ${JSON.stringify(args)}. Remove this tool and replace it with your own.`
7
7
  }
8
8
  }
@@ -12,10 +12,15 @@ const handler = async (args, tool) => {
12
12
  } catch (error) {
13
13
  errorMsg = error instanceof Error ? error.message : String(error)
14
14
  } finally {
15
- return {
16
- success: errorMsg === null ? true : false,
17
- payload
18
- }
15
+ const resp = { success: errorMsg === null ? true : false }
16
+
17
+ if (payload)
18
+ resp.payload = payload
19
+
20
+ if (errorMsg !== null)
21
+ resp.error = errorMsg
22
+
23
+ return resp
19
24
  }
20
25
  }
21
26
 
@@ -34,12 +39,12 @@ router.get('/', async (req, res, next) => {
34
39
 
35
40
  router.get('/:tool', async (req, res, next) => {
36
41
  try {
37
- const tool = tools[req.params.tool]
38
- if (!tool) {
39
- throw new Error(`Tool ${req.params.tool} not found.`)
40
- }
42
+ // const tool = tools[req.params.tool]
43
+ // if (!tool) {
44
+ // throw new Error(`Tool ${req.params.tool} not found.`)
45
+ // }
41
46
 
42
- const response = await handler(req.query, tool)
47
+ const response = await handler(req.query, tools)
43
48
  res.json({ response })
44
49
  } catch (error) {
45
50
  res.json({
@@ -53,19 +58,16 @@ router.get('/:tool', async (req, res, next) => {
53
58
 
54
59
  router.post('/custom', async (req, res, next) => {
55
60
  // console.log('TOOL CALL: ' + JSON.stringify(req.body))
56
- // {"name":"youtube-transcript","args":{"video":"m7kw0AhrMvQ"},"tool":{"name":"youtube-transcript","slug":"y2script","type":"custom","description":"Fetch the plain-text transcript (spoken words) of a YouTube video. Use this whenever the user asks about, quotes from, summarizes, or wants to search inside the content of a YouTube video — including questions like \"what does this video say about X\", \"summarize this video\", \"pull the transcript\", or when the user pastes a YouTube URL and expects you to know its contents. Do NOT use this for general video metadata (title, channel, view count) or for non-YouTube videos.","parameters":{"type":"object","properties":{"video":{"type":"string","description":"The YouTube video to transcribe. Accepts either a full URL (e.g. \"https://www.youtube.com/watch?v=EwusdkKUlwI\", \"https://youtu.be/EwusdkKUlwI\") or the bare 11-character video id (e.g. \"EwusdkKUlwI\"). Extract this from the user's message when they paste a link."}},"required":["video"]}},"user":{"id":"6a3d402f0817076e079e7398","username":"dkwon"}}
57
-
58
61
  try {
59
62
  const { name, args, tool, user = null } = req.body;
60
- console.log('TOOL CALL: ' + name)
63
+ // console.log('TOOL CALL: ' + name)
61
64
  // console.log('TOOL ARGS: ' + JSON.stringify(args))
62
65
 
63
- const _tool = tools[tool.slug]
64
- if (!_tool) {
65
- throw new Error(`Tool ${tool.name} not found.`)
66
+ if (process.env.SURPH_TOOL !== tool.slug) {
67
+ throw new Error(`Invalid tool ${tool.slug}. Check .env file.`)
66
68
  }
67
69
 
68
- const response = await handler(args, _tool)
70
+ const response = await handler(args, tools)
69
71
  // console.log('TOOL RESP: ' + JSON.stringify(response))
70
72
  res.json({ response })
71
73
  } catch (error) {
package/utils/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const fs = require('fs')
2
2
  const colors = require('colors/safe')
3
- // const superagent = require('superagent')
4
3
  const dotenv = require('dotenv')
5
4
  const MODE_0666 = parseInt('0666', 8)
6
5
 
@@ -1 +0,0 @@
1
- lts/jod
@@ -1,30 +0,0 @@
1
- # base-template
2
-
3
- This project was built with Vertex Labs. To learn more, click here: https://www.vtxlabs.io
4
-
5
- ## Instructions
6
- After cloning into repo, cd to project root directory and install dependencies:
7
-
8
- ```
9
- $ npm install
10
- ```
11
-
12
- To run dev server, install Nodemon library globally:
13
-
14
- ```
15
- $ sudo npm install nodemon -g
16
- ```
17
-
18
- Then run devserver from project root directory:
19
-
20
- ```
21
- $ nodemon
22
- ```
23
-
24
- Open browser to:
25
-
26
- ```
27
- http://localhost:3000
28
- ```
29
-
30
- Profit!
@@ -1,5 +0,0 @@
1
- import turbo from '@turbo360/turbo-sdk'
2
- import server from './build/server/index.js'
3
-
4
- const entry = turbo.entry(() => server)
5
- export { entry }
@@ -1 +0,0 @@
1
- declare module '@turbo360/turbo-sdk';