Skip to content
Snippets Groups Projects
Unverified Commit b3681bf6 authored by Brian Peiris's avatar Brian Peiris Committed by GitHub
Browse files

fix: DataCloneError when using FunctionTool (#1037)

parent b548b144
No related branches found
No related tags found
No related merge requests found
---
"@llamaindex/core": patch
"llamaindex": patch
---
fix: DataCloneError when using FunctionTool
...@@ -105,9 +105,7 @@ export class CallbackManager { ...@@ -105,9 +105,7 @@ export class CallbackManager {
} }
queueMicrotask(() => { queueMicrotask(() => {
cbs.forEach((handler) => cbs.forEach((handler) =>
handler( handler(LlamaIndexCustomEvent.fromEvent(event, { ...detail })),
LlamaIndexCustomEvent.fromEvent(event, structuredClone(detail)),
),
); );
}); });
} }
......
...@@ -6,6 +6,9 @@ declare module "@llamaindex/core/global" { ...@@ -6,6 +6,9 @@ declare module "@llamaindex/core/global" {
test: { test: {
value: number; value: number;
}; };
functionTest: {
fn: ({ x }: { x: number }) => string;
};
} }
} }
...@@ -42,6 +45,25 @@ describe("event system", () => { ...@@ -42,6 +45,25 @@ describe("event system", () => {
expect(callback).toHaveBeenCalledTimes(1); expect(callback).toHaveBeenCalledTimes(1);
}); });
test("dispatch function tool event", async () => {
const testFunction = ({ x }: { x: number }) => `${x * 2}`;
let callback;
Settings.callbackManager.on(
"functionTest",
(callback = vi.fn((event) => {
const data = event.detail;
expect(data.fn).toBe(testFunction);
})),
);
Settings.callbackManager.dispatchEvent("functionTest", {
fn: testFunction,
});
expect(callback).toHaveBeenCalledTimes(0);
await new Promise((resolve) => process.nextTick(resolve));
expect(callback).toHaveBeenCalledTimes(1);
});
// rollup doesn't support decorators for now // rollup doesn't support decorators for now
// test('wrap event caller', async () => { // test('wrap event caller', async () => {
// class A { // class A {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment