From 135af9b754f8aaf2997f5c79a0798659dbc15837 Mon Sep 17 00:00:00 2001 From: nerfZael Date: Mon, 21 Aug 2023 11:20:57 +0200 Subject: [PATCH] using json5 for parsing arguments --- packages/core/package.json | 3 ++- packages/core/src/agents/agent-function.ts | 3 ++- packages/core/src/agents/evo/agent-functions/executeScript.ts | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 7aba6148..b7c09011 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -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" }, diff --git a/packages/core/src/agents/agent-function.ts b/packages/core/src/agents/agent-function.ts index ecb9e712..d8882260 100644 --- a/packages/core/src/agents/agent-function.ts +++ b/packages/core/src/agents/agent-function.ts @@ -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; @@ -97,7 +98,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)); diff --git a/packages/core/src/agents/evo/agent-functions/executeScript.ts b/packages/core/src/agents/evo/agent-functions/executeScript.ts index 52c5291b..100ac1a3 100644 --- a/packages/core/src/agents/evo/agent-functions/executeScript.ts +++ b/packages/core/src/agents/evo/agent-functions/executeScript.ts @@ -4,6 +4,7 @@ import { JsEngine_Module, shimCode } from "../../../wrap"; +import JSON5 from "json5"; export const executeScript: AgentFunction = { definition: { @@ -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) => {