@copilotkit/react-native 1.71.2 → 1.72.0

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.
@@ -108,12 +108,11 @@ const ALLOWED_REACT_CORE_ENTRIES = [
108
108
  * were that `useComponent` (which registers into core's registry) rendered
109
109
  * nowhere on RN, and that renderers vanished from chat history on unmount.
110
110
  *
111
- * Paired with the delegation test below, this is the replacement for the
112
- * `useRenderTool` identity assertion: identity cannot police a deprecated shim
113
- * that is RN's own binding by construction, but "RN owns no registry" and "the
114
- * shim delegates" together catch everything identity caught — a local hook
115
- * re-grown under the name has to either write to a registry itself (caught
116
- * here) or stop calling core's hooks (caught there).
111
+ * This sits alongside the two identity assertions below rather than behind
112
+ * them. Identity pins what `useFrontendTool` and `useRenderTool` ARE; this pins
113
+ * that nothing ELSE in the graph has grown a registry to compete with core's —
114
+ * a component, a provider, a helper module that never touches either hook's
115
+ * name and would therefore pass identity untouched.
117
116
  */
118
117
  const FORBIDDEN_REGISTRY_APIS: readonly (readonly [
119
118
  identifier: string,
@@ -635,11 +634,9 @@ describe("@copilotkit/react-native/headless entry", () => {
635
634
  // (src/hooks/__tests__/useRenderTool.test.tsx pins the behaviour; this pins
636
635
  // the wiring).
637
636
  //
638
- // `useRenderTool` is currently a deprecated compatibility SHIM (removal
639
- // scheduled for the next minor), so its binding is RN's own by
640
- // construction and identity cannot be the instrument. The tests below
641
- // carry that half instead, deliberately at equal strength: the shim must
642
- // DELEGATE, and no module in this entry's graph may own a registry.
637
+ // PR #6533 converged both names onto react-core behind a temporary
638
+ // routing shim, during which this half of the assertion could not be
639
+ // identity; #6976 removed the shim and the test below is identity again.
643
640
  expect(
644
641
  mod.useFrontendTool,
645
642
  "`useFrontendTool` on the RN headless entry is NOT the binding from " +
@@ -649,27 +646,23 @@ describe("@copilotkit/react-native/headless entry", () => {
649
646
  ).toBe(coreHeadless.useFrontendTool);
650
647
  });
651
648
 
652
- it("`useRenderTool` is core's hook, or a shim that DELEGATES to core's hooks", () => {
653
- // The replacement for the `useRenderTool` half of the identity assertion
654
- // above, at equal strength and with the same target: RN must never own a
655
- // render-tool implementation, whatever the export is called.
649
+ it("exports react-core's `useRenderTool` ITSELF, not an RN copy of it", () => {
650
+ // The other half of the identity assertion above, and the one with the
651
+ // history. RN's local `useRenderTool` forwarded its whole body to core's
652
+ // `useFrontendTool`, so `name: "*"` registered a frontend tool literally
653
+ // named `*` — core's catch-all HANDLER name — and a display-only wildcard
654
+ // auto-answered every otherwise-unanswered tool call with an empty tool
655
+ // result and asked for a follow-up turn. Both names were present through
656
+ // that entire period, so every presence check above stayed green while
657
+ // verifying nothing about which hook a consumer gets.
656
658
  //
657
- // Two admissible states, and the guard picks its instrument from the entry
658
- // source rather than being told which world it is in:
659
- //
660
- // • the END STATE (shim removed): `headless.ts` re-exports the name
661
- // straight from `@copilotkit/react-core/v2/headless`, and this asserts
662
- // RUNTIME IDENTITY — the original assertion, unweakened;
663
- // • the SHIM STATE (now): the name comes from a local module, which must
664
- // import BOTH core hooks from core's headless entry and CALL both. A
665
- // local reimplementation — a hook that registers by itself instead of
666
- // forwarding — fails here, and so does a shim that quietly stops
667
- // delegating (the calls are what is asserted, not the imports alone).
668
- //
669
- // What this cannot see is WHICH core hook a given config reaches; that is
670
- // routing, and it is asserted against core's own observable state (getTool,
671
- // core.tools, the advertised tool list on a real run) in
672
- // src/hooks/__tests__/useRenderTool.test.tsx.
659
+ // Asserted TWICE, on purpose. Runtime identity is the claim; the source
660
+ // check is what keeps the failure legible, because a local module that
661
+ // re-exported core's binding unchanged today could grow a body tomorrow
662
+ // and the runtime assertion would only start failing then. Requiring the
663
+ // export to come straight from core's headless entry means an RN-local
664
+ // module cannot be introduced under this name at all — which is the state
665
+ // #6976 restored when it removed the compatibility shim.
673
666
  const source = fs.readFileSync(headlessEntry, "utf8");
674
667
  const from = reExportSpecifierOf(source, "useRenderTool");
675
668
  expect(
@@ -678,66 +671,19 @@ describe("@copilotkit/react-native/headless entry", () => {
678
671
  "this guard cannot tell what a consumer gets. If the export moved to " +
679
672
  "another form, teach `reExportSpecifierOf` about it.",
680
673
  ).not.toBeNull();
681
-
682
- if (from === CORE_HEADLESS) {
683
- expect(
684
- mod.useRenderTool,
685
- "`useRenderTool` on the RN headless entry is NOT the binding from " +
686
- `${CORE_HEADLESS}, though src/headless.ts re-exports it from there.`,
687
- ).toBe(coreHeadless.useRenderTool);
688
- return;
689
- }
690
-
691
- expect(
692
- from!.startsWith("."),
693
- `src/headless.ts re-exports \`useRenderTool\` from "${from}", which is ` +
694
- `neither ${CORE_HEADLESS} nor a local module. Only those two are ` +
695
- `admissible: anything else is an implementation RN does not control.`,
696
- ).toBe(true);
697
-
698
- const shimFile = resolveLocal(headlessEntry, from!);
699
- expect(
700
- shimFile,
701
- `cannot resolve the module "${from}" that src/headless.ts exports ` +
702
- `\`useRenderTool\` from`,
703
- ).not.toBeNull();
704
- // Non-vacuity: the deny-list test below reasons about this file too, so a
705
- // shim outside the walked graph would make both pass for the wrong reason.
706
674
  expect(
707
- rel(graphFor(headlessEntry).seen),
708
- `the shim module "${from}" is not in the walked headless graph`,
709
- ).toContain(path.relative(srcDir, shimFile!));
675
+ from,
676
+ `src/headless.ts re-exports \`useRenderTool\` from "${from}". It must ` +
677
+ `come straight from ${CORE_HEADLESS}: an RN-local module under this ` +
678
+ `name is what shipped the \`*\`-named-tool bug, and the temporary ` +
679
+ `shim that replaced it was removed in #6976.`,
680
+ ).toBe(CORE_HEADLESS);
710
681
 
711
- const shimSource = stripComments(fs.readFileSync(shimFile!, "utf8"));
712
- const { specs } = extractSpecs(shimSource);
713
682
  expect(
714
- specs,
715
- `${path.relative(srcDir, shimFile!)} does not import from ` +
716
- `${CORE_HEADLESS}, so it cannot be delegating to core's hooks — it is ` +
717
- `an RN-local implementation of \`useRenderTool\`.`,
718
- ).toContain(CORE_HEADLESS);
719
-
720
- // Both core hooks must be REACHED, not merely imported: the shim's whole
721
- // job is to route a legacy tool-shaped call to `useFrontendTool` and
722
- // everything else to core's `useRenderTool`. An import with no call site
723
- // is a shim that has stopped delegating.
724
- for (const hook of ["useRenderTool", "useFrontendTool"]) {
725
- const imported = new RegExp(
726
- `\\b${hook}\\b(?:\\s+as\\s+(\\w+))?[^;]*?from\\s*["'\`]${CORE_HEADLESS.replace(/[/.]/g, "\\$&")}["'\`]`,
727
- ).exec(shimSource);
728
- expect(
729
- imported,
730
- `${path.relative(srcDir, shimFile!)} does not import \`${hook}\` from ` +
731
- `${CORE_HEADLESS}. The shim must delegate BOTH routes to core.`,
732
- ).not.toBeNull();
733
- const localName = imported?.[1] ?? hook;
734
- expect(
735
- new RegExp(`\\b${localName}\\s*\\(`).test(shimSource),
736
- `${path.relative(srcDir, shimFile!)} imports \`${hook}\` (as ` +
737
- `\`${localName}\`) from ${CORE_HEADLESS} but never calls it. A shim ` +
738
- `that does not delegate registers nothing, or registers it itself.`,
739
- ).toBe(true);
740
- }
683
+ mod.useRenderTool,
684
+ "`useRenderTool` on the RN headless entry is NOT the binding from " +
685
+ `${CORE_HEADLESS}, though src/headless.ts re-exports it from there.`,
686
+ ).toBe(coreHeadless.useRenderTool);
741
687
  });
742
688
 
743
689
  it("no longer exports the removed registry hook or its provider", () => {
package/src/headless.ts CHANGED
@@ -119,25 +119,24 @@ export type {
119
119
  AgentCapabilities,
120
120
  } from "@ag-ui/client";
121
121
 
122
- // Render tool registration. `useRenderTool` is a TEMPORARY, deprecated
123
- // COMPATIBILITY SHIM over BOTH core hooks — routing rules and reasoning in
124
- // src/hooks/useRenderTool.ts — scheduled for removal in the next minor (tracked
125
- // in CopilotKit/CopilotKit#6976, Linear OSS-1148), after
126
- // which this line goes back to a plain re-export from
127
- // @copilotkit/react-core/v2/headless. Contract and migration notes:
128
- // /reference/react-native/hooks/useRenderTool.
122
+ // Render tool registration — react-core's hooks THEMSELVES, not RN copies.
123
+ //
124
+ // DO NOT reintroduce a LOCAL hook under either name. RN once shipped its own
125
+ // `useRenderTool` whose whole body forwarded to `useFrontendTool` — core's
126
+ // OTHER hook, wearing this one's name — so `name: "*"` registered a frontend
127
+ // tool literally called `*`. Core never advertised it (`buildFrontendTools`
128
+ // filters that name out), but `*` IS core's catch-all handler name: a
129
+ // display-only wildcard therefore auto-answered every otherwise-unanswered
130
+ // tool call with an empty tool result and asked for a follow-up turn.
129
131
  //
130
- // DO NOT reintroduce a LOCAL hook under either name. RN's old `useRenderTool`
131
- // forwarded its whole body to `useFrontendTool` — core's OTHER hook, wearing
132
- // this one's name — so `name: "*"` registered a frontend tool literally called
133
- // `*`. Core never advertised it (`buildFrontendTools` filters that name out),
134
- // but `*` IS core's catch-all handler name: a display-only wildcard therefore
135
- // auto-answered every otherwise-unanswered tool call with an empty tool result
136
- // and asked for a follow-up turn. The shim registers nothing itself: every
137
- // path delegates to a react-core hook, and
138
- // src/__tests__/headless-entry-surface.test.ts fails the build if any module in
139
- // this entry's graph grows a registry of its own.
140
- export { useRenderTool } from "./hooks/useRenderTool";
132
+ // PR #6533 converged both names onto react-core behind a temporary routing
133
+ // shim; #6976 removed the shim, so these are now plain re-exports and this
134
+ // package carries no render-tool implementation of its own.
135
+ // src/__tests__/headless-entry-surface.test.ts asserts runtime identity for
136
+ // both names and fails the build if any module in this entry's graph grows a
137
+ // registry. Contract and migration notes:
138
+ // /reference/react-native/hooks/useRenderTool.
139
+ export { useRenderTool } from "@copilotkit/react-core/v2/headless";
141
140
  export type { RenderToolProps } from "@copilotkit/react-core/v2/headless";
142
141
 
143
142
  // Render tool consumption. react-core's hook is platform-agnostic — it pulls no