@copilotkit/react-native 2.0.0-rc.4 → 2.0.0-rc.40
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 +334 -2
- package/USAGE.md +382 -21
- package/dist/CopilotKitProvider-Cbfrm_7u.d.mts +65 -0
- package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-CvJYytjn.cjs} +56 -42
- package/dist/CopilotKitProvider-CvJYytjn.cjs.map +1 -0
- package/dist/CopilotKitProvider-Dv3ISMKf.d.cts +65 -0
- package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-oTdmylSY.mjs} +55 -42
- package/dist/CopilotKitProvider-oTdmylSY.mjs.map +1 -0
- package/dist/{Markdown-C_9Re36O.cjs → Markdown-DLopAh5W.cjs} +10 -10
- package/dist/Markdown-DLopAh5W.cjs.map +1 -0
- package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-Du-b_Qpr.d.mts} +3 -3
- package/dist/{Markdown-1ips7myr.d.cts → Markdown-UXZdDjzs.d.cts} +3 -3
- package/dist/{Markdown-C6AsLHmd.mjs → Markdown-VxtPJ_yh.mjs} +4 -4
- package/dist/Markdown-VxtPJ_yh.mjs.map +1 -0
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-EobUsERg.mjs} +1 -1
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-EobUsERg.mjs.map} +1 -1
- package/dist/MarkdownRendererContext-cDEHvbw9.cjs +40 -0
- package/dist/{MarkdownRendererContext-BRNe808d.cjs.map → MarkdownRendererContext-cDEHvbw9.cjs.map} +1 -1
- package/dist/chunk-C0xms8kb.cjs +34 -0
- package/dist/components/index.cjs +78 -175
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +76 -174
- 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 +2 -2
- package/dist/headless.d.cts +2 -2
- package/dist/headless.d.mts +2 -2
- package/dist/headless.mjs +1 -1
- package/dist/index.cjs +131 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -18
- package/dist/index.d.mts +36 -18
- package/dist/index.mjs +130 -161
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +115 -5
- package/dist/polyfills/encoding.cjs.map +1 -1
- package/dist/polyfills/encoding.d.cts +31 -1
- package/dist/polyfills/encoding.d.mts +31 -1
- package/dist/polyfills/encoding.mjs +113 -6
- package/dist/polyfills/encoding.mjs.map +1 -1
- package/dist/polyfills/streams.cjs +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 +51 -21
- package/project.json +6 -1
- package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
- package/scripts/verify-polyfill-barrel.mjs +158 -11
- package/src/CopilotChat.tsx +114 -93
- package/src/CopilotKitProvider.tsx +87 -130
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +7 -5
- package/src/__mocks__/react-native.ts +31 -0
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/attachments-integration.test.tsx +15 -2
- package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
- package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- package/src/__tests__/copilot-chat-threads.test.tsx +232 -0
- package/src/__tests__/copilot-popup.test.tsx +15 -2
- package/src/__tests__/copilot-sidebar.test.tsx +15 -2
- package/src/__tests__/copilotkit-provider.test.tsx +68 -73
- 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 +979 -60
- package/src/__tests__/headless-integration.test.tsx +11 -1
- package/src/__tests__/use-attachments.test.ts +27 -2
- package/src/components/CopilotChat.tsx +106 -233
- package/src/components/CopilotModal.tsx +1 -1
- package/src/components/Markdown.tsx +4 -4
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
- package/src/components/__tests__/CopilotChat.test.tsx +12 -4
- package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
- package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/messages/AssistantMessage.tsx +3 -3
- package/src/components/messages/TypingIndicator.tsx +4 -4
- 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 +93 -0
- package/src/generative-ui/internal.ts +55 -0
- package/src/hooks/use-attachments.ts +95 -139
- package/src/index.ts +8 -3
- package/src/polyfills/__tests__/encoding-utf8.test.ts +112 -0
- package/src/polyfills/encoding.ts +160 -4
- package/src/types.d.ts +0 -13
- package/tsdown.config.ts +1 -0
- package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
- package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
- package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
- package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
- package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
- package/dist/Markdown-C_9Re36O.cjs.map +0 -1
- package/dist/MarkdownRendererContext-BRNe808d.cjs +0 -72
- 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,341 @@
|
|
|
1
|
+
import React, { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { GENERATIVE_UI_ACTIVITY_TYPE, GenerativeUIRejectedOperation, GenerativeUIRejectedOperation as GenerativeUIRejectedOperation$1 } from "@copilotkit/shared";
|
|
3
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import { StyleProp, ViewStyle } from "react-native";
|
|
5
|
+
import { CreateGenerativeUIConfig, ExportA2UICatalogOptions, GenerativeUI, GenerativeUI as GenerativeUI$1, GenerativeUIAccessibility, GenerativeUIAccessibilityWrapperProps, GenerativeUIAriaAttributes, GenerativeUIComponentDefinition, GenerativeUIComponentName, GenerativeUIComponentName as GenerativeUIComponentName$1, GenerativeUIComponentProps, GenerativeUIError, GenerativeUIErrorBoundaryConfig, GenerativeUIErrorCode, GenerativeUIErrorInfo, GenerativeUIEventDefinition, GenerativeUIEventHandler, GenerativeUIFunctionArgs, GenerativeUIFunctionDefinition, GenerativeUIFunctionInput, GenerativeUIFunctionName, GenerativeUIHost, GenerativeUIHost as GenerativeUIHost$1, GenerativeUIInvokeResult, GenerativeUINodeFallbackProps, GenerativeUINodeFallbackProps as GenerativeUINodeFallbackProps$1, GenerativeUIRuntime, GenerativeUISlotKind, GenerativeUIStateOf, GenerativeUISurfaceRootProps, GenerativeUIToolConfig as GenerativeUIToolConfig$1, child, childList, createGenerativeUI, exportA2UICatalog, useGenerativeUIAccessibility, useGenerativeUIFunction, useGenerativeUIRuntime, useGenerativeUIState } from "@copilotkit/react-core/generative-ui/native";
|
|
6
|
+
|
|
7
|
+
//#region src/generative-ui/GenerativeUIProvider.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* The generative UI config of React Native: the web tool transport's config
|
|
10
|
+
* without `theme`. On the web, `theme` sets the `--a2ui-*` CSS variables of
|
|
11
|
+
* the surfaces. React Native has no CSS variables, so the option is left out
|
|
12
|
+
* of the type rather than silently ignored. Style your catalog's components
|
|
13
|
+
* directly.
|
|
14
|
+
*/
|
|
15
|
+
type GenerativeUIToolConfig = Omit<GenerativeUIToolConfig$1, "theme">;
|
|
16
|
+
/**
|
|
17
|
+
* The props of {@link GenerativeUIProvider}: {@link GenerativeUIToolConfig},
|
|
18
|
+
* the children and the host elements.
|
|
19
|
+
*
|
|
20
|
+
* A `theme` or a `transport` other than `"tool"` that gets past the type (from
|
|
21
|
+
* JavaScript, or through a cast) is dropped before it reaches the runtime, with
|
|
22
|
+
* a warning in development: the surfaces never get a theme, and the transport
|
|
23
|
+
* is always the tool transport.
|
|
24
|
+
*/
|
|
25
|
+
type GenerativeUIProviderProps = GenerativeUIToolConfig & {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* The host elements around the catalog's components: the surface root, the
|
|
29
|
+
* accessibility wrapper and the error fallback. Defaults to React Native
|
|
30
|
+
* views.
|
|
31
|
+
*/
|
|
32
|
+
host?: GenerativeUIHost$1;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Experimental. Turns on generative UI for the agents of the enclosing
|
|
36
|
+
* `CopilotKitProvider`: the agent renders the components of `ui` (from
|
|
37
|
+
* `createGenerativeUI`) with the `render_ui` tool. Place it inside
|
|
38
|
+
* `CopilotKitProvider`. It applies to every agent run on that CopilotKit
|
|
39
|
+
* core, wherever the run starts in the component tree; limit it to some
|
|
40
|
+
* agents with `agentIds`. Show what the agent
|
|
41
|
+
* renders with `<GenerativeUIActivity>` (any activity message, for example in
|
|
42
|
+
* your own chat list or on a home screen) or `<GenerativeUISurface id>` (a
|
|
43
|
+
* named place in your app).
|
|
44
|
+
*
|
|
45
|
+
* The runtime needs no setup: `CopilotRuntime` adds the `render_ui` tool to
|
|
46
|
+
* the run when the app sends a catalog with at least one component. A
|
|
47
|
+
* catalog with no components gets no `render_ui` tool.
|
|
48
|
+
*
|
|
49
|
+
* Mount exactly one `GenerativeUIProvider` with a `ui` for each
|
|
50
|
+
* `CopilotKitProvider`, above every screen that shows generative UI, rather
|
|
51
|
+
* than one per screen. Each one sets the catalog and the named targets of
|
|
52
|
+
* every run on the core, so two of them override each other, and each
|
|
53
|
+
* shows only the surfaces built for its own catalog. In development, the
|
|
54
|
+
* second one mounted warns.
|
|
55
|
+
*
|
|
56
|
+
* It ingests every generative UI activity message in the messages of the
|
|
57
|
+
* agents it watches. A message whose content is malformed is skipped (in
|
|
58
|
+
* development it warns once for each distinct issue), as
|
|
59
|
+
* `<GenerativeUIActivity>` skips it.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* const ui = createGenerativeUI({
|
|
64
|
+
* id: "bank",
|
|
65
|
+
* components: {
|
|
66
|
+
* BalanceCard: {
|
|
67
|
+
* description: "An account balance",
|
|
68
|
+
* props: z.object({ accountId: z.string() }),
|
|
69
|
+
* component: BalanceCard,
|
|
70
|
+
* },
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* <CopilotKitProvider runtimeUrl={RUNTIME_URL}>
|
|
75
|
+
* <GenerativeUIProvider ui={ui}>
|
|
76
|
+
* <App />
|
|
77
|
+
* </GenerativeUIProvider>
|
|
78
|
+
* </CopilotKitProvider>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
declare function GenerativeUIProvider({
|
|
82
|
+
children,
|
|
83
|
+
host,
|
|
84
|
+
...props
|
|
85
|
+
}: GenerativeUIProviderProps): react_jsx_runtime0.JSX.Element;
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/generative-ui/GenerativeUIActivity.d.ts
|
|
88
|
+
/** The message shape this component reads: an AG-UI activity message. */
|
|
89
|
+
interface GenerativeUIActivityMessage {
|
|
90
|
+
id?: string;
|
|
91
|
+
role: string;
|
|
92
|
+
activityType?: string;
|
|
93
|
+
content?: unknown;
|
|
94
|
+
}
|
|
95
|
+
/** Props of the wrapper around one generated surface. */
|
|
96
|
+
interface GenerativeUIActivityWrapperProps {
|
|
97
|
+
surfaceId: string;
|
|
98
|
+
/** The agent is still writing this surface. */
|
|
99
|
+
isStreaming: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Set when `rejected` is not empty. The message is generic; `error.cause`
|
|
102
|
+
* holds the same list as `rejected`.
|
|
103
|
+
*/
|
|
104
|
+
error?: Error;
|
|
105
|
+
/**
|
|
106
|
+
* The rejected operations of the latest `render_ui` call, with the
|
|
107
|
+
* validator's reasons. When the surface is built again from its messages
|
|
108
|
+
* (for example when the app restarts on a stored thread), the call
|
|
109
|
+
* boundaries are not known, so the list can also hold rejections of
|
|
110
|
+
* earlier calls on the surface.
|
|
111
|
+
*/
|
|
112
|
+
rejected: GenerativeUIRejectedOperation$1[];
|
|
113
|
+
/**
|
|
114
|
+
* The surface. `null` when the agent's `createSurface` was rejected, so
|
|
115
|
+
* the surface never existed: only `error` and `rejected` are set.
|
|
116
|
+
*/
|
|
117
|
+
children: ReactNode;
|
|
118
|
+
}
|
|
119
|
+
interface GenerativeUIActivityProps {
|
|
120
|
+
/** An activity message from `agent.messages`. Other messages render nothing. */
|
|
121
|
+
message: GenerativeUIActivityMessage;
|
|
122
|
+
/** The agent whose messages these are (its thread owns the surface). */
|
|
123
|
+
agent: {
|
|
124
|
+
threadId?: string;
|
|
125
|
+
agentId?: string;
|
|
126
|
+
} | undefined;
|
|
127
|
+
/** Replaces the default wrapper around the surface. */
|
|
128
|
+
Wrapper?: ComponentType<GenerativeUIActivityWrapperProps>;
|
|
129
|
+
/**
|
|
130
|
+
* The surface target this component shows. Defaults to `"chat"`, the
|
|
131
|
+
* target of a surface the agent renders in the conversation, as in the
|
|
132
|
+
* web chat. Surfaces of any other target render nothing.
|
|
133
|
+
*
|
|
134
|
+
* A surface aimed at a named target is drawn by the
|
|
135
|
+
* `<GenerativeUISurface id>` with that id, so a chat list that renders
|
|
136
|
+
* every activity message leaves it out and does not show it twice. The
|
|
137
|
+
* agent can render into a named target only when a
|
|
138
|
+
* `<GenerativeUISurface>` with that id was mounted when the run started
|
|
139
|
+
* (the runtime rejects a `createSurface` for any other target), so this
|
|
140
|
+
* prop does not make a target on its own. Set it to show a surface that the agent rendered into such a
|
|
141
|
+
* target somewhere else, for example on a history screen after the user
|
|
142
|
+
* left the screen with the `<GenerativeUISurface>`. While both are on
|
|
143
|
+
* screen, the surface is drawn twice.
|
|
144
|
+
*/
|
|
145
|
+
target?: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* True for the activity messages that carry a generated surface. A type
|
|
149
|
+
* guard, so `agent.messages.filter(isGenerativeUIActivity)` gives activity
|
|
150
|
+
* messages. It does not check the content: `<GenerativeUIActivity>` does.
|
|
151
|
+
*/
|
|
152
|
+
declare function isGenerativeUIActivity<M extends GenerativeUIActivityMessage>(message: M): message is M & {
|
|
153
|
+
role: "activity";
|
|
154
|
+
activityType: typeof GENERATIVE_UI_ACTIVITY_TYPE;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The default wrapper: the surface, and an error line under it when
|
|
158
|
+
* operations were rejected.
|
|
159
|
+
*
|
|
160
|
+
* It is the flex item of the parent, so it grows (`flexGrow: 1`) to fill
|
|
161
|
+
* the free space of a parent with a fixed size, and the stretch default of
|
|
162
|
+
* `alignItems` gives it the parent's cross size. A catalog root that sizes
|
|
163
|
+
* itself against its parent (`flex: 1`, `flexGrow` or a percentage height)
|
|
164
|
+
* then fills the parent, for example a screen that shows one surface.
|
|
165
|
+
* In a list it does not: a `FlatList` cell and the content of a
|
|
166
|
+
* `ScrollView` are as tall as their content, so there is no free space and
|
|
167
|
+
* each row keeps its own height. Siblings in a parent with a fixed size, or
|
|
168
|
+
* in a `ScrollView` whose `contentContainerStyle` grows, share its free
|
|
169
|
+
* space. Pass a `Wrapper` for any other layout.
|
|
170
|
+
*/
|
|
171
|
+
declare function DefaultGenerativeUIActivityWrapper({
|
|
172
|
+
error,
|
|
173
|
+
children
|
|
174
|
+
}: GenerativeUIActivityWrapperProps): react_jsx_runtime0.JSX.Element;
|
|
175
|
+
/**
|
|
176
|
+
* Experimental. Shows the surface that an agent rendered with `render_ui`,
|
|
177
|
+
* from its activity message. Put it wherever the app shows the agent's
|
|
178
|
+
* output: in a chat list (one per activity message), or on a screen with no
|
|
179
|
+
* chat at all, for example a home screen that an agent composes.
|
|
180
|
+
*
|
|
181
|
+
* Like the web chat, it shows only surfaces whose target is `"chat"`. A
|
|
182
|
+
* surface aimed at a `<GenerativeUISurface id>` is drawn there (see
|
|
183
|
+
* `target`).
|
|
184
|
+
*
|
|
185
|
+
* It renders nothing when:
|
|
186
|
+
* - the message is not a generative UI activity;
|
|
187
|
+
* - its content is malformed (in development it warns with the issues);
|
|
188
|
+
* - there is no `<GenerativeUIProvider>` above it, or the provider has no
|
|
189
|
+
* `ui` (in development it warns);
|
|
190
|
+
* - the agent is undefined or has no `threadId` yet, since the surface
|
|
191
|
+
* belongs to a thread (in development it warns);
|
|
192
|
+
* - the surface's target is not `target`;
|
|
193
|
+
* - the agent deleted the surface (`deleteSurface`).
|
|
194
|
+
*
|
|
195
|
+
* When the agent's `createSurface` was rejected, the Wrapper renders with
|
|
196
|
+
* `children` set to `null`, and only the error shows.
|
|
197
|
+
*
|
|
198
|
+
* Each instance warns once for each distinct problem, also when a problem
|
|
199
|
+
* goes away and comes back. A `message` with another id warns again.
|
|
200
|
+
*
|
|
201
|
+
* The provider ingests every activity message of `agent.messages` itself,
|
|
202
|
+
* with the same checks: a malformed one is skipped there too (in
|
|
203
|
+
* development it warns), so it cannot break the agent's run.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```tsx
|
|
207
|
+
* const { agent } = useAgent({ agentId: "home" });
|
|
208
|
+
* return agent.messages
|
|
209
|
+
* .filter(isGenerativeUIActivity)
|
|
210
|
+
* .map((message) => (
|
|
211
|
+
* <GenerativeUIActivity key={message.id} message={message} agent={agent} />
|
|
212
|
+
* ));
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* Render every activity message, not only the latest: the latest can be a
|
|
216
|
+
* surface of a named target, or a deleted surface, and render nothing. For a
|
|
217
|
+
* placeholder until the agent renders, use `<GenerativeUISurface id
|
|
218
|
+
* fallback>`, which knows whether its target has a surface.
|
|
219
|
+
*/
|
|
220
|
+
declare function GenerativeUIActivity({
|
|
221
|
+
message,
|
|
222
|
+
agent,
|
|
223
|
+
Wrapper,
|
|
224
|
+
target
|
|
225
|
+
}: GenerativeUIActivityProps): react_jsx_runtime0.JSX.Element | null;
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/generative-ui/GenerativeUISurface.d.ts
|
|
228
|
+
type GenerativeUISurfaceProps<UI extends GenerativeUI$1<any> = GenerativeUI$1<any>> = {
|
|
229
|
+
/** Target id the agent renders into. */id: string;
|
|
230
|
+
/**
|
|
231
|
+
* Tells the model where this surface is and what to show in it, for
|
|
232
|
+
* example "The home screen, under the greeting."
|
|
233
|
+
*/
|
|
234
|
+
description?: string;
|
|
235
|
+
/**
|
|
236
|
+
* Shown until a surface targets this id, and while the provider has no
|
|
237
|
+
* `ui`.
|
|
238
|
+
*/
|
|
239
|
+
fallback?: ReactNode;
|
|
240
|
+
/**
|
|
241
|
+
* The style of the view around the surface. It applies while the fallback
|
|
242
|
+
* shows, too.
|
|
243
|
+
*/
|
|
244
|
+
style?: StyleProp<ViewStyle>;
|
|
245
|
+
/**
|
|
246
|
+
* Called once each time the agent starts to render into this surface: for
|
|
247
|
+
* each `render_ui` call, on a new surface or as an update, also when React
|
|
248
|
+
* batches several starts into one render. Also called when the surface
|
|
249
|
+
* mounts, its `id` changes, or the active thread changes, while the agent
|
|
250
|
+
* is rendering into it. Not called again for the same call when the
|
|
251
|
+
* component renders again, mounts under `<React.StrictMode>`, or gets a
|
|
252
|
+
* new callback or a new runtime. Use it, for example, to scroll the
|
|
253
|
+
* surface into view.
|
|
254
|
+
*
|
|
255
|
+
* A call is seen as new when the surface goes to "streaming" from another
|
|
256
|
+
* status, or stays "streaming" while its rejected operations are reset
|
|
257
|
+
* (the runtime resets them at the start of each call). When the app never
|
|
258
|
+
* sees the end of one call, for example because a reconnect delivers the
|
|
259
|
+
* next call already streaming and neither call had a rejected operation,
|
|
260
|
+
* the two calls count as one start.
|
|
261
|
+
*
|
|
262
|
+
* It runs after React commits the render. An error it throws is caught
|
|
263
|
+
* and logged with `console.error`, so the surface stays up.
|
|
264
|
+
*/
|
|
265
|
+
onGenerationStart?: () => void;
|
|
266
|
+
/**
|
|
267
|
+
* Replaces the default wrapper around the surface, as on
|
|
268
|
+
* `<GenerativeUIActivity>`. It gets the operations of the latest
|
|
269
|
+
* `render_ui` call that were rejected, by the runtime or on the device,
|
|
270
|
+
* and an `error` when there are any. The default draws the surface and,
|
|
271
|
+
* under it, "Part of this UI couldn't be shown." when some were rejected.
|
|
272
|
+
* The fallback is not wrapped. A surface whose `createSurface` was
|
|
273
|
+
* rejected never exists, so the fallback shows; render the activity
|
|
274
|
+
* message with `<GenerativeUIActivity target>` to show that error.
|
|
275
|
+
*/
|
|
276
|
+
Wrapper?: ComponentType<GenerativeUIActivityWrapperProps>;
|
|
277
|
+
} & ({
|
|
278
|
+
/** The UI of the provider. It types the names in `components`. */ui: UI;
|
|
279
|
+
/**
|
|
280
|
+
* The only components that the agent can use in this surface. Left
|
|
281
|
+
* out, every component of the UI is allowed.
|
|
282
|
+
*/
|
|
283
|
+
components?: readonly GenerativeUIComponentName$1<UI>[];
|
|
284
|
+
} | {
|
|
285
|
+
ui?: undefined;
|
|
286
|
+
components?: undefined;
|
|
287
|
+
});
|
|
288
|
+
/**
|
|
289
|
+
* Experimental. A named place in the app where the agent can render UI. The
|
|
290
|
+
* agent sees the target, with its `description`, in each run that starts
|
|
291
|
+
* while it is mounted (the target list is sent at the start of the run).
|
|
292
|
+
*
|
|
293
|
+
* A target follows the thread that is active in the provider: the thread of
|
|
294
|
+
* the last run that started on the CopilotKit core, of any agent, including
|
|
295
|
+
* agents that the provider's `agentIds` leaves out. To show the output of
|
|
296
|
+
* one particular agent run, use `<GenerativeUIActivity>` with that agent's
|
|
297
|
+
* activity message.
|
|
298
|
+
*
|
|
299
|
+
* In development it warns once for each distinct problem of this instance
|
|
300
|
+
* (no `ui` on the provider, a `ui` that is not the provider's, unknown
|
|
301
|
+
* component names), and again for any of them after the provider's catalog
|
|
302
|
+
* changes.
|
|
303
|
+
*
|
|
304
|
+
* It throws when there is no `<GenerativeUIProvider>` above it. Under a
|
|
305
|
+
* provider with no `ui`, it shows its fallback (in development it warns).
|
|
306
|
+
* The view around it, with `style` and the test ID
|
|
307
|
+
* `generative-ui-surface-<id>`, is there in both states.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```tsx
|
|
311
|
+
* <GenerativeUISurface
|
|
312
|
+
* id="insights"
|
|
313
|
+
* ui={bankUI}
|
|
314
|
+
* description="Under the balances. Show spending insights here."
|
|
315
|
+
* components={["SpendingCard", "InsightCard"]}
|
|
316
|
+
* fallback={<InsightsPlaceholder />}
|
|
317
|
+
* />
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
declare function GenerativeUISurface<UI extends GenerativeUI$1<any> = GenerativeUI$1<any>>({
|
|
321
|
+
id,
|
|
322
|
+
description,
|
|
323
|
+
ui,
|
|
324
|
+
components,
|
|
325
|
+
fallback,
|
|
326
|
+
style,
|
|
327
|
+
onGenerationStart,
|
|
328
|
+
Wrapper
|
|
329
|
+
}: GenerativeUISurfaceProps<UI>): react_jsx_runtime0.JSX.Element;
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region src/generative-ui/host.d.ts
|
|
332
|
+
declare function NativeNodeFallback({
|
|
333
|
+
message,
|
|
334
|
+
componentId,
|
|
335
|
+
retry
|
|
336
|
+
}: GenerativeUINodeFallbackProps$1): react_jsx_runtime0.JSX.Element;
|
|
337
|
+
/** The host elements of a surface on React Native. */
|
|
338
|
+
declare const nativeGenerativeUIHost: GenerativeUIHost$1;
|
|
339
|
+
//#endregion
|
|
340
|
+
export { type CreateGenerativeUIConfig, DefaultGenerativeUIActivityWrapper, type ExportA2UICatalogOptions, type GenerativeUI, type GenerativeUIAccessibility, type GenerativeUIAccessibilityWrapperProps, GenerativeUIActivity, type GenerativeUIActivityMessage, type GenerativeUIActivityProps, type GenerativeUIActivityWrapperProps, type GenerativeUIAriaAttributes, type GenerativeUIComponentDefinition, type GenerativeUIComponentName, type GenerativeUIComponentProps, GenerativeUIError, type GenerativeUIErrorBoundaryConfig, type GenerativeUIErrorCode, type GenerativeUIErrorInfo, type GenerativeUIEventDefinition, type GenerativeUIEventHandler, type GenerativeUIFunctionArgs, type GenerativeUIFunctionDefinition, type GenerativeUIFunctionInput, type GenerativeUIFunctionName, type GenerativeUIHost, type GenerativeUIInvokeResult, type GenerativeUINodeFallbackProps, GenerativeUIProvider, type GenerativeUIProviderProps, type GenerativeUIRejectedOperation, type GenerativeUIRuntime, type GenerativeUISlotKind, type GenerativeUIStateOf, GenerativeUISurface, type GenerativeUISurfaceProps, type GenerativeUISurfaceRootProps, type GenerativeUIToolConfig, NativeNodeFallback, child, childList, createGenerativeUI, exportA2UICatalog, isGenerativeUIActivity, nativeGenerativeUIHost, useGenerativeUIAccessibility, useGenerativeUIFunction, useGenerativeUIRuntime, useGenerativeUIState };
|
|
341
|
+
//# sourceMappingURL=index.d.mts.map
|