🚑️ Make executeFunction return any type of output to make it work with setVariable
Some checks failed
Create Tag / create-tag (push) Has been cancelled
Deploy Partykit server / deploy (push) Has been cancelled

This commit is contained in:
Baptiste Arnaud 2024-10-23 14:28:59 +02:00
parent caa397d255
commit 2d876ad160
No known key found for this signature in database
3 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import type { VariableStore } from "@typebot.io/forge/types";
import { safeStringify } from "@typebot.io/lib/safeStringify";
import { isNotEmpty } from "@typebot.io/lib/utils";
import { executeFunction } from "@typebot.io/variables/executeFunction";
import type { Variable } from "@typebot.io/variables/schemas";
@ -27,7 +28,7 @@ export const parseTools = ({
body: tool.code!,
});
newVariables?.forEach((v) => variables.set(v.id, v.value));
return output;
return safeStringify(output) ?? "";
},
} satisfies CoreTool;
return acc;

View File

@ -4,6 +4,7 @@ import type {
LogsStore,
VariableStore,
} from "@typebot.io/forge/types";
import { safeStringify } from "@typebot.io/lib/safeStringify";
import { isDefined, isEmpty, isNotEmpty } from "@typebot.io/lib/utils";
import { executeFunction } from "@typebot.io/variables/executeFunction";
import { readDataStream } from "ai";
@ -339,7 +340,7 @@ const createAssistantStream = async ({
return {
tool_call_id: toolCall.id,
output,
output: safeStringify(output) ?? "",
};
},
),

View File

@ -1,4 +1,3 @@
import { safeStringify } from "@typebot.io/lib/safeStringify";
import { stringifyError } from "@typebot.io/lib/stringifyError";
import { isDefined } from "@typebot.io/lib/utils";
import ivm from "isolated-vm";
@ -74,9 +73,9 @@ export const executeFunction = async ({
);
try {
const output = await run(parsedBody);
const output: unknown = await run(parsedBody);
return {
output: safeStringify(output) ?? "",
output,
newVariables: Object.entries(updatedVariables)
.map(([name, value]) => {
const existingVariable = variables.find((v) => v.name === name);