@copilotkit/react-core 1.51.3-next.7 → 1.51.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-BUSWSDYO.mjs → chunk-7JTI6ZL4.mjs} +2 -2
  3. package/dist/{chunk-GPEJNVE5.mjs → chunk-RBGVEVWY.mjs} +2 -2
  4. package/dist/{chunk-E7SE25ZU.mjs → chunk-SRJT5VVY.mjs} +2 -2
  5. package/dist/{chunk-CDUIA2WM.mjs → chunk-VGL3DGUW.mjs} +16 -13
  6. package/dist/chunk-VGL3DGUW.mjs.map +1 -0
  7. package/dist/hooks/index.js +14 -11
  8. package/dist/hooks/index.js.map +1 -1
  9. package/dist/hooks/index.mjs +4 -4
  10. package/dist/hooks/use-copilot-action.js +14 -11
  11. package/dist/hooks/use-copilot-action.js.map +1 -1
  12. package/dist/hooks/use-copilot-action.mjs +2 -2
  13. package/dist/hooks/use-copilot-authenticated-action.js +14 -11
  14. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  15. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  16. package/dist/hooks/use-default-tool.js +14 -11
  17. package/dist/hooks/use-default-tool.js.map +1 -1
  18. package/dist/hooks/use-default-tool.mjs +3 -3
  19. package/dist/hooks/use-frontend-tool.js +14 -11
  20. package/dist/hooks/use-frontend-tool.js.map +1 -1
  21. package/dist/hooks/use-frontend-tool.mjs +1 -1
  22. package/dist/index.js +14 -11
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +4 -4
  25. package/dist/index.umd.js +39 -0
  26. package/dist/index.umd.js.map +1 -0
  27. package/dist/setupTests.js +2 -0
  28. package/dist/setupTests.js.map +1 -1
  29. package/dist/setupTests.mjs +2 -0
  30. package/dist/setupTests.mjs.map +1 -1
  31. package/dist/v2/index.umd.js +2 -0
  32. package/dist/v2/index.umd.js.map +1 -0
  33. package/package.json +10 -8
  34. package/rollup.config.mjs +92 -0
  35. package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +92 -0
  36. package/src/hooks/use-frontend-tool.ts +20 -14
  37. package/src/setupTests.ts +3 -0
  38. package/dist/chunk-CDUIA2WM.mjs.map +0 -1
  39. /package/dist/{chunk-BUSWSDYO.mjs.map → chunk-7JTI6ZL4.mjs.map} +0 -0
  40. /package/dist/{chunk-GPEJNVE5.mjs.map → chunk-RBGVEVWY.mjs.map} +0 -0
  41. /package/dist/{chunk-E7SE25ZU.mjs.map → chunk-SRJT5VVY.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # ui
2
2
 
3
+ ## 1.51.3
4
+
5
+ ### Patch Changes
6
+
7
+ - d655e75: fix: update ag-ui dependencies
8
+ - d36fc1e: Add UMD export
9
+ - e89fe98: fix(v1.x): address issue causing onSubmitMessage to fire after agent response
10
+ - 3f00a01: Fix issue causing onSubmitMessage to fire after agent response
11
+ - Updated dependencies [d655e75]
12
+ - Updated dependencies [d36fc1e]
13
+ - @copilotkit/shared@1.51.3
14
+ - @copilotkit/runtime-client-gql@1.51.3
15
+ - @copilotkitnext/react@1.51.3
16
+ - @copilotkitnext/core@1.51.3
17
+
18
+ ## 1.51.3-next.8
19
+
20
+ ### Patch Changes
21
+
22
+ - d36fc1e: Add UMD export
23
+ - Updated dependencies [d36fc1e]
24
+ - @copilotkit/runtime-client-gql@1.51.3-next.8
25
+ - @copilotkit/shared@1.51.3-next.8
26
+ - @copilotkitnext/react@1.51.3-next.8
27
+ - @copilotkitnext/core@1.51.3-next.8
28
+
3
29
  ## 1.51.3-next.7
4
30
 
5
31
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotAction
3
- } from "./chunk-GPEJNVE5.mjs";
3
+ } from "./chunk-RBGVEVWY.mjs";
4
4
  import {
5
5
  __spreadProps,
6
6
  __spreadValues
@@ -14,4 +14,4 @@ function useDefaultTool(tool, dependencies) {
14
14
  export {
15
15
  useDefaultTool
16
16
  };
17
- //# sourceMappingURL=chunk-BUSWSDYO.mjs.map
17
+ //# sourceMappingURL=chunk-7JTI6ZL4.mjs.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-NBK4KBLX.mjs";
4
4
  import {
5
5
  useFrontendTool
6
- } from "./chunk-CDUIA2WM.mjs";
6
+ } from "./chunk-VGL3DGUW.mjs";
7
7
  import {
8
8
  useHumanInTheLoop
9
9
  } from "./chunk-7DTB7S5V.mjs";
@@ -77,4 +77,4 @@ function useCopilotAction(action, dependencies) {
77
77
  export {
78
78
  useCopilotAction
79
79
  };
80
- //# sourceMappingURL=chunk-GPEJNVE5.mjs.map
80
+ //# sourceMappingURL=chunk-RBGVEVWY.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotAction
3
- } from "./chunk-GPEJNVE5.mjs";
3
+ } from "./chunk-RBGVEVWY.mjs";
4
4
  import {
5
5
  useCopilotContext
6
6
  } from "./chunk-AFNWX62Q.mjs";
