gptscript-ai / desktop

MIT License
19 stars 13 forks source link

UI -Not able to execute tools with inline js code. #163

Open sangee2004 opened 1 month ago

sangee2004 commented 1 month ago

Electron dev build with commit id - 6e2f8ed99637f9

Steps to reproduce the problem:

  1. Create an assistant with tool that has inline node code.
  2. Run this assistant Following error is seen:
Screenshot 2024-08-07 at 2 51 09 PM

Following is the assistant that was generated when creating the tool:

Name: sangeetestnewagent
Type: Tool
Tools: json-query
Chat: true

You are a good assistant wait for user to ask you a question

---
Name: json-query
Type: Tool

#!node
const jq = require('node-jq');
// Simple argument parsing function
function parseArgs() {
    const args = {};
    process.argv.slice(2).forEach((val, index, array) => {
        if (val.startsWith('--')) {
            const argName = val.substring(2);
            // Check if we are not at the last element and the next element doesn't start with '--'
            if (index < array.length - 1 && !array[index + 1].startsWith('--')) {
                // Directly assign the following value to the argument
                args[argName] = array[index + 1];
            }
        }
    });
    return args;
}

const args = parseArgs();

// Fallback to default values if arguments not provided
const filter = args.filter || '.';
const jsonPath = args.jsonpath;
const options = {
    input: 'file',
    output: 'json',
    slurp: args.optionSlurp === 'true'
};

jq.run(filter, jsonPath, options)
    .then((output) => {
        console.log(output);
    })
    .catch((err) => {
        console.error(err);
    });

---
!metadata:json-query:package.json
{
  "name": "jq",
  "version": "0.0.1",
  "description": "gptscript jq tool",
  "main": "jq.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "cloudnautique",
  "license": "MIT",
  "dependencies": {
    "node-jq": "^4.3.0"
  },
  "devDependencies": {}
}
tylerslaton commented 1 month ago

@sangee2004 This should now be fixed. Can you give it another try?

tylerslaton commented 1 week ago

@sangee2004 Why was this issue reopened?