@copilotkit/react-native 1.71.2 → 1.72.1-canary.sp-longthread-perf
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.
- package/USAGE.md +11 -12
- package/dist/CopilotKitProvider-Bpj5_ayo.mjs +118 -0
- package/dist/CopilotKitProvider-Bpj5_ayo.mjs.map +1 -0
- package/dist/CopilotKitProvider-DsAKy9gw.d.cts +67 -0
- package/dist/CopilotKitProvider-OJzclDZY.d.mts +67 -0
- package/dist/CopilotKitProvider-_pvFePrv.cjs +125 -0
- package/dist/CopilotKitProvider-_pvFePrv.cjs.map +1 -0
- package/dist/headless.cjs +8 -3
- package/dist/headless.d.cts +2 -2
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +8 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +5 -5
- package/src/__tests__/headless-entry-surface.test.ts +34 -88
- package/src/headless.ts +17 -18
- package/src/hooks/__tests__/useRenderTool.test.tsx +18 -480
- package/dist/useRenderTool-DFz206nL.d.cts +0 -149
- package/dist/useRenderTool-DsCxzyAP.d.mts +0 -149
- package/dist/useRenderTool-L3Rw6SYD.cjs +0 -298
- package/dist/useRenderTool-L3Rw6SYD.cjs.map +0 -1
- package/dist/useRenderTool-pLM3upcs.mjs +0 -285
- package/dist/useRenderTool-pLM3upcs.mjs.map +0 -1
- package/src/hooks/useRenderTool.ts +0 -501
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { act, render, waitFor } from "@testing-library/react";
|
|
3
|
-
import { describe, it, expect
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { AbstractAgent } from "@ag-ui/client";
|
|
6
6
|
import type { RunAgentParameters, RunAgentResult } from "@ag-ui/client";
|
|
@@ -12,14 +12,13 @@ import {
|
|
|
12
12
|
} from "../../headless";
|
|
13
13
|
import type { CopilotKitContextValue } from "../../headless";
|
|
14
14
|
import { TestCopilotKit } from "../../__mocks__/test-copilotkit";
|
|
15
|
-
import { __resetRenderToolShimWarnings } from "../useRenderTool";
|
|
16
15
|
|
|
17
16
|
/**
|
|
18
|
-
* `useRenderTool` on `@copilotkit/react-native`
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* `useRenderTool` on `@copilotkit/react-native` IS react-core's
|
|
18
|
+
* `useRenderTool` — a plain re-export from `src/headless.ts`, with no RN
|
|
19
|
+
* implementation behind it. That wiring is asserted structurally in
|
|
20
|
+
* `src/__tests__/headless-entry-surface.test.ts`; this file asserts the
|
|
21
|
+
* BEHAVIOUR a React Native consumer gets through that entry.
|
|
23
22
|
*
|
|
24
23
|
* ─── What this file is for ───────────────────────────────────────────────────
|
|
25
24
|
*
|
|
@@ -42,10 +41,11 @@ import { __resetRenderToolShimWarnings } from "../useRenderTool";
|
|
|
42
41
|
* otherwise-unanswered tool call with an EMPTY tool result and asked for
|
|
43
42
|
* another turn.
|
|
44
43
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* ever re-grew under this name: the
|
|
48
|
-
* renderer
|
|
44
|
+
* PR #6533 converged the name onto react-core behind a temporary routing shim;
|
|
45
|
+
* #6976 removed the shim. So the assertions below are the properties that would
|
|
46
|
+
* silently regress if a local implementation ever re-grew under this name: the
|
|
47
|
+
* wildcard must register no TOOL, only a renderer, and a named renderer must
|
|
48
|
+
* land in CORE's registry and advertise nothing.
|
|
49
49
|
*
|
|
50
50
|
* ─── Why nothing here is mocked ──────────────────────────────────────────────
|
|
51
51
|
*
|
|
@@ -314,156 +314,9 @@ describe("agentId on a render-only registration", () => {
|
|
|
314
314
|
});
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
-
// ─── The
|
|
317
|
+
// ─── The renderer-only registration path ─────────────────────────────────────
|
|
318
318
|
|
|
319
|
-
/**
|
|
320
|
-
* The three rules `src/hooks/useRenderTool.ts` implements, each asserted on
|
|
321
|
-
* core's OWN observable state rather than on a spy's call arguments:
|
|
322
|
-
*
|
|
323
|
-
* 1. `name === "*"` wins UNCONDITIONALLY -> core's `useRenderTool`
|
|
324
|
-
* (renderer-only, wildcard path), whatever else was supplied.
|
|
325
|
-
* 2. otherwise `handler` or `description` present -> core's `useFrontendTool`
|
|
326
|
-
* (tool AND renderer), which is what the old RN hook actually did.
|
|
327
|
-
* 3. otherwise -> core's `useRenderTool`.
|
|
328
|
-
*
|
|
329
|
-
* Rule 1 is the load-bearing one and it is deliberately not the obvious
|
|
330
|
-
* reading. The old RN hook made `description` REQUIRED, so every wildcard
|
|
331
|
-
* renderer anyone ever wrote carries the old tool fields; routing "has old
|
|
332
|
-
* fields" to `useFrontendTool` would recreate the `*`-named-tool bug for exactly
|
|
333
|
-
* the people who had tried hardest to use the wildcard.
|
|
334
|
-
*
|
|
335
|
-
* Each probe uses a tool name no other test in this file uses, because the
|
|
336
|
-
* shim's deprecation warning is deduped per tool name for the lifetime of the
|
|
337
|
-
* module.
|
|
338
|
-
*/
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Rule 1: a wildcard call carrying the OLD tool fields — the only shape the old
|
|
342
|
-
* hook's required `description` allowed.
|
|
343
|
-
*/
|
|
344
|
-
function LegacyWildcardProbe({ paints }: { paints: string }) {
|
|
345
|
-
useRenderTool(
|
|
346
|
-
{
|
|
347
|
-
name: "*",
|
|
348
|
-
description: "renders every tool call nothing else claims",
|
|
349
|
-
parameters: z.object({ anything: z.string() }),
|
|
350
|
-
handler: async () => "should never be registered, let alone run",
|
|
351
|
-
render: ({ name, status }) => <>{`legacy-wildcard|${name}|${status}`}</>,
|
|
352
|
-
},
|
|
353
|
-
[],
|
|
354
|
-
);
|
|
355
|
-
const renderToolCall = useRenderToolCall();
|
|
356
|
-
return <>{renderToolCall(renderOneCall(paints))}</>;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
describe('rule 1: `name: "*"` wins unconditionally', () => {
|
|
360
|
-
it("paints as a fallback renderer and registers NO tool named `*`", async () => {
|
|
361
|
-
// The regression rule 1 exists to prevent. Under the old hook this exact
|
|
362
|
-
// call shape registered a frontend tool literally named `*` — claiming
|
|
363
|
-
// core's catch-all HANDLER slot, so every otherwise-unanswered tool call
|
|
364
|
-
// got auto-answered with an empty tool result plus a follow-up turn.
|
|
365
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
366
|
-
const agent = new ToolListRecordingAgent();
|
|
367
|
-
|
|
368
|
-
const { container } = render(
|
|
369
|
-
<TestCopilotKit messages={[]} agent={agent}>
|
|
370
|
-
<CaptureCore into={coreRef} />
|
|
371
|
-
<LegacyWildcardProbe paints="someServerToolNobodyClaimed" />
|
|
372
|
-
</TestCopilotKit>,
|
|
373
|
-
);
|
|
374
|
-
const core = coreRef.current!;
|
|
375
|
-
|
|
376
|
-
// Half one: it still paints, as a FALLBACK — the tool call it renders has
|
|
377
|
-
// no renderer of its own.
|
|
378
|
-
await waitFor(() =>
|
|
379
|
-
expect(container.textContent).toBe(
|
|
380
|
-
"legacy-wildcard|someServerToolNobodyClaimed|inProgress",
|
|
381
|
-
),
|
|
382
|
-
);
|
|
383
|
-
expect(core.renderToolCalls.map((r) => r.name)).toContain("*");
|
|
384
|
-
|
|
385
|
-
// Half two: nothing named `*` is a TOOL. These two are the discriminating
|
|
386
|
-
// assertions — the tool registry is the thing rule 1 keeps clean, and
|
|
387
|
-
// mutating rule 1 kills exactly this pair.
|
|
388
|
-
expect(core.getTool({ toolName: "*" })).toBeUndefined();
|
|
389
|
-
expect(core.tools.map((t) => t.name)).not.toContain("*");
|
|
390
|
-
|
|
391
|
-
// Forward guard only, as in the sibling test above: `buildFrontendTools`
|
|
392
|
-
// already withholds `*`, so this recorded `[[]]` on `origin/main` too and
|
|
393
|
-
// cannot fail for the old defect. It pins that `*` stays unadvertisable.
|
|
394
|
-
await act(async () => {
|
|
395
|
-
await core.runAgent({ agent });
|
|
396
|
-
});
|
|
397
|
-
expect(agent.advertised).toEqual([[]]);
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Rule 2: the old tool-plus-renderer shape, under a real name.
|
|
403
|
-
*
|
|
404
|
-
* `handler` returns a value the test can observe through core's own execution
|
|
405
|
-
* path, because "the handler never runs again" is the silent half of the break
|
|
406
|
-
* this shim exists for.
|
|
407
|
-
*/
|
|
408
|
-
function LegacyToolProbe() {
|
|
409
|
-
useRenderTool(
|
|
410
|
-
{
|
|
411
|
-
name: "sendEmail",
|
|
412
|
-
description: "Send an email on the user's behalf",
|
|
413
|
-
parameters: z.object({ to: z.string() }),
|
|
414
|
-
handler: async ({ to }) => `sent to ${to}`,
|
|
415
|
-
render: ({ status, parameters }) => (
|
|
416
|
-
<>{`legacy-tool|${status}|${parameters.to ?? ""}`}</>
|
|
417
|
-
),
|
|
418
|
-
},
|
|
419
|
-
[],
|
|
420
|
-
);
|
|
421
|
-
const renderToolCall = useRenderToolCall();
|
|
422
|
-
return (
|
|
423
|
-
<>{renderToolCall(renderOneCall("sendEmail", '{"to":"a@b.example"}'))}</>
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
describe("rule 2: `handler`/`description` route to `useFrontendTool`", () => {
|
|
428
|
-
it("registers a callable, advertised tool AND its renderer", async () => {
|
|
429
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
430
|
-
const agent = new ToolListRecordingAgent();
|
|
431
|
-
|
|
432
|
-
const { container } = render(
|
|
433
|
-
<TestCopilotKit messages={[]} agent={agent}>
|
|
434
|
-
<CaptureCore into={coreRef} />
|
|
435
|
-
<LegacyToolProbe />
|
|
436
|
-
</TestCopilotKit>,
|
|
437
|
-
);
|
|
438
|
-
const core = coreRef.current!;
|
|
439
|
-
|
|
440
|
-
await waitFor(() =>
|
|
441
|
-
expect(core.getTool({ toolName: "sendEmail" })).toBeDefined(),
|
|
442
|
-
);
|
|
443
|
-
|
|
444
|
-
// The tool half: present, described, advertised, and — the assertion that
|
|
445
|
-
// separates "registered" from "works" — actually executable through core.
|
|
446
|
-
expect(core.getTool({ toolName: "sendEmail" })?.description).toBe(
|
|
447
|
-
"Send an email on the user's behalf",
|
|
448
|
-
);
|
|
449
|
-
expect(core.tools.map((t) => t.name)).toContain("sendEmail");
|
|
450
|
-
await expect(
|
|
451
|
-
core.runTool({ name: "sendEmail", parameters: { to: "a@b.example" } }),
|
|
452
|
-
).resolves.toMatchObject({
|
|
453
|
-
result: "sent to a@b.example",
|
|
454
|
-
error: undefined,
|
|
455
|
-
});
|
|
456
|
-
await act(async () => {
|
|
457
|
-
await core.runAgent({ agent });
|
|
458
|
-
});
|
|
459
|
-
expect(agent.advertised).toEqual([["sendEmail"]]);
|
|
460
|
-
|
|
461
|
-
// The renderer half: registered through the same call, and painting.
|
|
462
|
-
expect(container.textContent).toBe("legacy-tool|inProgress|a@b.example");
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
/** Rule 3: the new, renderer-only shape — no tool fields at all. */
|
|
319
|
+
/** The renderer-only shape: a schema and a renderer, no tool fields. */
|
|
467
320
|
function ModernRendererProbe() {
|
|
468
321
|
useRenderTool(
|
|
469
322
|
{
|
|
@@ -481,12 +334,12 @@ function ModernRendererProbe() {
|
|
|
481
334
|
);
|
|
482
335
|
}
|
|
483
336
|
|
|
484
|
-
describe("
|
|
337
|
+
describe("a renderer-only registration through RN's entry", () => {
|
|
485
338
|
it("lands the renderer in CopilotKitCoreReact's registry and advertises nothing", async () => {
|
|
486
|
-
// Also the behavioural half of the
|
|
487
|
-
// through RN's
|
|
488
|
-
// an RN-local registry (RN once had one) would break
|
|
489
|
-
// export-surface check stayed green.
|
|
339
|
+
// Also the behavioural half of the "RN owns no registry" guard: a
|
|
340
|
+
// registration made through RN's entry has to end up in CORE's registry,
|
|
341
|
+
// which is the property an RN-local registry (RN once had one) would break
|
|
342
|
+
// while every export-surface check stayed green.
|
|
490
343
|
const coreRef: { current: Core | null } = { current: null };
|
|
491
344
|
const agent = new ToolListRecordingAgent();
|
|
492
345
|
|
|
@@ -513,318 +366,3 @@ describe("rule 3: no tool fields routes to core's `useRenderTool`", () => {
|
|
|
513
366
|
expect(agent.advertised).toEqual([[]]);
|
|
514
367
|
});
|
|
515
368
|
});
|
|
516
|
-
|
|
517
|
-
// ─── The deprecation warning ──────────────────────────────────────────────────
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* A legacy tool-shaped call whose tool NAME the caller chooses, so each warning
|
|
521
|
-
* test gets a name of its own — the warning is deduped per tool name for the
|
|
522
|
-
* lifetime of the module, which is the property under test.
|
|
523
|
-
*/
|
|
524
|
-
function WarningProbe({ name }: { name: string }) {
|
|
525
|
-
useRenderTool(
|
|
526
|
-
{
|
|
527
|
-
name,
|
|
528
|
-
description: "a legacy tool-plus-renderer registration",
|
|
529
|
-
parameters: z.object({ x: z.string() }),
|
|
530
|
-
handler: async () => "ok",
|
|
531
|
-
render: () => null,
|
|
532
|
-
},
|
|
533
|
-
[],
|
|
534
|
-
);
|
|
535
|
-
return null;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* The renderer-only call with NO legacy fields at all: `{ name, parameters,
|
|
540
|
-
* render }`. Simultaneously the correct new spelling and the one old-JS shape
|
|
541
|
-
* the shim cannot tell apart from it, so the warning carries it.
|
|
542
|
-
*/
|
|
543
|
-
function RendererOnlyProbe({ name }: { name: string }) {
|
|
544
|
-
useRenderTool(
|
|
545
|
-
{
|
|
546
|
-
name,
|
|
547
|
-
parameters: z.object({ x: z.string() }),
|
|
548
|
-
render: () => null,
|
|
549
|
-
},
|
|
550
|
-
[],
|
|
551
|
-
);
|
|
552
|
-
return null;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* A call whose SHAPE changes between renders — `handler`/`description` appear
|
|
557
|
-
* only once `legacy` is true, which is what a `handler: enabled ? fn : undefined`
|
|
558
|
-
* call site looks like from the shim's side.
|
|
559
|
-
*/
|
|
560
|
-
function ShapeShiftingProbe({ legacy }: { legacy: boolean }) {
|
|
561
|
-
useRenderTool(
|
|
562
|
-
{
|
|
563
|
-
name: "shapeShifter",
|
|
564
|
-
parameters: z.object({ x: z.string() }),
|
|
565
|
-
render: () => null,
|
|
566
|
-
...(legacy
|
|
567
|
-
? { description: "now a tool as well", handler: async () => "ok" }
|
|
568
|
-
: {}),
|
|
569
|
-
},
|
|
570
|
-
[],
|
|
571
|
-
);
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
describe("the shim's deprecation warning", () => {
|
|
576
|
-
// The dedup key is the tool NAME and it lives as long as the module, so
|
|
577
|
-
// without this the wildcard's warning (always `"*"`) would already have been
|
|
578
|
-
// consumed by the rule-1 test above and these tests would have to depend on
|
|
579
|
-
// file order to observe anything.
|
|
580
|
-
beforeEach(() => {
|
|
581
|
-
__resetRenderToolShimWarnings();
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
it("fires once per distinct tool name, not once per render", async () => {
|
|
585
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
586
|
-
try {
|
|
587
|
-
const { rerender, unmount } = render(
|
|
588
|
-
<TestCopilotKit messages={[]}>
|
|
589
|
-
<WarningProbe name="warnOnceTool" />
|
|
590
|
-
</TestCopilotKit>,
|
|
591
|
-
);
|
|
592
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
593
|
-
|
|
594
|
-
// Re-render the same tree several times. A warning emitted from the
|
|
595
|
-
// render path — or keyed on anything per-render — shows up here as a
|
|
596
|
-
// growing count.
|
|
597
|
-
for (let i = 0; i < 3; i++) {
|
|
598
|
-
rerender(
|
|
599
|
-
<TestCopilotKit messages={[]}>
|
|
600
|
-
<WarningProbe name="warnOnceTool" />
|
|
601
|
-
</TestCopilotKit>,
|
|
602
|
-
);
|
|
603
|
-
}
|
|
604
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
605
|
-
|
|
606
|
-
// Then MOUNT IT AGAIN, which is what makes the module-level dedup set the
|
|
607
|
-
// load-bearing part rather than the effect's dependency array: a fresh
|
|
608
|
-
// mount runs a fresh effect. On a real device this is navigating back to
|
|
609
|
-
// a screen, and re-warning there would put the notice in a loop.
|
|
610
|
-
unmount();
|
|
611
|
-
render(
|
|
612
|
-
<TestCopilotKit messages={[]}>
|
|
613
|
-
<WarningProbe name="warnOnceTool" />
|
|
614
|
-
</TestCopilotKit>,
|
|
615
|
-
);
|
|
616
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
617
|
-
|
|
618
|
-
const message = String(warn.mock.calls[0]![0]);
|
|
619
|
-
// What was received, which hook it was routed to, and what to change the
|
|
620
|
-
// call to — a warning that says less than that is not actionable.
|
|
621
|
-
expect(message).toContain("[CopilotKit]");
|
|
622
|
-
expect(message).toContain("warnOnceTool");
|
|
623
|
-
expect(message).toContain("`description`");
|
|
624
|
-
expect(message).toContain("`handler`");
|
|
625
|
-
expect(message).toContain("`useFrontendTool`");
|
|
626
|
-
expect(message).toContain("removal in the next minor");
|
|
627
|
-
} finally {
|
|
628
|
-
warn.mockRestore();
|
|
629
|
-
}
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
it("names the fields a wildcard call ignored, and says no `*` tool is registered", async () => {
|
|
633
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
634
|
-
try {
|
|
635
|
-
render(
|
|
636
|
-
<TestCopilotKit messages={[]}>
|
|
637
|
-
<LegacyWildcardProbe paints="anything" />
|
|
638
|
-
</TestCopilotKit>,
|
|
639
|
-
);
|
|
640
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
641
|
-
|
|
642
|
-
const message = String(warn.mock.calls[0]![0]);
|
|
643
|
-
expect(message).toContain("IGNORED");
|
|
644
|
-
expect(message).toContain("`description`");
|
|
645
|
-
expect(message).toContain("`handler`");
|
|
646
|
-
expect(message).toContain("`parameters`");
|
|
647
|
-
expect(message).toContain("RENDERER ONLY");
|
|
648
|
-
} finally {
|
|
649
|
-
warn.mockRestore();
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
it("warns on the renderer-only route even with NO legacy fields to name", async () => {
|
|
654
|
-
// The one shape routing cannot discriminate, and therefore the one the
|
|
655
|
-
// warning has to carry alone.
|
|
656
|
-
//
|
|
657
|
-
// `{ name, parameters, render }` is BOTH the correct new renderer-only
|
|
658
|
-
// spelling AND — for an untyped JS caller, the population this shim exists
|
|
659
|
-
// for — a call that on `origin/main` registered and ADVERTISED a real tool.
|
|
660
|
-
// (`description` was required by the old hook's types, so TypeScript
|
|
661
|
-
// callers could not reach this shape; `FrontendTool.handler` is optional
|
|
662
|
-
// and `buildFrontendTools` does not filter on it, so the registration and
|
|
663
|
-
// the advertisement both happened without either field.) Measured against
|
|
664
|
-
// a vendored copy of the old hook, this call went from advertising
|
|
665
|
-
// `["rendererOnlyNoLegacyFields"]` to advertising nothing — so silence
|
|
666
|
-
// here would be the exact failure the shim exists to prevent.
|
|
667
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
668
|
-
try {
|
|
669
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
670
|
-
render(
|
|
671
|
-
<TestCopilotKit messages={[]}>
|
|
672
|
-
<CaptureCore into={coreRef} />
|
|
673
|
-
<RendererOnlyProbe name="rendererOnlyNoLegacyFields" />
|
|
674
|
-
</TestCopilotKit>,
|
|
675
|
-
);
|
|
676
|
-
|
|
677
|
-
// Wait on the REGISTRATION, not on the warning: a hook that did nothing
|
|
678
|
-
// at all could satisfy a warning-only assertion.
|
|
679
|
-
await waitFor(() =>
|
|
680
|
-
expect(coreRef.current!.renderToolCalls.map((r) => r.name)).toContain(
|
|
681
|
-
"rendererOnlyNoLegacyFields",
|
|
682
|
-
),
|
|
683
|
-
);
|
|
684
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
685
|
-
|
|
686
|
-
const message = String(warn.mock.calls[0]![0]);
|
|
687
|
-
expect(message).toContain("rendererOnlyNoLegacyFields");
|
|
688
|
-
expect(message).toContain("RENDERER ONLY");
|
|
689
|
-
// The actionable half: what was lost, and what to use if it was wanted.
|
|
690
|
-
expect(message).toContain("advertised");
|
|
691
|
-
expect(message).toContain("`useFrontendTool`");
|
|
692
|
-
|
|
693
|
-
// And the registration really is renderer-only.
|
|
694
|
-
expect(
|
|
695
|
-
coreRef.current!.getTool({ toolName: "rendererOnlyNoLegacyFields" }),
|
|
696
|
-
).toBeUndefined();
|
|
697
|
-
} finally {
|
|
698
|
-
warn.mockRestore();
|
|
699
|
-
}
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
it("dedups the renderer-only warning per tool name, and stays silent in production", async () => {
|
|
703
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
704
|
-
try {
|
|
705
|
-
const { rerender, unmount } = render(
|
|
706
|
-
<TestCopilotKit messages={[]}>
|
|
707
|
-
<RendererOnlyProbe name="rendererOnlyDedup" />
|
|
708
|
-
</TestCopilotKit>,
|
|
709
|
-
);
|
|
710
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
711
|
-
|
|
712
|
-
rerender(
|
|
713
|
-
<TestCopilotKit messages={[]}>
|
|
714
|
-
<RendererOnlyProbe name="rendererOnlyDedup" />
|
|
715
|
-
</TestCopilotKit>,
|
|
716
|
-
);
|
|
717
|
-
unmount();
|
|
718
|
-
render(
|
|
719
|
-
<TestCopilotKit messages={[]}>
|
|
720
|
-
<RendererOnlyProbe name="rendererOnlyDedup" />
|
|
721
|
-
</TestCopilotKit>,
|
|
722
|
-
);
|
|
723
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
724
|
-
} finally {
|
|
725
|
-
warn.mockRestore();
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// Same route, production gate on: nothing at all.
|
|
729
|
-
const prodWarn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
730
|
-
const previous = process.env.NODE_ENV;
|
|
731
|
-
process.env.NODE_ENV = "production";
|
|
732
|
-
try {
|
|
733
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
734
|
-
render(
|
|
735
|
-
<TestCopilotKit messages={[]}>
|
|
736
|
-
<CaptureCore into={coreRef} />
|
|
737
|
-
<RendererOnlyProbe name="rendererOnlyProdSilent" />
|
|
738
|
-
</TestCopilotKit>,
|
|
739
|
-
);
|
|
740
|
-
await waitFor(() =>
|
|
741
|
-
expect(coreRef.current!.renderToolCalls.map((r) => r.name)).toContain(
|
|
742
|
-
"rendererOnlyProdSilent",
|
|
743
|
-
),
|
|
744
|
-
);
|
|
745
|
-
expect(prodWarn).not.toHaveBeenCalled();
|
|
746
|
-
} finally {
|
|
747
|
-
process.env.NODE_ENV = previous;
|
|
748
|
-
prodWarn.mockRestore();
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
it("reports, rather than silently acts on, a config that changes shape mid-life", async () => {
|
|
753
|
-
// The route is frozen at first render because a hook cannot be called
|
|
754
|
-
// conditionally unless the condition is stable for the component's
|
|
755
|
-
// lifetime. That is a real limitation, so it is stated out loud rather than
|
|
756
|
-
// papered over: the registration stays where it started (renderer-only
|
|
757
|
-
// here, so `shapeShifter` never becomes a tool) and the consumer is told to
|
|
758
|
-
// call the hook they actually want.
|
|
759
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
760
|
-
try {
|
|
761
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
762
|
-
const { rerender } = render(
|
|
763
|
-
<TestCopilotKit messages={[]}>
|
|
764
|
-
<CaptureCore into={coreRef} />
|
|
765
|
-
<ShapeShiftingProbe legacy={false} />
|
|
766
|
-
</TestCopilotKit>,
|
|
767
|
-
);
|
|
768
|
-
await waitFor(() =>
|
|
769
|
-
expect(coreRef.current!.renderToolCalls.map((r) => r.name)).toContain(
|
|
770
|
-
"shapeShifter",
|
|
771
|
-
),
|
|
772
|
-
);
|
|
773
|
-
// Rule 3 on the first render. This warns too — the renderer-only route
|
|
774
|
-
// is never silent, because on the old hook this same shape registered
|
|
775
|
-
// and advertised a tool (see the dedicated test below).
|
|
776
|
-
await waitFor(() => expect(warn).toHaveBeenCalledTimes(1));
|
|
777
|
-
expect(String(warn.mock.calls[0]![0])).toContain("RENDERER ONLY");
|
|
778
|
-
|
|
779
|
-
rerender(
|
|
780
|
-
<TestCopilotKit messages={[]}>
|
|
781
|
-
<CaptureCore into={coreRef} />
|
|
782
|
-
<ShapeShiftingProbe legacy />
|
|
783
|
-
</TestCopilotKit>,
|
|
784
|
-
);
|
|
785
|
-
|
|
786
|
-
// Wait for the DRIFT message specifically: the renderer-only notice
|
|
787
|
-
// above has already been emitted, so a bare `toHaveBeenCalled()` would
|
|
788
|
-
// be satisfied by it and never observe the drift warning at all.
|
|
789
|
-
await waitFor(() => {
|
|
790
|
-
const messages = warn.mock.calls.map((call) => String(call[0]));
|
|
791
|
-
expect(
|
|
792
|
-
messages.some((m) => m.includes("changed shape between renders")),
|
|
793
|
-
).toBe(true);
|
|
794
|
-
});
|
|
795
|
-
// And the frozen route is the observable consequence: still no tool.
|
|
796
|
-
expect(
|
|
797
|
-
coreRef.current!.getTool({ toolName: "shapeShifter" }),
|
|
798
|
-
).toBeUndefined();
|
|
799
|
-
} finally {
|
|
800
|
-
warn.mockRestore();
|
|
801
|
-
}
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
it("is silent in production", async () => {
|
|
805
|
-
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
806
|
-
const previous = process.env.NODE_ENV;
|
|
807
|
-
process.env.NODE_ENV = "production";
|
|
808
|
-
try {
|
|
809
|
-
const coreRef: { current: Core | null } = { current: null };
|
|
810
|
-
render(
|
|
811
|
-
<TestCopilotKit messages={[]}>
|
|
812
|
-
<CaptureCore into={coreRef} />
|
|
813
|
-
<WarningProbe name="productionSilentTool" />
|
|
814
|
-
</TestCopilotKit>,
|
|
815
|
-
);
|
|
816
|
-
// Wait for the REGISTRATION rather than for a timeout: the claim is
|
|
817
|
-
// "routed and silent", and a test that only waited for silence would pass
|
|
818
|
-
// just as well if the hook had done nothing at all.
|
|
819
|
-
await waitFor(() =>
|
|
820
|
-
expect(
|
|
821
|
-
coreRef.current!.getTool({ toolName: "productionSilentTool" }),
|
|
822
|
-
).toBeDefined(),
|
|
823
|
-
);
|
|
824
|
-
expect(warn).not.toHaveBeenCalled();
|
|
825
|
-
} finally {
|
|
826
|
-
process.env.NODE_ENV = previous;
|
|
827
|
-
warn.mockRestore();
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import React$1, { ReactNode } from "react";
|
|
2
|
-
import { RenderToolProps } from "@copilotkit/react-core/v2/headless";
|
|
3
|
-
import { CopilotKitCoreErrorCode, FrontendToolHandlerContext } from "@copilotkit/core";
|
|
4
|
-
import { DebugConfig, InferSchemaOutput, StandardSchemaV1 } from "@copilotkit/shared";
|
|
5
|
-
|
|
6
|
-
//#region src/CopilotKitProvider.d.ts
|
|
7
|
-
interface CopilotKitNativeProviderProps {
|
|
8
|
-
children: ReactNode;
|
|
9
|
-
/** URL of the CopilotKit runtime endpoint */
|
|
10
|
-
runtimeUrl: string;
|
|
11
|
-
/** Custom headers sent with every request */
|
|
12
|
-
headers?: Record<string, string> | (() => Record<string, string>);
|
|
13
|
-
/**
|
|
14
|
-
* Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
|
|
15
|
-
*/
|
|
16
|
-
credentials?: RequestCredentials;
|
|
17
|
-
/** Whether the runtime uses a single-route endpoint */
|
|
18
|
-
useSingleEndpoint?: boolean;
|
|
19
|
-
/** Custom properties forwarded to agents */
|
|
20
|
-
properties?: Record<string, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Error handler called when CopilotKit encounters an error.
|
|
23
|
-
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
24
|
-
* If not provided, errors are logged to console.error.
|
|
25
|
-
*/
|
|
26
|
-
onError?: (event: {
|
|
27
|
-
error: Error;
|
|
28
|
-
code: CopilotKitCoreErrorCode;
|
|
29
|
-
context: Record<string, any>;
|
|
30
|
-
}) => void | Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* Enable debug logging for the client-side event pipeline.
|
|
33
|
-
* When `true`, enables verbose logging from the core instance.
|
|
34
|
-
*/
|
|
35
|
-
debug?: DebugConfig;
|
|
36
|
-
/**
|
|
37
|
-
* Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
|
|
38
|
-
* subscriptions. Individual subscriptions can override with their own `throttleMs`.
|
|
39
|
-
*/
|
|
40
|
-
defaultThrottleMs?: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* CopilotKit provider for React Native.
|
|
44
|
-
*
|
|
45
|
-
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
46
|
-
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
47
|
-
*
|
|
48
|
-
* Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
|
|
49
|
-
* so a separate `import "@copilotkit/react-native/polyfills"` is no longer
|
|
50
|
-
* required (though it remains available for advanced use).
|
|
51
|
-
*
|
|
52
|
-
* Usage:
|
|
53
|
-
* ```tsx
|
|
54
|
-
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
55
|
-
*
|
|
56
|
-
* function App() {
|
|
57
|
-
* return (
|
|
58
|
-
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
59
|
-
* <ChatScreen />
|
|
60
|
-
* </CopilotKitProvider>
|
|
61
|
-
* );
|
|
62
|
-
* }
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
declare const CopilotKitProvider: React$1.FC<CopilotKitNativeProviderProps>;
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/hooks/useRenderTool.d.ts
|
|
68
|
-
/**
|
|
69
|
-
* Fields the OLD React Native hook accepted, kept optional here so the call
|
|
70
|
-
* shapes the compiler cannot see (hoisted / spread / untyped) still type-check
|
|
71
|
-
* and get routed rather than silently dropped.
|
|
72
|
-
*
|
|
73
|
-
* @typeParam A - The parsed argument type a legacy `handler` receives.
|
|
74
|
-
*/
|
|
75
|
-
interface LegacyToolFields<A> {
|
|
76
|
-
/**
|
|
77
|
-
* @deprecated A description is a TOOL field: it is what gets advertised to
|
|
78
|
-
* the model. Supplying it routes this call to `useFrontendTool` — rename the
|
|
79
|
-
* call to `useFrontendTool` instead.
|
|
80
|
-
*/
|
|
81
|
-
description?: string;
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated A handler is a TOOL field: it is what the model's call
|
|
84
|
-
* executes. Supplying it routes this call to `useFrontendTool` — rename the
|
|
85
|
-
* call to `useFrontendTool` instead. Note that core's handler receives a
|
|
86
|
-
* SECOND argument (the {@link FrontendToolHandlerContext}, carrying
|
|
87
|
-
* `stopAgent()`'s abort signal), which the old React Native hook dropped.
|
|
88
|
-
*/
|
|
89
|
-
handler?: (args: A, context: FrontendToolHandlerContext) => Promise<unknown>;
|
|
90
|
-
}
|
|
91
|
-
/** The wildcard call shape: a fallback renderer for every unclaimed tool call. */
|
|
92
|
-
type WildcardConfig = {
|
|
93
|
-
name: "*";
|
|
94
|
-
render: (props: any) => React.ReactElement | null;
|
|
95
|
-
agentId?: string;
|
|
96
|
-
} & LegacyToolFields<Record<string, unknown>> & {
|
|
97
|
-
/**
|
|
98
|
-
* @deprecated A wildcard renderer paints tool calls it does not own, so it
|
|
99
|
-
* has no schema of its own — core's wildcard path ignores this. Remove it.
|
|
100
|
-
*/
|
|
101
|
-
parameters?: StandardSchemaV1;
|
|
102
|
-
};
|
|
103
|
-
/** The name-scoped call shape. */
|
|
104
|
-
type NamedConfig<S extends StandardSchemaV1> = {
|
|
105
|
-
name: string;
|
|
106
|
-
parameters: S;
|
|
107
|
-
render: (props: RenderToolProps<S>) => React.ReactElement | null;
|
|
108
|
-
agentId?: string;
|
|
109
|
-
} & LegacyToolFields<InferSchemaOutput<S>>;
|
|
110
|
-
/**
|
|
111
|
-
* TEST-ONLY escape hatch for the per-name dedup above.
|
|
112
|
-
*
|
|
113
|
-
* Not re-exported from any package entry (`src/headless.ts` exports only the
|
|
114
|
-
* hook), so it is not public API. It exists because the dedup key is the tool
|
|
115
|
-
* NAME and lives for the lifetime of the module: the wildcard's name is the
|
|
116
|
-
* same `"*"` for every caller, so without this the second test to assert the
|
|
117
|
-
* wildcard's warning would silently observe zero calls and have to be written
|
|
118
|
-
* order-dependently instead.
|
|
119
|
-
*/
|
|
120
|
-
/**
|
|
121
|
-
* Registers a wildcard (`"*"`) renderer for tool calls.
|
|
122
|
-
*
|
|
123
|
-
* @deprecated Use `useRenderTool` from `@copilotkit/react-core` (re-exported by
|
|
124
|
-
* `@copilotkit/react-native/headless` once this shim is gone) for a
|
|
125
|
-
* renderer-only registration, or `useFrontendTool` to register a tool and its
|
|
126
|
-
* renderer together. This shim is scheduled for removal in the next minor.
|
|
127
|
-
*
|
|
128
|
-
* @param config - Wildcard renderer configuration.
|
|
129
|
-
* @param deps - Optional dependencies to refresh registration.
|
|
130
|
-
*/
|
|
131
|
-
declare function useRenderTool(config: WildcardConfig, deps?: ReadonlyArray<unknown>): void;
|
|
132
|
-
/**
|
|
133
|
-
* Registers a name-scoped renderer for tool calls — or, if `description` or
|
|
134
|
-
* `handler` is supplied, a frontend tool and its renderer (what the old React
|
|
135
|
-
* Native hook did), with a development warning.
|
|
136
|
-
*
|
|
137
|
-
* @deprecated Use `useRenderTool` from `@copilotkit/react-core` (re-exported by
|
|
138
|
-
* `@copilotkit/react-native/headless` once this shim is gone) for a
|
|
139
|
-
* renderer-only registration, or `useFrontendTool` to register a tool and its
|
|
140
|
-
* renderer together. This shim is scheduled for removal in the next minor.
|
|
141
|
-
*
|
|
142
|
-
* @typeParam S - Schema type describing tool call parameters.
|
|
143
|
-
* @param config - Named renderer configuration.
|
|
144
|
-
* @param deps - Optional dependencies to refresh registration.
|
|
145
|
-
*/
|
|
146
|
-
declare function useRenderTool<S extends StandardSchemaV1>(config: NamedConfig<S>, deps?: ReadonlyArray<unknown>): void;
|
|
147
|
-
//#endregion
|
|
148
|
-
export { CopilotKitNativeProviderProps as n, CopilotKitProvider as r, useRenderTool as t };
|
|
149
|
-
//# sourceMappingURL=useRenderTool-DFz206nL.d.cts.map
|