@@ -56,4 +56,4 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
56
56
  export {
57
57
  useCopilotAuthenticatedAction_c
58
58
  };
59
- //# sourceMappingURL=chunk-E7SE25ZU.mjs.map
59
+ //# sourceMappingURL=chunk-SRJT5VVY.mjs.map
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-SKC7AJIV.mjs";
5
5
 
6
6
  // src/hooks/use-frontend-tool.ts
7
- import React, { useEffect, useRef } from "react";
7
+ import React, { useEffect, useMemo, useRef } from "react";
8
8
  import { getZodParameters } from "@copilotkit/shared";
9
9
  import { parseJson } from "@copilotkit/shared";
10
10
  import {
@@ -13,29 +13,32 @@ import {
13
13
  function useFrontendTool(tool, dependencies) {
14
14
  const { name, description, parameters, render, followUp } = tool;
15
15
  const zodParameters = getZodParameters(parameters);
16
- const normalizedRender = (() => {
16
+ const renderRef = useRef(render);
17
+ useEffect(() => {
18
+ renderRef.current = render;
19
+ }, [render, ...dependencies != null ? dependencies : []]);
20
+ const normalizedRender = useMemo(() => {
17
21
  if (typeof render === "undefined") {
18
22
  return void 0;
19
23
  }
20
- if (typeof render === "string") {
21
- const staticRender = render;
22
- return () => React.createElement(
23
- React.Fragment,
24
- null,
25
- staticRender
26
- );
27
- }
28
24
  return (args) => {
25
+ const currentRender = renderRef.current;
26
+ if (typeof currentRender === "undefined") {
27
+ return null;
28
+ }
29
+ if (typeof currentRender === "string") {
30
+ return React.createElement(React.Fragment, null, currentRender);
31
+ }
29
32
  const renderArgs = __spreadProps(__spreadValues({}, args), {
30
33
  result: typeof args.result === "string" ? parseJson(args.result, args.result) : args.result
31
34
  });
32
- const rendered = render(renderArgs);
35
+ const rendered = currentRender(renderArgs);
33
36
  if (typeof rendered === "string") {
34
37
  return React.createElement(React.Fragment, null, rendered);
35
38
  }
36
39
  return rendered != null ? rendered : null;
37
40
  };
38
- })();
41
+ }, []);
39
42
  const handlerRef = useRef(tool.handler);
40
43
  useEffect(() => {
41
44
  handlerRef.current = tool.handler;
@@ -57,4 +60,4 @@ function useFrontendTool(tool, dependencies) {
57
60
  export {
58
61
  useFrontendTool
59
62
  };
60
- //# sourceMappingURL=chunk-CDUIA2WM.mjs.map
63
+ //# sourceMappingURL=chunk-VGL3DGUW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-frontend-tool.ts"],"sourcesContent":["import React, { useEffect, useMemo, useRef } from \"react\";\nimport { ActionRenderProps, FrontendAction } from \"../types/frontend-action\";\nimport { Parameter, getZodParameters, MappedParameterTypes } from \"@copilotkit/shared\";\nimport { parseJson } from \"@copilotkit/shared\";\nimport { ToolCallStatus } from \"@copilotkitnext/core\";\nimport {\n type ReactFrontendTool,\n useFrontendTool as useFrontendToolVNext,\n} from \"@copilotkitnext/react\";\n\ntype FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<MappedParameterTypes<T>>;\ntype FrontendToolRenderArgs<T extends Parameter[] | []> =\n | {\n name: string;\n args: Partial<MappedParameterTypes<T>>;\n status: ToolCallStatus.InProgress;\n result: undefined;\n }\n | {\n name: string;\n args: MappedParameterTypes<T>;\n status: ToolCallStatus.Executing;\n result: undefined;\n }\n | {\n name: string;\n args: MappedParameterTypes<T>;\n status: ToolCallStatus.Complete;\n result: string;\n };\n\nexport type UseFrontendToolArgs<T extends Parameter[] | [] = []> = {\n available?: \"disabled\" | \"enabled\";\n} & Pick<\n FrontendAction<T>,\n \"name\" | \"description\" | \"parameters\" | \"handler\" | \"followUp\" | \"render\"\n>;\n\nexport function useFrontendTool<const T extends Parameter[] = []>(\n tool: UseFrontendToolArgs<T>,\n dependencies?: any[],\n) {\n const { name, description, parameters, render, followUp } = tool;\n const zodParameters = getZodParameters(parameters);\n\n const renderRef = useRef<typeof render>(render);\n\n useEffect(() => {\n renderRef.current = render;\n }, [render, ...(dependencies ?? [])]);\n\n const normalizedRender: FrontendToolOptions<T>[\"render\"] | undefined = useMemo(() => {\n if (typeof render === \"undefined\") {\n return undefined;\n }\n\n return ((args: FrontendToolRenderArgs<T>) => {\n const currentRender = renderRef.current;\n\n if (typeof currentRender === \"undefined\") {\n return null;\n }\n\n if (typeof currentRender === \"string\") {\n return React.createElement(React.Fragment, null, currentRender);\n }\n\n const renderArgs = {\n ...args,\n result: typeof args.result === \"string\" ? parseJson(args.result, args.result) : args.result,\n } as ActionRenderProps<T>;\n\n const rendered = currentRender(renderArgs);\n\n if (typeof rendered === \"string\") {\n return React.createElement(React.Fragment, null, rendered);\n }\n\n return rendered ?? null;\n }) as FrontendToolOptions<T>[\"render\"];\n }, []);\n\n // Handler ref to avoid stale closures\n const handlerRef = useRef<typeof tool.handler>(tool.handler);\n\n useEffect(() => {\n handlerRef.current = tool.handler;\n }, [tool.handler, ...(dependencies ?? [])]);\n\n const normalizedHandler = tool.handler\n ? (args: MappedParameterTypes<T>) => handlerRef.current?.(args)\n : undefined;\n\n useFrontendToolVNext<MappedParameterTypes<T>>({\n name,\n description,\n parameters: z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A+B;AA1FtC;AA0FyC,4BAAW,YAAX,oCAAqB;AAAA,MACxD;AAEJ,uBAA8C;AAAA,IAC5C;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ,SAAS;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,EACV,CAAC;AACH;","names":[]}
@@ -1377,29 +1377,32 @@ var import_react18 = require("@copilotkitnext/react");
1377
1377
  function useFrontendTool(tool, dependencies) {
1378
1378
  const { name, description, parameters, render, followUp } = tool;
1379
1379
  const zodParameters = (0, import_shared6.getZodParameters)(parameters);
1380
- const normalizedRender = (() => {
1380
+ const renderRef = (0, import_react17.useRef)(render);
1381
+ (0, import_react17.useEffect)(() => {
1382
+ renderRef.current = render;
1383
+ }, [render, ...dependencies != null ? dependencies : []]);
1384
+ const normalizedRender = (0, import_react17.useMemo)(() => {
1381
1385
  if (typeof render === "undefined") {
1382
1386
  return void 0;
1383
1387
  }
1384
- if (typeof render === "string") {
1385
- const staticRender = render;
1386
- return () => import_react17.default.createElement(
1387
- import_react17.default.Fragment,
1388
- null,
1389
- staticRender
1390
- );
1391
- }
1392
1388
  return (args) => {
1389
+ const currentRender = renderRef.current;
1390
+ if (typeof currentRender === "undefined") {
1391
+ return null;
1392
+ }
1393
+ if (typeof currentRender === "string") {
1394
+ return import_react17.default.createElement(import_react17.default.Fragment, null, currentRender);
1395
+ }
1393
1396
  const renderArgs = __spreadProps(__spreadValues({}, args), {
1394
1397
  result: typeof args.result === "string" ? (0, import_shared7.parseJson)(args.result, args.result) : args.result
1395
1398
  });
1396
- const rendered = render(renderArgs);
1399
+ const rendered = currentRender(renderArgs);
1397
1400
  if (typeof rendered === "string") {
1398
1401
  return import_react17.default.createElement(import_react17.default.Fragment, null, rendered);
1399
1402
  }
1400
1403
  return rendered != null ? rendered : null;
1401
1404
  };
1402
- })();
1405
+ }, []);
1403
1406
  const handlerRef = (0, import_react17.useRef)(tool.handler);
1404
1407
  (0, import_react17.useEffect)(() => {
1405
1408
  handlerRef.current = tool.handler;