Skip to content

Commit

Permalink
Merge pull request #53 from polywrap/nerfzael-json5
Browse files Browse the repository at this point in the history
Using json5 for parsing arguments
  • Loading branch information
dOrgJelli authored Aug 21, 2023
2 parents 8979acd + 135af9b commit fac316a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
},
"dependencies": {
"@polywrap/client-js": "~0.12.0",
"@polywrap/result": "~0.12.0",
"@polywrap/sys-config-bundle-js": "~0.12.0",
"@polywrap/web3-config-bundle-js": "~0.12.0",
"@polywrap/result": "~0.12.0",
"axios": "^0.26.0",
"figlet": "~1.6.0",
"fuse.js": "^6.6.2",
"json5": "^2.2.3",
"openai": "~3.3.0",
"path-browserify": "1.0.1"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/agents/agent-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Scripts } from "../Scripts";
import { WrapClient } from "../wrap";
import { LlmApi, Chat } from "../llm";
import { trimText } from "./utils";
import JSON5 from "json5";

export interface AgentContext {
globals: Record<string, string>;
Expand Down Expand Up @@ -98,7 +99,7 @@ function processFunctionAndArgs(
let fnArgs;
try {
fnArgs = args
? JSON.parse(args)
? JSON5.parse(args)
: undefined;
} catch(err: any) {
return ResultErr(UNPARSABLE_FUNCTION_ARGS(name, args, err));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
JsEngine_Module,
shimCode
} from "../../../wrap";
import JSON5 from "json5";

export const executeScript: AgentFunction = {
definition: {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const executeScript: AgentFunction = {
args = options.arguments.replace(/\{\{/g, "\\{\\{").replace(/\}\}/g, "\\}\\}");
try {

args = JSON.parse(options.arguments);
args = JSON5.parse(options.arguments);

if (args) {
const replaceVars = (str: string, vars: any) => {
Expand Down

0 comments on commit fac316a

Please sign in to comment.