@copilotkit/react-core 2.0.0-rc.4 → 2.0.0-rc.41
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 +1 -1
- package/dist/MarkdownRendererContext-BL8ct_3U.d.mts +34 -0
- package/dist/MarkdownRendererContext-BL8ct_3U.d.mts.map +1 -0
- package/dist/MarkdownRendererContext-C2J_lgqF.d.cts +34 -0
- package/dist/MarkdownRendererContext-C2J_lgqF.d.cts.map +1 -0
- package/dist/MarkdownSurfaces-Byz821bg.mjs +324 -0
- package/dist/MarkdownSurfaces-Byz821bg.mjs.map +1 -0
- package/dist/MarkdownSurfaces-D2Ck-cbb.cjs +378 -0
- package/dist/MarkdownSurfaces-D2Ck-cbb.cjs.map +1 -0
- package/dist/chat-Bf0vVdo7.mjs +1600 -0
- package/dist/chat-Bf0vVdo7.mjs.map +1 -0
- package/dist/chat-D3fxo6Ah.cjs +1784 -0
- package/dist/chat-D3fxo6Ah.cjs.map +1 -0
- package/dist/chat-DgP2N7bD.d.mts +233 -0
- package/dist/chat-DgP2N7bD.d.mts.map +1 -0
- package/dist/chat-DtHs4alO.d.cts +233 -0
- package/dist/chat-DtHs4alO.d.cts.map +1 -0
- package/dist/context.cjs +75 -63
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.cts +62 -107
- package/dist/context.d.cts.map +1 -1
- package/dist/context.d.mts +62 -107
- package/dist/context.d.mts.map +1 -1
- package/dist/context.mjs +76 -64
- package/dist/context.mjs.map +1 -1
- package/dist/generative-ui/native.cjs +66 -0
- package/dist/generative-ui/native.cjs.map +1 -0
- package/dist/generative-ui/native.d.cts +155 -0
- package/dist/generative-ui/native.d.cts.map +1 -0
- package/dist/generative-ui/native.d.mts +155 -0
- package/dist/generative-ui/native.d.mts.map +1 -0
- package/dist/generative-ui/native.mjs +24 -0
- package/dist/generative-ui/native.mjs.map +1 -0
- package/dist/generative-ui.cjs +757 -3056
- package/dist/generative-ui.cjs.map +1 -1
- package/dist/generative-ui.d.cts +2470 -4788
- package/dist/generative-ui.d.cts.map +1 -1
- package/dist/generative-ui.d.mts +2470 -4788
- package/dist/generative-ui.d.mts.map +1 -1
- package/dist/generative-ui.mjs +327 -2636
- package/dist/generative-ui.mjs.map +1 -1
- package/dist/headless.cjs +289 -1054
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +146 -371
- package/dist/headless.d.cts.map +1 -1
- package/dist/headless.d.mts +120 -236
- package/dist/headless.d.mts.map +1 -1
- package/dist/headless.mjs +283 -1054
- package/dist/headless.mjs.map +1 -1
- package/dist/hooks-2Ur8NQhj.d.cts +84 -0
- package/dist/hooks-2Ur8NQhj.d.cts.map +1 -0
- package/dist/hooks-BRYonCVu.d.mts +84 -0
- package/dist/hooks-BRYonCVu.d.mts.map +1 -0
- package/dist/index.cjs +9003 -13047
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +352 -834
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +349 -831
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1904 -7583
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +10629 -15765
- package/dist/index.umd.js.map +1 -1
- package/dist/refs-BIUfn1wb.cjs +43 -0
- package/dist/refs-BIUfn1wb.cjs.map +1 -0
- package/dist/refs-CMrRm3ta.mjs +31 -0
- package/dist/refs-CMrRm3ta.mjs.map +1 -0
- package/dist/use-generative-ui-root-C12htqbK.cjs +390 -0
- package/dist/use-generative-ui-root-C12htqbK.cjs.map +1 -0
- package/dist/use-generative-ui-root-CVgsDy1f.mjs +385 -0
- package/dist/use-generative-ui-root-CVgsDy1f.mjs.map +1 -0
- package/package.json +45 -23
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts +0 -954
- package/dist/MarkdownRendererContext-B4Us6mwL.d.cts.map +0 -1
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts +0 -954
- package/dist/MarkdownRendererContext-CRKFzsEB.d.mts.map +0 -1
- package/dist/MarkdownSurfaces-Bd--93O1.mjs +0 -3676
- package/dist/MarkdownSurfaces-Bd--93O1.mjs.map +0 -1
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs +0 -3991
- package/dist/MarkdownSurfaces-S4wfUl3J.cjs.map +0 -1
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import * as react from "react";
|
|
2
|
+
import React, { ComponentType, ReactNode } from "react";
|
|
3
|
+
import { AnyGenerativeUI, CreateGenerativeUIConfig, GenerativeUI, GenerativeUIBasesDefinitions, GenerativeUIComponentDefinition, GenerativeUIComponentName, GenerativeUIComponentProps, GenerativeUIDefinitions, GenerativeUIDefinitionsOf, GenerativeUIErrorInfo, GenerativeUIEventDefinition, GenerativeUIFunctionArgs, GenerativeUIFunctionDefinition, GenerativeUIFunctionDefinition as GenerativeUIFunctionDefinition$1, GenerativeUIFunctionInput, GenerativeUIFunctionName, GenerativeUIInvokeResult, GenerativeUIResultDefinitions, GenerativeUISchema, GenerativeUISlotKind, GenerativeUIStateOf, GenerativeUITheme } from "@copilotkit/shared/generative-ui";
|
|
4
|
+
import { GenerativeUIAccessibility, GenerativeUIAriaAttributes, GenerativeUIAriaAttributes as GenerativeUIAriaAttributes$1, GenerativeUIDispatcher, GenerativeUISurfaceManager } from "@copilotkit/core/generative-ui";
|
|
5
|
+
import { GenerativeUIRejectedOperation, GenerativeUISurfaceContent, GenerativeUIUserEvent } from "@copilotkit/shared";
|
|
6
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
7
|
+
import { ActivityMessageRenderProps, ActivityMessageRendererDef } from "@copilotkit/core";
|
|
8
|
+
|
|
9
|
+
//#region src/generative-ui/catalog.d.ts
|
|
10
|
+
/** One component of a generative UI, as the renderer reads it. */
|
|
11
|
+
type GenerativeUIComponentDefinition$1 = GenerativeUIComponentDefinition<ComponentType<any>>;
|
|
12
|
+
/**
|
|
13
|
+
* Experimental. The result of `createGenerativeUI`: the components the model
|
|
14
|
+
* can render, the app state they read, and the functions they call. Give it
|
|
15
|
+
* to the provider (`generativeUI={{ ui }}`) and to the typed hooks.
|
|
16
|
+
*/
|
|
17
|
+
type GenerativeUI$1<Definitions extends GenerativeUIDefinitions = GenerativeUIDefinitions> = GenerativeUI<Definitions, ComponentType<any>>;
|
|
18
|
+
/**
|
|
19
|
+
* Props that the renderer passes to a component:
|
|
20
|
+
* `function CheckoutForm(props: GenerativeUIComponentProps<typeof ui, "CheckoutForm">)`.
|
|
21
|
+
* Data props are the parsed `props` schema, bound props included. Event and
|
|
22
|
+
* slot props are present only when they are bound or filled. Each writable
|
|
23
|
+
* prop gets a setter (`value` gets `setValue`), which is always present.
|
|
24
|
+
*/
|
|
25
|
+
type GenerativeUIComponentProps$1<UI extends AnyGenerativeUI, Name extends keyof NonNullable<UI["definitions"]>["components"] & string> = GenerativeUIComponentProps<UI, Name, ReactNode>;
|
|
26
|
+
/** One new React component for each component of the bases that it names. */
|
|
27
|
+
type OverridesConfig<Bases extends readonly AnyGenerativeUI[]> = { [Name in keyof GenerativeUIBasesDefinitions<Bases>["components"] & string]?: {
|
|
28
|
+
component: ComponentType<GenerativeUIBasesDefinitions<Bases> extends infer Definitions extends GenerativeUIDefinitions ? GenerativeUIComponentProps$1<GenerativeUI$1<Definitions>, Name> : never>;
|
|
29
|
+
} };
|
|
30
|
+
/** The config of `createGenerativeUI`. */
|
|
31
|
+
type CreateGenerativeUIConfig$1<Bases extends readonly AnyGenerativeUI[], State extends Record<string, GenerativeUISchema>, Functions extends Record<string, GenerativeUIFunctionDefinition>, Props extends Record<string, unknown>, Events extends Record<string, unknown>, Slots extends Record<string, unknown>, Writable extends Record<string, unknown>> = CreateGenerativeUIConfig<Bases, State, Functions, Props, Events, Slots, Writable, OverridesConfig<Bases>>;
|
|
32
|
+
/**
|
|
33
|
+
* Experimental. Declares the components the model can render, the app state
|
|
34
|
+
* they read, and the functions they call.
|
|
35
|
+
*
|
|
36
|
+
* - A prop with the name of a top-level state key is bound to that state.
|
|
37
|
+
* - `bind: { prop: (state, props) => value }` binds a prop to a selector.
|
|
38
|
+
* - An event binds to the function with its name, else to the name without
|
|
39
|
+
* `on` (`onAddToCart` calls `addToCart`).
|
|
40
|
+
* - `writable: ["value"]` gives the component a `setValue` prop. See
|
|
41
|
+
* `GenerativeUIComponentDefinition.writable`.
|
|
42
|
+
*
|
|
43
|
+
* The model does not see bound props or matched events.
|
|
44
|
+
*
|
|
45
|
+
* @param config - `id`, then optional `extends`, `state`, `functions` and
|
|
46
|
+
* `overrides`, then `components`. Put `state` before `components`, so the selectors
|
|
47
|
+
* get typed state.
|
|
48
|
+
* @throws Error when a name comes from two places, an override names no
|
|
49
|
+
* component of the bases, `props` is not an object
|
|
50
|
+
* schema with a JSON Schema, a key is reserved or used
|
|
51
|
+
* twice on a component, an event matches two functions, an unmatched event
|
|
52
|
+
* has no `parameters`, a `bind` key is not a prop, a `writable` key is not
|
|
53
|
+
* a prop or is a bound prop, or a setter name is already a key of the
|
|
54
|
+
* component. Also throws when `parameterOrder` contains duplicate or unknown
|
|
55
|
+
* keys, or an ordered component declares integer-index keys whose JSON object
|
|
56
|
+
* enumeration order cannot be controlled.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const ui = createGenerativeUI({
|
|
61
|
+
* id: "acme/store@1",
|
|
62
|
+
* state: { cart: cartSchema },
|
|
63
|
+
* functions: { addToCart: { parameters: z.object({ productId: z.string() }) } },
|
|
64
|
+
* components: {
|
|
65
|
+
* CartSummary: {
|
|
66
|
+
* component: CartSummary,
|
|
67
|
+
* props: z.object({ count: z.number() }),
|
|
68
|
+
* bind: { count: (state) => state.cart.count },
|
|
69
|
+
* },
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function createGenerativeUI<Bases extends readonly AnyGenerativeUI[] = [], State extends Record<string, GenerativeUISchema> = {}, Functions extends Record<string, GenerativeUIFunctionDefinition> = {}, Props extends Record<string, unknown> = {}, Events extends Record<string, unknown> = {}, Slots extends Record<string, unknown> = {}, Writable extends Record<string, unknown> = {}>(config: CreateGenerativeUIConfig$1<Bases, State, Functions, Props, Events, Slots, Writable>): GenerativeUI$1<GenerativeUIResultDefinitions<Bases, State, Functions, Props, Events, Slots, Writable>>;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/generative-ui/accessibility.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Experimental. The ARIA attributes of the `accessibility` that the model
|
|
79
|
+
* gave the component being rendered, to spread on its root element. The
|
|
80
|
+
* standard components do this; a custom component does it itself:
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* function Panel({ children }: { children?: ReactNode }) {
|
|
85
|
+
* const aria = useGenerativeUIAccessibility();
|
|
86
|
+
* return <section {...aria}>{children}</section>;
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* Outside of generated UI it gives `{}`.
|
|
91
|
+
*/
|
|
92
|
+
declare function useGenerativeUIAccessibility(): GenerativeUIAriaAttributes;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/generative-ui/runtime-context.d.ts
|
|
95
|
+
interface GenerativeUIErrorBoundaryConfig {
|
|
96
|
+
/**
|
|
97
|
+
* Replaces the host's fallback for a component that failed to render. It
|
|
98
|
+
* is not used for invalid props, unknown types, cyclic references or a
|
|
99
|
+
* failed surface: the host's `NodeFallback` shows those. If it throws,
|
|
100
|
+
* the host's fallback stands in and the error is reported. `error` is
|
|
101
|
+
* always an Error: a component that throws something else (a string,
|
|
102
|
+
* `undefined`) gets an Error that describes it, with the value as its
|
|
103
|
+
* `cause`.
|
|
104
|
+
*/
|
|
105
|
+
fallback?: (props: {
|
|
106
|
+
error: Error;
|
|
107
|
+
retry: () => void;
|
|
108
|
+
surfaceId: string;
|
|
109
|
+
componentId: string;
|
|
110
|
+
}) => ReactNode;
|
|
111
|
+
/**
|
|
112
|
+
* Called for render, props, operation, function and event failures. A
|
|
113
|
+
* render or props failure that stays the same across new revisions of the
|
|
114
|
+
* node or the surface is reported once, until the node or surface renders
|
|
115
|
+
* again. A failed function or event is reported on every call.
|
|
116
|
+
*/
|
|
117
|
+
onError?: (info: GenerativeUIErrorInfo) => void;
|
|
118
|
+
}
|
|
119
|
+
interface GenerativeUIBaseConfig {
|
|
120
|
+
/**
|
|
121
|
+
* The result of `createGenerativeUI`: the components the model can render,
|
|
122
|
+
* the app state they read and the functions they call.
|
|
123
|
+
*/
|
|
124
|
+
ui: GenerativeUI$1;
|
|
125
|
+
/**
|
|
126
|
+
* The agents that get the generative UI. When omitted, every agent gets
|
|
127
|
+
* it. Other agents get no envelope.
|
|
128
|
+
*/
|
|
129
|
+
agentIds?: string[];
|
|
130
|
+
/**
|
|
131
|
+
* Web only. Values for the `--a2ui-*` CSS variables and the map style.
|
|
132
|
+
* Top-level values apply in both modes. `dark` changes them in dark mode,
|
|
133
|
+
* which is on under a `.dark` class, like the CopilotKit chat. React
|
|
134
|
+
* Native ignores it.
|
|
135
|
+
*/
|
|
136
|
+
theme?: GenerativeUITheme;
|
|
137
|
+
/** Fallback UI and error reporting for generated UI. */
|
|
138
|
+
errorBoundary?: GenerativeUIErrorBoundaryConfig;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The tool transport: the model calls the `render_ui` tool, and the runtime
|
|
142
|
+
* validates each operation before it streams it to the client.
|
|
143
|
+
*/
|
|
144
|
+
interface GenerativeUIToolConfig extends GenerativeUIBaseConfig {
|
|
145
|
+
/** Leave it out, or set "tool". */
|
|
146
|
+
transport?: "tool";
|
|
147
|
+
sendContext?: never;
|
|
148
|
+
includeCatalog?: never;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The markdown transport: the model writes the operations in ```a2ui fences
|
|
152
|
+
* in its reply. The client reads and validates them.
|
|
153
|
+
*/
|
|
154
|
+
interface GenerativeUIMarkdownConfig extends GenerativeUIBaseConfig {
|
|
155
|
+
transport: "markdown";
|
|
156
|
+
/**
|
|
157
|
+
* Send the component schema and the fence guideline as context entries.
|
|
158
|
+
* Set `false` when the backend builds its own prompt from the envelope.
|
|
159
|
+
* Default `true`.
|
|
160
|
+
*/
|
|
161
|
+
sendContext?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Send the component schemas in the envelope (`catalog.components`).
|
|
164
|
+
* Default `true`.
|
|
165
|
+
*/
|
|
166
|
+
includeCatalog?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Experimental. The `generativeUI` prop of `CopilotKitProvider`. Set
|
|
170
|
+
* `transport: "markdown"` to get the markdown options.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```tsx
|
|
174
|
+
* <CopilotKitProvider generativeUI={{ ui }} />
|
|
175
|
+
* <CopilotKitProvider generativeUI={{ ui, transport: "markdown", sendContext: false }} />
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
type GenerativeUIConfig = GenerativeUIToolConfig | GenerativeUIMarkdownConfig;
|
|
179
|
+
interface GenerativeUIRuntime {
|
|
180
|
+
manager: GenerativeUISurfaceManager;
|
|
181
|
+
dispatcher: GenerativeUIDispatcher;
|
|
182
|
+
/** The generative UI given to the provider as `generativeUI={{ ui }}`. */
|
|
183
|
+
ui: GenerativeUI$1;
|
|
184
|
+
/** How the model sends operations. "tool" when the config leaves it out. */
|
|
185
|
+
transport: "tool" | "markdown";
|
|
186
|
+
/** The latest `generativeUI` config of the provider. */
|
|
187
|
+
readonly config: GenerativeUIConfig;
|
|
188
|
+
/**
|
|
189
|
+
* The latest `theme`. The host's surface root gets it: on the web it sets
|
|
190
|
+
* the CSS variables; the React Native root ignores it.
|
|
191
|
+
*/
|
|
192
|
+
theme?: GenerativeUITheme;
|
|
193
|
+
forwardEvent: (event: GenerativeUIUserEvent, agentId: string | undefined) => Promise<GenerativeUIInvokeResult>;
|
|
194
|
+
reportError: (info: GenerativeUIErrorInfo) => void;
|
|
195
|
+
readonly errorFallback?: GenerativeUIErrorBoundaryConfig["fallback"];
|
|
196
|
+
}
|
|
197
|
+
declare const GenerativeUIRuntimeContext: react.Context<GenerativeUIRuntime | null>;
|
|
198
|
+
declare function useGenerativeUIRuntime(): GenerativeUIRuntime | null;
|
|
199
|
+
declare function useRequiredGenerativeUIRuntime(): GenerativeUIRuntime;
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region src/types/react-activity-message-renderer.d.ts
|
|
202
|
+
/**
|
|
203
|
+
* An activity message renderer for React: a React component that draws
|
|
204
|
+
* activity messages of one `activityType` (or `"*"` for any type). The
|
|
205
|
+
* component receives {@link ActivityMessageRenderProps}.
|
|
206
|
+
*
|
|
207
|
+
* @typeParam TActivityContent - The shape of the activity content.
|
|
208
|
+
*/
|
|
209
|
+
type ReactActivityMessageRenderer<TActivityContent> = ActivityMessageRendererDef<TActivityContent, React.ComponentType<ActivityMessageRenderProps<TActivityContent>>>;
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/generative-ui/chat.d.ts
|
|
212
|
+
interface GenerativeUIChatSurfaceProps {
|
|
213
|
+
surfaceId: string;
|
|
214
|
+
isStreaming: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Set when operations from the latest render_ui call were rejected. The
|
|
217
|
+
* message is user-facing; `error.cause` holds the same list as `rejected`.
|
|
218
|
+
*/
|
|
219
|
+
error?: Error;
|
|
220
|
+
/** Rejected operations from the latest render_ui call, with validator reasons. */
|
|
221
|
+
rejected: GenerativeUIRejectedOperation[];
|
|
222
|
+
children: ReactNode;
|
|
223
|
+
}
|
|
224
|
+
declare function DefaultGenerativeUIChatCard({
|
|
225
|
+
surfaceId,
|
|
226
|
+
error,
|
|
227
|
+
children
|
|
228
|
+
}: GenerativeUIChatSurfaceProps): react_jsx_runtime0.JSX.Element;
|
|
229
|
+
/** Hides the raw `render_ui` tool call; the surface activity owns the UX. */
|
|
230
|
+
declare function GenerativeUIToolCallRenderer(): null;
|
|
231
|
+
//#endregion
|
|
232
|
+
export { createGenerativeUI as A, GenerativeUIEventDefinition as C, GenerativeUIFunctionName as D, GenerativeUIFunctionInput as E, GenerativeUISlotKind as O, GenerativeUIDefinitionsOf as S, GenerativeUIFunctionDefinition$1 as T, CreateGenerativeUIConfig$1 as _, GenerativeUIConfig as a, GenerativeUIComponentName as b, GenerativeUIRuntime as c, GenerativeUIToolConfig as d, useGenerativeUIRuntime as f, useGenerativeUIAccessibility as g, GenerativeUIAriaAttributes$1 as h, ReactActivityMessageRenderer as i, GenerativeUIStateOf as k, GenerativeUIRuntimeContext as l, GenerativeUIAccessibility as m, GenerativeUIChatSurfaceProps as n, GenerativeUIErrorBoundaryConfig as o, useRequiredGenerativeUIRuntime as p, GenerativeUIToolCallRenderer as r, GenerativeUIMarkdownConfig as s, DefaultGenerativeUIChatCard as t, GenerativeUITheme as u, GenerativeUI$1 as v, GenerativeUIFunctionArgs as w, GenerativeUIComponentProps$1 as x, GenerativeUIComponentDefinition$1 as y };
|
|
233
|
+
//# sourceMappingURL=chat-DtHs4alO.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-DtHs4alO.d.cts","names":[],"sources":["../src/generative-ui/catalog.ts","../src/generative-ui/accessibility.ts","../src/generative-ui/runtime-context.ts","../src/types/react-activity-message-renderer.ts","../src/generative-ui/chat.tsx"],"mappings":";;;;;;;;;;KA2CY,iCAAA,GACV,+BAAA,CAAsC,aAAA;;AADxC;;;;KAaY,cAAA,qBACU,uBAAA,GAA0B,uBAAA,IAC5C,YAAA,CAAmB,WAAA,EAAa,aAAA;AAFpC;;;;;;;AAAA,KAWY,4BAAA,YACC,eAAA,qBACQ,WAAA,CAAY,EAAA,2CAC7B,0BAAA,CAAiC,EAAA,EAAI,IAAA,EAAM,SAAA;;KAG1C,eAAA,wBAAuC,eAAA,uBAC3B,4BAAA,CAA6B,KAAA;EAC1C,SAAA,EAAW,aAAA,CACT,4BAAA,CAA6B,KAAA,oCAC3B,uBA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e,0BAAA,SAAmC,sBAAA;EAClD,SAAA;EFL0B;;;;;EEW1B,WAAA;EFXE;;;;EEgBF,cAAA;AAAA;;;;;;;AFNF;;;;KEmBY,kBAAA,GACR,sBAAA,GACA,0BAAA;AAAA,UAEa,mBAAA;EACf,OAAA,EAAS,0BAAA;EACT,UAAA,EAAY,sBAAA;EFrBE;EEuBd,EAAA,EAAI,cAAA;EFrBU;EEuBd,SAAA;EFpBA;EAAA,SEsBS,MAAA,EAAQ,kBAAA;EFpBjB;;;;EEyBA,KAAA,GAAQ,iBAAA;EACR,YAAA,GACE,KAAA,EAAO,qBAAA,EACP,OAAA,yBACG,OAAA,CAAQ,wBAAA;EACb,WAAA,GAAc,IAAA,EAAM,qBAAA;EAAA,SACX,aAAA,GAAgB,+BAAA;AAAA;AAAA,cAGd,0BAAA,EAA0B,KAAA,CAAA,OAAA,CAAA,mBAAA;AAAA,iBAGvB,sBAAA,CAAA,GAA0B,mBAAA;AAAA,iBAI1B,8BAAA,CAAA,GAAkC,mBAAA;;;;;;;;;;KC5HtC,4BAAA,qBACV,0BAAA,CACE,gBAAA,EACA,KAAA,CAAM,aAAA,CAAc,0BAAA,CAA2B,gBAAA;;;UCSlC,4BAAA;EACf,SAAA;EACA,WAAA;;;AJgBF;;EIXE,KAAA,GAAQ,KAAA;EJYR;EIVA,QAAA,EAAU,6BAAA;EACV,QAAA,EAAU,SAAA;AAAA;AAAA,iBAOI,2BAAA,CAAA;EACd,SAAA;EACA,KAAA;EACA;AAAA,GACC,4BAAA,GAA4B,kBAAA,CAAA,GAAA,CAAA,OAAA;;iBA0Ef,4BAAA,CAAA"}
|
package/dist/context.cjs
CHANGED
|
@@ -5,98 +5,110 @@ let react = require("react");
|
|
|
5
5
|
let _copilotkit_core = require("@copilotkit/core");
|
|
6
6
|
|
|
7
7
|
//#region src/lib/react-core.ts
|
|
8
|
+
/**
|
|
9
|
+
* Wait for pending React state updates before the follow-up agent run.
|
|
10
|
+
*
|
|
11
|
+
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
12
|
+
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
13
|
+
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
14
|
+
* synchronously after React commits that batch.
|
|
15
|
+
*
|
|
16
|
+
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
17
|
+
* MessageChannel task runs first, committing the pending state and running
|
|
18
|
+
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
19
|
+
* call then reads fresh context.
|
|
20
|
+
*/
|
|
21
|
+
function waitForReactCommit() {
|
|
22
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
23
|
+
}
|
|
8
24
|
var CopilotKitCoreReact = class extends _copilotkit_core.CopilotKitCore {
|
|
25
|
+
_renderers;
|
|
9
26
|
constructor(config) {
|
|
10
|
-
super(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
27
|
+
super({
|
|
28
|
+
...config,
|
|
29
|
+
ɵwaitForFrameworkUpdates: waitForReactCommit
|
|
30
|
+
});
|
|
31
|
+
this._renderers = new _copilotkit_core.ɵRendererRegistry({
|
|
32
|
+
toolCalls: config.renderToolCalls,
|
|
33
|
+
activity: config.renderActivityMessages,
|
|
34
|
+
custom: config.renderCustomMessages
|
|
35
|
+
});
|
|
36
|
+
this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));
|
|
37
|
+
this.ɵsubscribeToInterruptPayload(() => {
|
|
38
|
+
this.notifySubscribers((subscriber) => {
|
|
39
|
+
return subscriber.onInterruptElementChanged?.({
|
|
40
|
+
copilotkit: this,
|
|
41
|
+
interruptElement: this.interruptElement
|
|
42
|
+
});
|
|
43
|
+
}, "Subscriber onInterruptElementChanged error:");
|
|
44
|
+
});
|
|
20
45
|
}
|
|
21
46
|
get renderCustomMessages() {
|
|
22
|
-
return this.
|
|
47
|
+
return this._renderers.custom;
|
|
23
48
|
}
|
|
24
49
|
get renderActivityMessages() {
|
|
25
|
-
return this.
|
|
50
|
+
return this._renderers.activity;
|
|
26
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Prop, hook and built-in renderers merged. For one name and agentId, a
|
|
54
|
+
* hook renderer wins over a prop one, and both win over a built-in one.
|
|
55
|
+
*/
|
|
27
56
|
get renderToolCalls() {
|
|
28
|
-
|
|
29
|
-
if (this._cachedMergedRenderToolCalls) return this._cachedMergedRenderToolCalls;
|
|
30
|
-
const merged = /* @__PURE__ */ new Map();
|
|
31
|
-
for (const rc of this._renderToolCalls) merged.set(`${rc.agentId ?? ""}:${rc.name}`, rc);
|
|
32
|
-
for (const [key, rc] of this._hookRenderToolCalls) merged.set(key, rc);
|
|
33
|
-
this._cachedMergedRenderToolCalls = Array.from(merged.values());
|
|
34
|
-
return this._cachedMergedRenderToolCalls;
|
|
57
|
+
return this._renderers.toolCalls;
|
|
35
58
|
}
|
|
36
59
|
setRenderActivityMessages(renderers) {
|
|
37
|
-
this.
|
|
60
|
+
this._renderers.setActivity(renderers);
|
|
38
61
|
}
|
|
39
62
|
setRenderCustomMessages(renderers) {
|
|
40
|
-
this.
|
|
63
|
+
this._renderers.setCustom(renderers);
|
|
41
64
|
}
|
|
42
65
|
setRenderToolCalls(renderToolCalls) {
|
|
43
|
-
this.
|
|
44
|
-
this._cachedMergedRenderToolCalls = null;
|
|
45
|
-
this._notifyRenderToolCallsChanged();
|
|
66
|
+
this._renderers.setPropToolCalls(renderToolCalls);
|
|
46
67
|
}
|
|
47
68
|
addHookRenderToolCall(entry) {
|
|
48
|
-
|
|
49
|
-
this._hookRenderToolCalls.set(key, entry);
|
|
50
|
-
this._cachedMergedRenderToolCalls = null;
|
|
51
|
-
this._notifyRenderToolCallsChanged();
|
|
69
|
+
this._renderers.addHookToolCall(entry);
|
|
52
70
|
}
|
|
53
71
|
removeHookRenderToolCall(name, agentId) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
this._renderers.removeHookToolCall(name, agentId);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @internal Add a renderer for a tool a built-in feature owns (A2UI,
|
|
76
|
+
* generative UI). Prop and hook renderers with the same name and agent win
|
|
77
|
+
* over it, and `setRenderToolCalls` never removes it.
|
|
78
|
+
*
|
|
79
|
+
* @returns A function that removes the renderer.
|
|
80
|
+
*/
|
|
81
|
+
ɵaddBuiltInRenderToolCall(entry) {
|
|
82
|
+
return this._renderers.addBuiltInToolCall(entry);
|
|
59
83
|
}
|
|
60
|
-
|
|
84
|
+
notifyRenderersChanged(kind) {
|
|
61
85
|
this.notifySubscribers((subscriber) => {
|
|
62
86
|
const reactSubscriber = subscriber;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
switch (kind) {
|
|
88
|
+
case "toolCalls": return reactSubscriber.onRenderToolCallsChanged?.({
|
|
89
|
+
copilotkit: this,
|
|
90
|
+
renderToolCalls: this.renderToolCalls
|
|
91
|
+
});
|
|
92
|
+
case "activity": return reactSubscriber.onRenderActivityMessagesChanged?.({
|
|
93
|
+
copilotkit: this,
|
|
94
|
+
renderActivityMessages: this.renderActivityMessages
|
|
95
|
+
});
|
|
96
|
+
case "custom": return reactSubscriber.onRenderCustomMessagesChanged?.({
|
|
97
|
+
copilotkit: this,
|
|
98
|
+
renderCustomMessages: this.renderCustomMessages
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}, `Subscriber renderer change (${kind}) error:`);
|
|
68
102
|
}
|
|
69
103
|
get interruptElement() {
|
|
70
|
-
return this
|
|
104
|
+
return this.ɵinterruptPayload;
|
|
71
105
|
}
|
|
72
106
|
setInterruptElement(element) {
|
|
73
|
-
this
|
|
74
|
-
this.notifySubscribers((subscriber) => {
|
|
75
|
-
subscriber.onInterruptElementChanged?.({
|
|
76
|
-
copilotkit: this,
|
|
77
|
-
interruptElement: this._interruptElement
|
|
78
|
-
});
|
|
79
|
-
}, "Subscriber onInterruptElementChanged error:");
|
|
107
|
+
this.ɵsetInterruptPayload(element);
|
|
80
108
|
}
|
|
81
109
|
subscribe(subscriber) {
|
|
82
110
|
return super.subscribe(subscriber);
|
|
83
111
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Wait for pending React state updates before the follow-up agent run.
|
|
86
|
-
*
|
|
87
|
-
* When a frontend tool handler calls setState(), React 18 batches the update
|
|
88
|
-
* and schedules a commit via its internal scheduler (MessageChannel). The
|
|
89
|
-
* useAgentContext hook registers context via useLayoutEffect, which runs
|
|
90
|
-
* synchronously after React commits that batch.
|
|
91
|
-
*
|
|
92
|
-
* Awaiting a zero-delay timeout yields to the macrotask queue. React's
|
|
93
|
-
* MessageChannel task runs first, committing the pending state and running
|
|
94
|
-
* useLayoutEffect (which updates the context store). The follow-up runAgent
|
|
95
|
-
* call then reads fresh context.
|
|
96
|
-
*/
|
|
97
|
-
async waitForPendingFrameworkUpdates() {
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
99
|
-
}
|
|
100
112
|
};
|
|
101
113
|
|
|
102
114
|
//#endregion
|
package/dist/context.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","names":["CopilotKitCore"],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private _renderToolCalls: ReactToolCallRenderer<any>[] = [];\n private _hookRenderToolCalls: Map<string, ReactToolCallRenderer<any>> =\n new Map();\n private _cachedMergedRenderToolCalls: ReactToolCallRenderer<any>[] | null =\n null;\n private _renderCustomMessages: ReactCustomMessageRenderer[] = [];\n private _renderActivityMessages: ReactActivityMessageRenderer<any>[] = [];\n private _interruptElement: React.ReactElement | null = null;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super(config);\n this._renderToolCalls = config.renderToolCalls ?? [];\n this._renderCustomMessages = config.renderCustomMessages ?? [];\n this._renderActivityMessages = config.renderActivityMessages ?? [];\n }\n\n get renderCustomMessages(): Readonly<ReactCustomMessageRenderer[]> {\n return this._renderCustomMessages;\n }\n\n get renderActivityMessages(): Readonly<ReactActivityMessageRenderer<any>>[] {\n return this._renderActivityMessages;\n }\n\n get renderToolCalls(): Readonly<ReactToolCallRenderer<any>>[] {\n if (this._hookRenderToolCalls.size === 0) {\n return this._renderToolCalls;\n }\n if (this._cachedMergedRenderToolCalls) {\n return this._cachedMergedRenderToolCalls;\n }\n // Merge: hook entries override prop entries with the same key\n const merged = new Map<string, ReactToolCallRenderer<any>>();\n for (const rc of this._renderToolCalls) {\n merged.set(`${rc.agentId ?? \"\"}:${rc.name}`, rc);\n }\n for (const [key, rc] of this._hookRenderToolCalls) {\n merged.set(key, rc);\n }\n this._cachedMergedRenderToolCalls = Array.from(merged.values());\n return this._cachedMergedRenderToolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderActivityMessages = renderers;\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderCustomMessages = renderers;\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderToolCalls = renderToolCalls;\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n const key = `${entry.agentId ?? \"\"}:${entry.name}`;\n this._hookRenderToolCalls.set(key, entry);\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n const key = `${agentId ?? \"\"}:${name}`;\n if (this._hookRenderToolCalls.delete(key)) {\n this._cachedMergedRenderToolCalls = null;\n this._notifyRenderToolCallsChanged();\n }\n }\n\n private _notifyRenderToolCallsChanged(): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n if (reactSubscriber.onRenderToolCallsChanged) {\n reactSubscriber.onRenderToolCallsChanged({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n }\n }, \"Subscriber onRenderToolCallsChanged error:\");\n }\n\n get interruptElement(): React.ReactElement | null {\n return this._interruptElement;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this._interruptElement = element;\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this._interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n\n /**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\n async waitForPendingFrameworkUpdates(): Promise<void> {\n await new Promise<void>((resolve) => setTimeout(resolve, 0));\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;AAiCA,IAAa,sBAAb,cAAyCA,gCAAe;CAUtD,YAAY,QAAmC;AAC7C,QAAM,OAAO;0BAV0C,EAAE;8CAEzD,IAAI,KAAK;sCAET;+BAC4D,EAAE;iCACO,EAAE;2BAClB;AAIrD,OAAK,mBAAmB,OAAO,mBAAmB,EAAE;AACpD,OAAK,wBAAwB,OAAO,wBAAwB,EAAE;AAC9D,OAAK,0BAA0B,OAAO,0BAA0B,EAAE;;CAGpE,IAAI,uBAA+D;AACjE,SAAO,KAAK;;CAGd,IAAI,yBAAwE;AAC1E,SAAO,KAAK;;CAGd,IAAI,kBAA0D;AAC5D,MAAI,KAAK,qBAAqB,SAAS,EACrC,QAAO,KAAK;AAEd,MAAI,KAAK,6BACP,QAAO,KAAK;EAGd,MAAM,yBAAS,IAAI,KAAyC;AAC5D,OAAK,MAAM,MAAM,KAAK,iBACpB,QAAO,IAAI,GAAG,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iC,IAAI,KAAK;AAEvD,MAAa,6CACX,KACD;AAED,MAAa,sBAA8C;CACzD,MAAM,gCAAqB,kBAAkB;CAC7C,MAAM,GAAG,sCAA2B,MAAc,IAAI,GAAG,EAAE;AAE3D,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,uDAAuD;AAEzE,4BAAgB;EACd,MAAM,eAAe,QAAQ,WAAW,UAAU;GAChD,wCAAwC;AACtC,iBAAa;;GAEf,wBAAwB;AACtB,iBAAa;;GAEhB,CAAC;AACF,eAAa;AACX,gBAAa,aAAa;;IAG3B,EAAE,CAAC;AAEN,QAAO;;AAOT,MAAa,0CAAoD;CAC/D,QAAQ;CACR,SAAS;CACT,oBAAoB;CACpB,gBAAgB;CACjB,CAAwB;AAEzB,MAAa,gDACA,eAAe;AAe5B,MAAa,oDACX,OACD;AAED,MAAa,gDACA,yBAAyB"}
|
|
1
|
+
{"version":3,"file":"context.cjs","names":["CopilotKitCore","ɵRendererRegistry"],"sources":["../src/lib/react-core.ts","../src/context.ts"],"sourcesContent":["import React from \"react\";\nimport type {\n ReactActivityMessageRenderer,\n ReactToolCallRenderer,\n} from \"../types\";\nimport type { ReactCustomMessageRenderer } from \"../types/react-custom-message-renderer\";\nimport { CopilotKitCore, ɵRendererRegistry } from \"@copilotkit/core\";\nimport type {\n CopilotKitCoreConfig,\n CopilotKitCoreSubscriber,\n CopilotKitCoreSubscription,\n ɵRendererKind,\n} from \"@copilotkit/core\";\n\nexport interface CopilotKitCoreReactConfig extends CopilotKitCoreConfig {\n // Add any additional configuration properties specific to the React implementation\n renderToolCalls?: ReactToolCallRenderer<any>[];\n renderActivityMessages?: ReactActivityMessageRenderer<any>[];\n\n // Add custom message renderers\n renderCustomMessages?: ReactCustomMessageRenderer[];\n}\n\nexport interface CopilotKitCoreReactSubscriber extends CopilotKitCoreSubscriber {\n onRenderToolCallsChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderToolCalls: readonly ReactToolCallRenderer<any>[];\n }) => void | Promise<void>;\n onRenderActivityMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderActivityMessages: readonly ReactActivityMessageRenderer<any>[];\n }) => void | Promise<void>;\n onRenderCustomMessagesChanged?: (event: {\n copilotkit: CopilotKitCore;\n renderCustomMessages: readonly ReactCustomMessageRenderer[];\n }) => void | Promise<void>;\n onInterruptElementChanged?: (event: {\n copilotkit: CopilotKitCore;\n interruptElement: React.ReactElement | null;\n }) => void | Promise<void>;\n}\n\n/**\n * Wait for pending React state updates before the follow-up agent run.\n *\n * When a frontend tool handler calls setState(), React 18 batches the update\n * and schedules a commit via its internal scheduler (MessageChannel). The\n * useAgentContext hook registers context via useLayoutEffect, which runs\n * synchronously after React commits that batch.\n *\n * Awaiting a zero-delay timeout yields to the macrotask queue. React's\n * MessageChannel task runs first, committing the pending state and running\n * useLayoutEffect (which updates the context store). The follow-up runAgent\n * call then reads fresh context.\n */\nfunction waitForReactCommit() {\n return new Promise<void>((resolve) => setTimeout(resolve, 0));\n}\n\nexport class CopilotKitCoreReact extends CopilotKitCore {\n private readonly _renderers: ɵRendererRegistry<\n ReactToolCallRenderer<any>,\n ReactActivityMessageRenderer<any>,\n ReactCustomMessageRenderer\n >;\n\n constructor(config: CopilotKitCoreReactConfig) {\n super({\n ...config,\n ɵwaitForFrameworkUpdates: waitForReactCommit,\n });\n this._renderers = new ɵRendererRegistry({\n toolCalls: config.renderToolCalls,\n activity: config.renderActivityMessages,\n custom: config.renderCustomMessages,\n });\n this._renderers.subscribe((kind) => this.notifyRenderersChanged(kind));\n // The element lives in core's generic interrupt slot; keep the React\n // subscriber event for existing listeners.\n this.ɵsubscribeToInterruptPayload(() => {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n return reactSubscriber.onInterruptElementChanged?.({\n copilotkit: this,\n interruptElement: this.interruptElement,\n });\n }, \"Subscriber onInterruptElementChanged error:\");\n });\n }\n\n get renderCustomMessages() {\n return this._renderers.custom;\n }\n\n get renderActivityMessages() {\n return this._renderers.activity;\n }\n\n /**\n * Prop, hook and built-in renderers merged. For one name and agentId, a\n * hook renderer wins over a prop one, and both win over a built-in one.\n */\n get renderToolCalls() {\n return this._renderers.toolCalls;\n }\n\n setRenderActivityMessages(\n renderers: ReactActivityMessageRenderer<any>[],\n ): void {\n this._renderers.setActivity(renderers);\n }\n\n setRenderCustomMessages(renderers: ReactCustomMessageRenderer[]): void {\n this._renderers.setCustom(renderers);\n }\n\n setRenderToolCalls(renderToolCalls: ReactToolCallRenderer<any>[]): void {\n this._renderers.setPropToolCalls(renderToolCalls);\n }\n\n addHookRenderToolCall(entry: ReactToolCallRenderer<any>): void {\n this._renderers.addHookToolCall(entry);\n }\n\n removeHookRenderToolCall(name: string, agentId?: string): void {\n this._renderers.removeHookToolCall(name, agentId);\n }\n\n /**\n * @internal Add a renderer for a tool a built-in feature owns (A2UI,\n * generative UI). Prop and hook renderers with the same name and agent win\n * over it, and `setRenderToolCalls` never removes it.\n *\n * @returns A function that removes the renderer.\n */\n ɵaddBuiltInRenderToolCall(entry: ReactToolCallRenderer): () => void {\n return this._renderers.addBuiltInToolCall(entry);\n }\n\n private notifyRenderersChanged(kind: ɵRendererKind): void {\n void this.notifySubscribers((subscriber) => {\n const reactSubscriber = subscriber as CopilotKitCoreReactSubscriber;\n switch (kind) {\n case \"toolCalls\":\n return reactSubscriber.onRenderToolCallsChanged?.({\n copilotkit: this,\n renderToolCalls: this.renderToolCalls,\n });\n case \"activity\":\n return reactSubscriber.onRenderActivityMessagesChanged?.({\n copilotkit: this,\n renderActivityMessages: this.renderActivityMessages,\n });\n case \"custom\":\n return reactSubscriber.onRenderCustomMessagesChanged?.({\n copilotkit: this,\n renderCustomMessages: this.renderCustomMessages,\n });\n }\n }, `Subscriber renderer change (${kind}) error:`);\n }\n\n get interruptElement(): React.ReactElement | null {\n return this.ɵinterruptPayload as React.ReactElement | null;\n }\n\n setInterruptElement(element: React.ReactElement | null): void {\n this.ɵsetInterruptPayload(element);\n }\n\n // Override to accept React-specific subscriber type\n subscribe(\n subscriber: CopilotKitCoreReactSubscriber,\n ): CopilotKitCoreSubscription {\n return super.subscribe(subscriber);\n }\n}\n","\"use client\";\n\nimport { createContext, useContext, useEffect, useReducer } from \"react\";\nimport { CopilotKitCoreReact } from \"./lib/react-core\";\nimport type { CopilotKitCoreReactConfig } from \"./lib/react-core\";\nimport type { LicenseContextValue } from \"@copilotkit/shared\";\n\n// Re-export so headless.ts (and consumers) reference the same type declaration.\nexport { CopilotKitCoreReact };\nexport type { CopilotKitCoreReactConfig };\n\nexport interface CopilotKitContextValue {\n copilotkit: CopilotKitCoreReact;\n /**\n * Whether CopilotKit should automatically mount Intelligence indicators.\n * Defaults to true when omitted for compatibility with custom providers.\n */\n showIntelligenceIndicator?: boolean;\n /**\n * Set of tool call IDs currently being executed.\n * This is tracked at the provider level to ensure tool execution events\n * are captured even before child components mount.\n */\n executingToolCallIds: ReadonlySet<string>;\n}\n\nexport const EMPTY_SET: ReadonlySet<string> = new Set();\n\nexport const CopilotKitContext = createContext<CopilotKitContextValue | null>(\n null,\n);\n\nexport const useCopilotKit = (): CopilotKitContextValue => {\n const context = useContext(CopilotKitContext);\n const [, forceUpdate] = useReducer((x: number) => x + 1, 0);\n\n if (!context) {\n throw new Error(\"useCopilotKit must be used within CopilotKitProvider\");\n }\n useEffect(() => {\n const subscription = context.copilotkit.subscribe({\n onRuntimeConnectionStatusChanged: () => {\n forceUpdate();\n },\n onHeadersChanged: () => {\n forceUpdate();\n },\n });\n return () => {\n subscription.unsubscribe();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return context;\n};\n\n// License context — shared between web and RN providers.\n// Default is permissive (all features allowed) — providers override via createLicenseContextValue.\n// Inlined here to avoid a runtime import from @copilotkit/shared, which pulls in\n// Node-only deps (jose) that break React Native's Metro bundler.\nexport const LicenseContext = createContext<LicenseContextValue>({\n status: null,\n license: null,\n checkFeature: () => true,\n getLimit: () => null,\n} as LicenseContextValue);\n\nexport const useLicenseContext = (): LicenseContextValue =>\n useContext(LicenseContext);\n\n// Provider-level default agent id, published by `<CopilotKitProvider agentId>`.\n//\n// This is a context of its own rather than a `CopilotChatConfigurationProvider`\n// rendered at the root, because that provider also owns a thread: it resolves a\n// threadId (minting a UUID when none is given) and the top-most one owns the\n// imperative active-thread override. Rendering it around the whole application\n// would hand every `<CopilotChat>` the same inherited threadId, so two sibling\n// chats would share one transcript. A bare string context carries the agent\n// default and nothing else.\n//\n// It is the LAST fallback before `DEFAULT_AGENT_ID`, so an explicit `agentId`\n// argument, a `<CopilotChat agentId>`, and a `<CopilotChatConfigurationProvider\n// agentId>` all still win.\nexport const CopilotKitAgentIdContext = createContext<string | undefined>(\n undefined,\n);\n\nexport const useDefaultAgentId = (): string | undefined =>\n useContext(CopilotKitAgentIdContext);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuDA,SAAS,qBAAqB;AAC5B,QAAO,IAAI,SAAe,YAAY,WAAW,SAAS,EAAE,CAAC;;AAG/D,IAAa,sBAAb,cAAyCA,gCAAe;CACtD,AAAiB;CAMjB,YAAY,QAAmC;AAC7C,QAAM;GACJ,GAAG;GACH,0BAA0B;GAC3B,CAAC;AACF,OAAK,aAAa,IAAIC,mCAAkB;GACtC,WAAW,OAAO;GAClB,UAAU,OAAO;GACjB,QAAQ,OAAO;GAChB,CAAC;AACF,OAAK,WAAW,WAAW,SAAS,KAAK,uBAAuB,KAAK,CAAC;AAGtE,OAAK,mCAAmC;AACtC,GAAK,KAAK,mBAAmB,eAAe;AAE1C,WADwB,WACD,4BAA4B;KACjD,YAAY;KACZ,kBAAkB,KAAK;KACxB,CAAC;MACD,8CAA8C;IACjD;;CAGJ,IAAI,uBAAuB;AACzB,SAAO,KAAK,WAAW;;CAGzB,IAAI,yBAAyB;AAC3B,SAAO,KAAK,WAAW;;;;;;CAOzB,IAAI,kBAAkB;AACpB,SAAO,KAAK,WAAW;;CAGzB,0BACE,WACM;AACN,OAAK,WAAW,YA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