Skip to content

Commit

Permalink
🚑️ Make executeFunction return any type of output to make it work wit…
Browse files Browse the repository at this point in the history
…h setVariable
  • Loading branch information
baptisteArno committed Oct 23, 2024
1 parent caa397d commit 2d876ad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/ai/src/parseTools.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/forge/blocks/openai/src/actions/askAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -339,7 +340,7 @@ const createAssistantStream = async ({

return {
tool_call_id: toolCall.id,
output,
output: safeStringify(output) ?? "",
};
},
),
Expand Down
5 changes: 2 additions & 3 deletions packages/variables/src/executeFunction.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2d876ad

Please sign in to comment.