@copilotkit/react-native 1.84.2-canary.openbot-intel-fixes → 1.86.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.
- package/README.md +341 -2
- package/USAGE.md +388 -21
- package/dist/{CopilotKitProvider-DBq4AhRP.d.cts → CopilotKitProvider-CQ-DpvY1.d.cts} +2 -2
- package/dist/{CopilotKitProvider-D8sn7G_C.mjs → CopilotKitProvider-CXQGv39c.mjs} +1 -1
- package/dist/{CopilotKitProvider-D8sn7G_C.mjs.map → CopilotKitProvider-CXQGv39c.mjs.map} +1 -1
- package/dist/{CopilotKitProvider-fW21Gb7T.d.mts → CopilotKitProvider-Dc1Vbv7K.d.mts} +1 -1
- package/dist/{CopilotKitProvider-CjoPnabW.cjs → CopilotKitProvider-zSfbWwIg.cjs} +1 -1
- package/dist/{CopilotKitProvider-CjoPnabW.cjs.map → CopilotKitProvider-zSfbWwIg.cjs.map} +1 -1
- package/dist/components/index.cjs +1 -0
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.mjs +1 -0
- package/dist/components/index.mjs.map +1 -1
- package/dist/generative-ui/index.cjs +612 -0
- package/dist/generative-ui/index.cjs.map +1 -0
- package/dist/generative-ui/index.d.cts +341 -0
- package/dist/generative-ui/index.d.mts +341 -0
- package/dist/generative-ui/index.mjs +549 -0
- package/dist/generative-ui/index.mjs.map +1 -0
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.mts +1 -1
- package/dist/headless.mjs +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills.cjs +218 -2
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +217 -1
- package/dist/polyfills.mjs.map +1 -1
- package/package.json +13 -5
- package/project.json +6 -1
- package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
- package/scripts/verify-polyfill-barrel.mjs +154 -5
- package/src/__tests__/generative-ui-harness.tsx +243 -0
- package/src/__tests__/generative-ui-provider-props.test-d.tsx +106 -0
- package/src/__tests__/generative-ui-rn-mock.tsx +54 -0
- package/src/__tests__/generative-ui-wiring.test.tsx +720 -0
- package/src/__tests__/generative-ui.test.tsx +1000 -0
- package/src/__tests__/headless-entry-surface.test.ts +964 -34
- package/src/components/index.ts +6 -0
- package/src/generative-ui/GenerativeUIActivity.tsx +235 -0
- package/src/generative-ui/GenerativeUIProvider.tsx +171 -0
- package/src/generative-ui/GenerativeUISurface.tsx +303 -0
- package/src/generative-ui/host.tsx +138 -0
- package/src/generative-ui/index.ts +99 -0
- package/src/generative-ui/internal.ts +55 -0
- package/src/index.ts +8 -3
- package/tsdown.config.ts +1 -0
- package/dist/streaming-fetch-Bm91EsRc.cjs +0 -225
- package/dist/streaming-fetch-Bm91EsRc.cjs.map +0 -1
- package/dist/streaming-fetch-Dm1oN4f2.mjs +0 -219
- package/dist/streaming-fetch-Dm1oN4f2.mjs.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import { expectTypeOf } from "vitest";
|
|
3
|
+
import type { Message } from "@ag-ui/client";
|
|
4
|
+
import {
|
|
5
|
+
createGenerativeUI,
|
|
6
|
+
GenerativeUIProvider,
|
|
7
|
+
GenerativeUISurface,
|
|
8
|
+
isGenerativeUIActivity,
|
|
9
|
+
} from "../generative-ui";
|
|
10
|
+
import type {
|
|
11
|
+
GenerativeUIAccessibilityWrapperProps,
|
|
12
|
+
GenerativeUIActivityWrapperProps,
|
|
13
|
+
GenerativeUIHost,
|
|
14
|
+
GenerativeUINodeFallbackProps,
|
|
15
|
+
GenerativeUIProviderProps,
|
|
16
|
+
GenerativeUIRejectedOperation,
|
|
17
|
+
GenerativeUIRuntime,
|
|
18
|
+
GenerativeUISurfaceProps,
|
|
19
|
+
GenerativeUISurfaceRootProps,
|
|
20
|
+
GenerativeUIToolConfig,
|
|
21
|
+
} from "../generative-ui";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Type-level guard for the `@copilotkit/react-native/generative-ui` entry.
|
|
25
|
+
*
|
|
26
|
+
* A `.test-d.tsx` file, like `frontend-tool-render.test-d.tsx`: `tsc --noEmit`
|
|
27
|
+
* (`nx run @copilotkit/react-native:check-types`) compiles it, so every
|
|
28
|
+
* `@ts-expect-error` below is load-bearing, and the `.test-d.` infix keeps it
|
|
29
|
+
* out of vitest's suite glob.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const ui = createGenerativeUI({ id: "props-test", components: {} });
|
|
33
|
+
|
|
34
|
+
// ─── `theme` is not a React Native prop ──────────────────────────────────────
|
|
35
|
+
// The web `theme` sets `--a2ui-*` CSS variables. React Native has no CSS
|
|
36
|
+
// variables, so the RN host never applies it; accepting it would drop the
|
|
37
|
+
// value silently.
|
|
38
|
+
|
|
39
|
+
expectTypeOf<GenerativeUIProviderProps>().not.toHaveProperty("theme");
|
|
40
|
+
// The config type this entry exports is the React Native one, without theme.
|
|
41
|
+
expectTypeOf<GenerativeUIToolConfig>().not.toHaveProperty("theme");
|
|
42
|
+
expectTypeOf<GenerativeUIToolConfig>().toHaveProperty("agentIds");
|
|
43
|
+
|
|
44
|
+
export const withTheme = (
|
|
45
|
+
// @ts-expect-error `theme` is not accepted on React Native.
|
|
46
|
+
<GenerativeUIProvider ui={ui} theme={{}}>
|
|
47
|
+
{null}
|
|
48
|
+
</GenerativeUIProvider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const withoutTheme = (
|
|
52
|
+
<GenerativeUIProvider ui={ui} agentIds={["agent"]}>
|
|
53
|
+
{null}
|
|
54
|
+
</GenerativeUIProvider>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// ─── The types a custom `host` and a custom Wrapper need are exported ────────
|
|
58
|
+
|
|
59
|
+
expectTypeOf<GenerativeUIActivityWrapperProps["rejected"]>().toEqualTypeOf<
|
|
60
|
+
GenerativeUIRejectedOperation[]
|
|
61
|
+
>();
|
|
62
|
+
expectTypeOf<
|
|
63
|
+
React.ComponentProps<GenerativeUIHost["SurfaceRoot"]>
|
|
64
|
+
>().toEqualTypeOf<GenerativeUISurfaceRootProps>();
|
|
65
|
+
expectTypeOf<
|
|
66
|
+
React.ComponentProps<GenerativeUIHost["AccessibilityWrapper"]>
|
|
67
|
+
>().toEqualTypeOf<GenerativeUIAccessibilityWrapperProps>();
|
|
68
|
+
expectTypeOf<
|
|
69
|
+
React.ComponentProps<GenerativeUIHost["NodeFallback"]>
|
|
70
|
+
>().toEqualTypeOf<GenerativeUINodeFallbackProps>();
|
|
71
|
+
expectTypeOf<GenerativeUIRuntime>().toBeObject();
|
|
72
|
+
|
|
73
|
+
// ─── isGenerativeUIActivity is a type guard ──────────────────────────────────
|
|
74
|
+
|
|
75
|
+
declare const messages: Message[];
|
|
76
|
+
const activities = messages.filter(isGenerativeUIActivity);
|
|
77
|
+
expectTypeOf(activities[0]!.role).toEqualTypeOf<"activity">();
|
|
78
|
+
expectTypeOf(
|
|
79
|
+
activities[0]!.activityType,
|
|
80
|
+
).toEqualTypeOf<"generative-ui-surface">();
|
|
81
|
+
|
|
82
|
+
// ─── GenerativeUISurface: `components` is typed by `ui` ──────────────────────
|
|
83
|
+
|
|
84
|
+
const shopUI = createGenerativeUI({
|
|
85
|
+
id: "surface-props-test",
|
|
86
|
+
components: { Card: { component: () => null } },
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const typedComponents = (
|
|
90
|
+
<GenerativeUISurface id="a" ui={shopUI} components={["Card"]} />
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
export const unknownComponent = (
|
|
94
|
+
// @ts-expect-error "Nope" is not a component of shopUI.
|
|
95
|
+
<GenerativeUISurface id="a" ui={shopUI} components={["Nope"]} />
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
export const componentsWithoutUI = (
|
|
99
|
+
// @ts-expect-error `components` needs `ui`, which types its names.
|
|
100
|
+
<GenerativeUISurface id="a" components={["Card"]} />
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// The Wrapper of a named-target surface takes the Activity's Wrapper props.
|
|
104
|
+
expectTypeOf<NonNullable<GenerativeUISurfaceProps["Wrapper"]>>().toEqualTypeOf<
|
|
105
|
+
React.ComponentType<GenerativeUIActivityWrapperProps>
|
|
106
|
+
>();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native host components as DOM elements, so the generative UI tests
|
|
3
|
+
* can query them. The layout and accessibility props a native view would
|
|
4
|
+
* receive are written out as data attributes, so the tests can see what
|
|
5
|
+
* reaches the platform.
|
|
6
|
+
*
|
|
7
|
+
* Use it as the factory of `vi.mock("react-native", ...)`. It imports
|
|
8
|
+
* nothing that imports react-native, so the factory cannot recurse.
|
|
9
|
+
*/
|
|
10
|
+
import React from "react";
|
|
11
|
+
|
|
12
|
+
const host =
|
|
13
|
+
(tag: string) =>
|
|
14
|
+
({
|
|
15
|
+
children,
|
|
16
|
+
testID,
|
|
17
|
+
style,
|
|
18
|
+
onPress,
|
|
19
|
+
accessibilityRole,
|
|
20
|
+
collapsable,
|
|
21
|
+
accessibilityElementsHidden,
|
|
22
|
+
importantForAccessibility,
|
|
23
|
+
accessibilityLiveRegion,
|
|
24
|
+
"aria-hidden": ariaHidden,
|
|
25
|
+
"aria-live": ariaLive,
|
|
26
|
+
}: any) =>
|
|
27
|
+
React.createElement(
|
|
28
|
+
tag,
|
|
29
|
+
{
|
|
30
|
+
"data-testid": testID,
|
|
31
|
+
"data-style": JSON.stringify(style ?? null),
|
|
32
|
+
"data-collapsable": JSON.stringify(collapsable),
|
|
33
|
+
"data-accessibility-elements-hidden": JSON.stringify(
|
|
34
|
+
accessibilityElementsHidden,
|
|
35
|
+
),
|
|
36
|
+
"data-important-for-accessibility": importantForAccessibility,
|
|
37
|
+
"data-accessibility-live-region": accessibilityLiveRegion,
|
|
38
|
+
"data-aria-hidden": JSON.stringify(ariaHidden),
|
|
39
|
+
"data-aria-live": ariaLive,
|
|
40
|
+
role: accessibilityRole,
|
|
41
|
+
onClick: onPress,
|
|
42
|
+
},
|
|
43
|
+
children,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export function createReactNativeMock() {
|
|
47
|
+
return {
|
|
48
|
+
View: host("div"),
|
|
49
|
+
Text: host("span"),
|
|
50
|
+
Pressable: host("button"),
|
|
51
|
+
StyleSheet: { create: (s: unknown) => s, hairlineWidth: 1 },
|
|
52
|
+
Platform: { OS: "ios", select: (o: any) => o.ios ?? o.default },
|
|
53
|
+
};
|
|
54
|
+
}
|