@copilotkit/react-native 1.71.1 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,149 +0,0 @@
1
- import React$1, { ReactNode } from "react";
2
- import { RenderToolProps } from "@copilotkit/react-core/v2/headless";
3
- import { DebugConfig, InferSchemaOutput, StandardSchemaV1 } from "@copilotkit/shared";
4
- import { CopilotKitCoreErrorCode, FrontendToolHandlerContext } from "@copilotkit/core";
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$1(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$1<S extends StandardSchemaV1>(config: NamedConfig<S>, deps?: ReadonlyArray<unknown>): void;
147
- //#endregion
148
- export { CopilotKitNativeProviderProps as n, CopilotKitProvider as r, useRenderTool$1 as t };
149
- //# sourceMappingURL=useRenderTool-DsCxzyAP.d.mts.map
@@ -1,298 +0,0 @@
1
- const require_chunk = require('./chunk-C0xms8kb.cjs');
2
- let react = require("react");
3
- react = require_chunk.__toESM(react);
4
- let _copilotkit_react_core_v2_context = require("@copilotkit/react-core/v2/context");
5
- let _copilotkit_react_core_v2_headless = require("@copilotkit/react-core/v2/headless");
6
- let _copilotkit_shared = require("@copilotkit/shared");
7
- let react_jsx_runtime = require("react/jsx-runtime");
8
- let _copilotkit_core = require("@copilotkit/core");
9
-
10
- //#region src/CopilotKitProvider.tsx
11
- /**
12
- * CopilotKit provider for React Native.
13
- *
14
- * A lightweight alternative to the web CopilotKitProvider that avoids
15
- * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
16
- *
17
- * Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
18
- * so a separate `import "@copilotkit/react-native/polyfills"` is no longer
19
- * required (though it remains available for advanced use).
20
- *
21
- * Usage:
22
- * ```tsx
23
- * import { CopilotKitProvider } from "@copilotkit/react-native";
24
- *
25
- * function App() {
26
- * return (
27
- * <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
28
- * <ChatScreen />
29
- * </CopilotKitProvider>
30
- * );
31
- * }
32
- * ```
33
- */
34
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp, credentials, useSingleEndpoint, properties, onError, debug, defaultThrottleMs }) => {
35
- const resolvedHeaders = typeof headersProp === "function" ? headersProp() : headersProp;
36
- const stableHeaders = (0, react.useMemo)(() => resolvedHeaders ?? {}, [JSON.stringify(resolvedHeaders)]);
37
- const stableProperties = (0, react.useMemo)(() => properties ?? {}, [JSON.stringify(properties)]);
38
- const copilotkitRef = (0, react.useRef)(null);
39
- if (copilotkitRef.current === null) {
40
- const instance = new _copilotkit_react_core_v2_headless.CopilotKitCoreReact({
41
- runtimeUrl,
42
- runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
43
- headers: stableHeaders,
44
- credentials,
45
- properties: stableProperties,
46
- debug
47
- });
48
- if (defaultThrottleMs !== void 0) instance.setDefaultThrottleMs(defaultThrottleMs);
49
- copilotkitRef.current = instance;
50
- }
51
- const copilotkit = copilotkitRef.current;
52
- (0, react.useEffect)(() => {
53
- copilotkit.setRuntimeUrl(runtimeUrl);
54
- copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
55
- copilotkit.setHeaders(stableHeaders);
56
- copilotkit.setCredentials(credentials);
57
- copilotkit.setProperties(stableProperties);
58
- copilotkit.setDebug(debug);
59
- }, [
60
- runtimeUrl,
61
- useSingleEndpoint,
62
- stableHeaders,
63
- credentials,
64
- stableProperties,
65
- debug,
66
- copilotkit
67
- ]);
68
- (0, react.useEffect)(() => {
69
- copilotkit.setDefaultThrottleMs(defaultThrottleMs);
70
- }, [copilotkit, defaultThrottleMs]);
71
- const [executingToolCallIds, setExecutingToolCallIds] = (0, react.useState)(() => /* @__PURE__ */ new Set());
72
- const [runtimeLicenseStatus, setRuntimeLicenseStatus] = (0, react.useState)(void 0);
73
- const onErrorRef = (0, react.useRef)(onError);
74
- (0, react.useEffect)(() => {
75
- onErrorRef.current = onError;
76
- }, [onError]);
77
- (0, react.useEffect)(() => {
78
- const subscription = copilotkit.subscribe({
79
- onToolExecutionStart: ({ toolCallId }) => {
80
- setExecutingToolCallIds((prev) => {
81
- if (prev.has(toolCallId)) return prev;
82
- const next = new Set(prev);
83
- next.add(toolCallId);
84
- return next;
85
- });
86
- },
87
- onToolExecutionEnd: ({ toolCallId }) => {
88
- setExecutingToolCallIds((prev) => {
89
- if (!prev.has(toolCallId)) return prev;
90
- const next = new Set(prev);
91
- next.delete(toolCallId);
92
- return next;
93
- });
94
- },
95
- onError: (event) => {
96
- if (onErrorRef.current) onErrorRef.current(event);
97
- else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
98
- },
99
- onRuntimeConnectionStatusChanged: () => {
100
- setRuntimeLicenseStatus(copilotkit.licenseStatus);
101
- }
102
- });
103
- return () => subscription.unsubscribe();
104
- }, [copilotkit]);
105
- const contextValue = (0, react.useMemo)(() => ({
106
- copilotkit,
107
- executingToolCallIds
108
- }), [copilotkit, executingToolCallIds]);
109
- const licenseContextValue = (0, react.useMemo)(() => (0, _copilotkit_shared.createLicenseContextValue)(runtimeLicenseStatus), [runtimeLicenseStatus]);
110
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_react_core_v2_context.CopilotKitContext.Provider, {
111
- value: contextValue,
112
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_react_core_v2_context.LicenseContext.Provider, {
113
- value: licenseContextValue,
114
- children
115
- })
116
- });
117
- };
118
-
119
- //#endregion
120
- //#region src/hooks/useRenderTool.ts
121
- /**
122
- * Dedup key set for the deprecation warning: one warning per distinct tool
123
- * name, not one per render. Module-level (not a ref) so remounting the same
124
- * screen does not re-warn either.
125
- */
126
- const warnedToolNames = /* @__PURE__ */ new Set();
127
- /** Tool-shaped fields that only `useFrontendTool` can honour. */
128
- const LEGACY_TOOL_FIELDS = ["description", "handler"];
129
- /**
130
- * Which core hook a config routes to.
131
- *
132
- * Rule 1 — `name === "*"` WINS, UNCONDITIONALLY. This is deliberately not the
133
- * obvious reading of "old fields mean the old hook". The old RN hook made
134
- * `description` REQUIRED, so anyone who ever attempted a wildcard renderer
135
- * necessarily wrote it WITH the old tool fields. Routing "has old fields" to
136
- * `useFrontendTool` would therefore recreate the original `*`-named-tool bug for
137
- * precisely the people who had tried hardest to use the wildcard. A wildcard
138
- * always means renderer-only.
139
- *
140
- * Rule 2 — otherwise, `handler` or `description` present means the caller wanted
141
- * a tool AND its renderer, which is what the old hook actually did:
142
- * `useFrontendTool`.
143
- *
144
- * Rule 3 — otherwise, `useRenderTool`, i.e. core's hook, unchanged.
145
- *
146
- * One consequence worth knowing about the renderer-only routes (1 and 3): they
147
- * change the EFFECT PHASE the registration lands in. `useFrontendTool`
148
- * registers in a `useLayoutEffect`, core's `useRenderTool` in a `useEffect`, so
149
- * a call that used to register during the layout phase now registers one phase
150
- * later. Only untyped-JS callers can be affected (a typed old call site had to
151
- * supply the required `description`, which routes to `useFrontendTool` and
152
- * keeps the layout phase), and the later phase is what core's `useRenderTool`
153
- * has always done on the web, so this is documented rather than compensated
154
- * for.
155
- */
156
- function routeFor(config) {
157
- if (config.name === "*") return "useRenderTool";
158
- if (config.description !== void 0 || config.handler !== void 0) return "useFrontendTool";
159
- return "useRenderTool";
160
- }
161
- /** Legacy field names actually supplied on this config, in declaration order. */
162
- function legacyFieldsOn(config) {
163
- const supplied = LEGACY_TOOL_FIELDS.filter((field) => config[field] !== void 0);
164
- if (config.name === "*" && config.parameters !== void 0) supplied.push("parameters");
165
- return supplied;
166
- }
167
- /** `description`, `handler` -> "`description`, `handler`" */
168
- const quoteList = (names) => names.map((name) => `\`${name}\``).join(", ");
169
- const SHIM_NOTICE = "React Native's `useRenderTool` is a temporary compatibility shim (deprecated, scheduled for removal in the next minor).";
170
- function warnOnce(name, message) {
171
- if (process.env.NODE_ENV === "production") return;
172
- if (warnedToolNames.has(name)) return;
173
- warnedToolNames.add(name);
174
- console.warn(message);
175
- }
176
- /**
177
- * Says what was received, which hook the call was routed to, and what to change
178
- * the call to. Dev-only and once per distinct tool name.
179
- *
180
- * EVERY route warns — including the renderer-only route that supplied no legacy
181
- * fields at all. That route looks like a no-op and is not. `description` was
182
- * REQUIRED on the old hook, so a TypeScript caller could never reach
183
- * `{ name, parameters, render }` — but an untyped JS caller could, and untyped
184
- * JS is the whole population this shim exists for. `FrontendTool.handler` is
185
- * optional (`core/src/types.ts`) and `buildFrontendTools` does not filter on
186
- * it, so on the old hook that same call DID register AND advertise a real tool.
187
- * Routing cannot recover the intent, because `{ name, parameters, render }` is
188
- * equally the correct NEW renderer-only spelling — so the warning has to carry
189
- * it, or this one shape stays silent while losing registration.
190
- */
191
- function warnRouted(name, route, legacyFields) {
192
- if (legacyFields.length === 0) {
193
- if (route !== "useRenderTool") return;
194
- const registersRendererOnly = `[CopilotKit] \`useRenderTool({ name: "${name}" })\` from @copilotkit/react-native registers a RENDERER ONLY: it supplies UI for a tool call and registers no tool of its own. `;
195
- warnOnce(name, name === "*" ? registersRendererOnly + `That is the right behaviour for a wildcard, and it is NOT what the old React Native \`useRenderTool\` did: that registered a tool literally named "*", which is core's catch-all HANDLER name, so it auto-answered every otherwise-unanswered tool call with an empty tool result and asked for a follow-up turn. ${SHIM_NOTICE} Switch to \`useRenderTool\` from \`@copilotkit/react-core\`.` : registersRendererOnly + `On the old React Native hook this SAME call also registered and advertised a tool named "${name}" to the model, so if you relied on that, this call has quietly stopped doing it — use \`useFrontendTool\` instead. If you only ever wanted to supply UI for a tool somebody else owns, this call is already correct: switch it to \`useRenderTool\` from \`@copilotkit/react-core\`. ${SHIM_NOTICE}`);
196
- return;
197
- }
198
- const received = `[CopilotKit] \`useRenderTool({ name: "${name}" })\` from @copilotkit/react-native received ${quoteList(legacyFields)}. `;
199
- if (route === "useFrontendTool") {
200
- warnOnce(name, received + `Those are TOOL fields, so this call was routed to \`useFrontendTool\` — the hook that registers a tool AND its renderer, which is what the old React Native \`useRenderTool\` did. ${SHIM_NOTICE} Rename the call to \`useFrontendTool\` (same config object; render props rename \`args\` to \`parameters\`). If you only meant to supply UI for a tool somebody else owns, drop ${quoteList(legacyFields)} and keep \`useRenderTool\`.`);
201
- return;
202
- }
203
- warnOnce(name, received + "This call registers a RENDERER ONLY through react-core's `useRenderTool`, which cannot use them, so they were IGNORED. " + (name === "*" ? "No tool named \"*\" is registered — the old React Native `useRenderTool` did register one, and that was the bug: \"*\" is core's catch-all HANDLER name, so it auto-answered every otherwise-unanswered tool call with an empty tool result and asked for a follow-up turn. " : "The route was fixed at this component's first render and cannot change for its lifetime. ") + `${SHIM_NOTICE} Remove ${quoteList(legacyFields)} from this call. If you meant to register a real frontend tool, give it a real name and use \`useFrontendTool\`.`);
204
- }
205
- /**
206
- * @deprecated Temporary compatibility shim over react-core's `useRenderTool` /
207
- * `useFrontendTool`; scheduled for removal in the next minor. See the routing
208
- * rules on {@link routeFor}.
209
- */
210
- function useRenderTool(config, deps) {
211
- const route = routeFor(config);
212
- const frozenRouteRef = (0, react.useRef)(null);
213
- frozenRouteRef.current ??= route;
214
- const frozenRoute = frozenRouteRef.current;
215
- const legacyFields = legacyFieldsOn(config);
216
- (0, react.useEffect)(() => {
217
- warnRouted(config.name, frozenRoute, legacyFields);
218
- }, [
219
- config.name,
220
- frozenRoute,
221
- legacyFields.join(",")
222
- ]);
223
- (0, react.useEffect)(() => {
224
- if (route === frozenRoute) return;
225
- warnOnce(`${config.name}:route-drift`, `[CopilotKit] \`useRenderTool({ name: "${config.name}" })\` from @copilotkit/react-native changed shape between renders: it now routes to \`${route}\` but was registered through \`${frozenRoute}\` and stays there for this component's lifetime (a hook cannot be swapped mid-life). Call \`${route}\` directly instead of varying \`description\`/\`handler\`.`);
226
- }, [
227
- config.name,
228
- route,
229
- frozenRoute
230
- ]);
231
- if (frozenRoute === "useFrontendTool") {
232
- (0, _copilotkit_react_core_v2_headless.useFrontendTool)(toFrontendTool(config), deps);
233
- return;
234
- }
235
- if (config.name === "*") {
236
- (0, _copilotkit_react_core_v2_headless.useRenderTool)({
237
- name: "*",
238
- render: config.render,
239
- ...config.agentId ? { agentId: config.agentId } : {}
240
- }, deps);
241
- return;
242
- }
243
- (0, _copilotkit_react_core_v2_headless.useRenderTool)({
244
- name: config.name,
245
- parameters: config.parameters,
246
- render: config.render,
247
- ...config.agentId ? { agentId: config.agentId } : {}
248
- }, deps);
249
- }
250
- /**
251
- * Builds the `ReactFrontendTool` for the `useFrontendTool` route.
252
- *
253
- * The renderer bridge mirrors react-core's own (`use-render-tool.tsx`): core's
254
- * registry invokes a renderer with `args` and an enum `status`, while this
255
- * hook's `render` is declared with core's public `parameters` / string-literal
256
- * `status` shape. Spreading per status keeps the discriminated union correlated
257
- * — and spreading `...props` (rather than picking fields) is also what keeps an
258
- * old `render: ({ args }) => …` painting unchanged at runtime.
259
- */
260
- function toFrontendTool(config) {
261
- const render = (props) => {
262
- if (props.status === _copilotkit_core.ToolCallStatus.InProgress) return config.render({
263
- ...props,
264
- parameters: props.args
265
- });
266
- if (props.status === _copilotkit_core.ToolCallStatus.Executing) return config.render({
267
- ...props,
268
- parameters: props.args
269
- });
270
- return config.render({
271
- ...props,
272
- parameters: props.args
273
- });
274
- };
275
- return {
276
- name: config.name,
277
- ...config.description !== void 0 ? { description: config.description } : {},
278
- ...config.parameters !== void 0 ? { parameters: config.parameters } : {},
279
- ...config.handler !== void 0 ? { handler: config.handler } : {},
280
- ...config.agentId ? { agentId: config.agentId } : {},
281
- render
282
- };
283
- }
284
-
285
- //#endregion
286
- Object.defineProperty(exports, 'CopilotKitProvider', {
287
- enumerable: true,
288
- get: function () {
289
- return CopilotKitProvider;
290
- }
291
- });
292
- Object.defineProperty(exports, 'useRenderTool', {
293
- enumerable: true,
294
- get: function () {
295
- return useRenderTool;
296
- }
297
- });
298
- //# sourceMappingURL=useRenderTool-L3Rw6SYD.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useRenderTool-L3Rw6SYD.cjs","names":["CopilotKitCoreReact","CopilotKitContext","LicenseContext","ToolCallStatus"],"sources":["../src/CopilotKitProvider.tsx","../src/hooks/useRenderTool.ts"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\nimport {\n CopilotKitContext,\n LicenseContext,\n} from \"@copilotkit/react-core/v2/context\";\nimport type {\n CopilotKitContextValue,\n CopilotKitCoreReact as CopilotKitCoreReactInstance,\n} from \"@copilotkit/react-core/v2/context\";\nimport { CopilotKitCoreReact } from \"@copilotkit/react-core/v2/headless\";\nimport type { CopilotKitCoreErrorCode } from \"@copilotkit/core\";\nimport type { DebugConfig, RuntimeLicenseStatus } from \"@copilotkit/shared\";\nimport { createLicenseContextValue } from \"@copilotkit/shared\";\n\nexport interface CopilotKitNativeProviderProps {\n children: ReactNode;\n /** URL of the CopilotKit runtime endpoint */\n runtimeUrl: string;\n /** Custom headers sent with every request */\n headers?: Record<string, string> | (() => Record<string, string>);\n /**\n * Credentials mode for fetch requests (e.g., \"include\" for HTTP-only cookies in cross-origin requests).\n */\n credentials?: RequestCredentials;\n /** Whether the runtime uses a single-route endpoint */\n useSingleEndpoint?: boolean;\n /** Custom properties forwarded to agents */\n properties?: Record<string, unknown>;\n /**\n * Error handler called when CopilotKit encounters an error.\n * Fires for all error types (runtime connection failures, agent errors, tool errors).\n * If not provided, errors are logged to console.error.\n */\n onError?: (event: {\n error: Error;\n code: CopilotKitCoreErrorCode;\n context: Record<string, any>;\n }) => void | Promise<void>;\n /**\n * Enable debug logging for the client-side event pipeline.\n * When `true`, enables verbose logging from the core instance.\n */\n debug?: DebugConfig;\n /**\n * Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`\n * subscriptions. Individual subscriptions can override with their own `throttleMs`.\n */\n defaultThrottleMs?: number;\n // Cloud features (publicApiKey, licenseToken) — not yet supported on React Native\n}\n\n/**\n * CopilotKit provider for React Native.\n *\n * A lightweight alternative to the web CopilotKitProvider that avoids\n * web-only dependencies (DOM, CSS, Radix UI, Lit, etc).\n *\n * Polyfills are auto-imported when `@copilotkit/react-native` is loaded,\n * so a separate `import \"@copilotkit/react-native/polyfills\"` is no longer\n * required (though it remains available for advanced use).\n *\n * Usage:\n * ```tsx\n * import { CopilotKitProvider } from \"@copilotkit/react-native\";\n *\n * function App() {\n * return (\n * <CopilotKitProvider runtimeUrl=\"https://your-runtime/api/copilotkit\">\n * <ChatScreen />\n * </CopilotKitProvider>\n * );\n * }\n * ```\n */\nexport const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps> = ({\n children,\n runtimeUrl,\n headers: headersProp,\n credentials,\n useSingleEndpoint,\n properties,\n onError,\n debug,\n defaultThrottleMs,\n}) => {\n // Resolve headers from function or static object (matches web provider pattern)\n const resolvedHeaders =\n typeof headersProp === \"function\" ? headersProp() : headersProp;\n\n // Stabilize headers/properties references to avoid effect churn when callers\n // pass inline object literals (e.g. headers={{}} or the undefined default).\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableHeaders = useMemo(\n () => resolvedHeaders ?? {},\n [JSON.stringify(resolvedHeaders)],\n );\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const stableProperties = useMemo(\n () => properties ?? {},\n [JSON.stringify(properties)],\n );\n\n const copilotkitRef = useRef<CopilotKitCoreReactInstance | null>(null);\n\n if (copilotkitRef.current === null) {\n const instance: CopilotKitCoreReactInstance = new CopilotKitCoreReact({\n runtimeUrl,\n runtimeTransport:\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n headers: stableHeaders,\n credentials,\n properties: stableProperties,\n debug,\n });\n // Set initial defaultThrottleMs synchronously so child hooks see the\n // correct value on their first render (before useEffect fires).\n if (defaultThrottleMs !== undefined) {\n instance.setDefaultThrottleMs(defaultThrottleMs);\n }\n copilotkitRef.current = instance;\n }\n\n const copilotkit = copilotkitRef.current;\n\n // Sync props to core instance\n useEffect(() => {\n copilotkit.setRuntimeUrl(runtimeUrl);\n copilotkit.setRuntimeTransport(\n useSingleEndpoint === true\n ? \"single\"\n : useSingleEndpoint === false\n ? \"rest\"\n : \"auto\",\n );\n copilotkit.setHeaders(stableHeaders);\n copilotkit.setCredentials(credentials);\n copilotkit.setProperties(stableProperties);\n copilotkit.setDebug(debug);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n credentials,\n stableProperties,\n debug,\n copilotkit,\n ]);\n\n // Sync defaultThrottleMs to the core instance on prop changes.\n // Initial value is set synchronously during instance creation (inside the\n // ref guard above), so this only handles subsequent updates.\n useEffect(() => {\n copilotkit.setDefaultThrottleMs(defaultThrottleMs);\n }, [copilotkit, defaultThrottleMs]);\n\n // Track executing tool call IDs at the provider level.\n // Critical for HITL reconnection: onToolExecutionStart fires before child\n // components mount, so we must capture the state here.\n const [executingToolCallIds, setExecutingToolCallIds] = useState<\n ReadonlySet<string>\n >(() => new Set());\n\n const [runtimeLicenseStatus, setRuntimeLicenseStatus] = useState<\n RuntimeLicenseStatus | undefined\n >(undefined);\n\n // Use ref to avoid subscription churn when onError changes\n const onErrorRef = useRef(onError);\n useEffect(() => {\n onErrorRef.current = onError;\n }, [onError]);\n\n // Single subscription for tool execution tracking and error handling.\n // Tool call IDs are tracked at the provider level because onToolExecutionStart\n // fires before child components mount — critical for HITL reconnection.\n useEffect(() => {\n const subscription = copilotkit.subscribe({\n onToolExecutionStart: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.add(toolCallId);\n return next;\n });\n },\n onToolExecutionEnd: ({ toolCallId }) => {\n setExecutingToolCallIds((prev) => {\n if (!prev.has(toolCallId)) return prev;\n const next = new Set(prev);\n next.delete(toolCallId);\n return next;\n });\n },\n onError: (event) => {\n if (onErrorRef.current) {\n onErrorRef.current(event);\n } else {\n console.error(\n `[CopilotKit] Error (${event.code}):`,\n event.error,\n event.context ?? {},\n );\n }\n },\n onRuntimeConnectionStatusChanged: () => {\n setRuntimeLicenseStatus(copilotkit.licenseStatus);\n },\n });\n return () => subscription.unsubscribe();\n }, [copilotkit]);\n\n const contextValue: CopilotKitContextValue = useMemo(\n () => ({\n copilotkit,\n executingToolCallIds,\n }),\n [copilotkit, executingToolCallIds],\n );\n\n // License context — driven by server-reported status via /info endpoint\n const licenseContextValue = useMemo(\n () => createLicenseContextValue(runtimeLicenseStatus),\n [runtimeLicenseStatus],\n );\n\n return (\n <CopilotKitContext.Provider value={contextValue}>\n <LicenseContext.Provider value={licenseContextValue}>\n {children}\n </LicenseContext.Provider>\n </CopilotKitContext.Provider>\n );\n};\n","import { useEffect, useRef } from \"react\";\nimport {\n useFrontendTool,\n useRenderTool as useCoreRenderTool,\n} from \"@copilotkit/react-core/v2/headless\";\nimport type {\n ReactFrontendTool,\n RenderToolProps,\n} from \"@copilotkit/react-core/v2/headless\";\nimport { ToolCallStatus } from \"@copilotkit/core\";\nimport type { FrontendToolHandlerContext } from \"@copilotkit/core\";\nimport type { InferSchemaOutput, StandardSchemaV1 } from \"@copilotkit/shared\";\n\n/**\n * TEMPORARY COMPATIBILITY SHIM — scheduled for removal in the next minor.\n * Removal is tracked in CopilotKit/CopilotKit#6976 (Linear OSS-1148).\n *\n * ─── Why this exists at all ──────────────────────────────────────────────────\n *\n * `@copilotkit/react-native` used to export a hook named `useRenderTool` that\n * was NOT react-core's `useRenderTool`: its whole body forwarded to core's\n * OTHER hook, `useFrontendTool`, while wearing this one's name. The two are not\n * interchangeable — `useFrontendTool` registers a TOOL (advertised to the model,\n * callable by it) *and* its renderer through `addTool`, while `useRenderTool`\n * registers a RENDERER ONLY through `addHookRenderToolCall` and special-cases\n * `name: \"*\"` into a schema-less fallback. Under the alias, `name: \"*\"`\n * registered a frontend tool literally named `*`.\n *\n * ─── What a tool named `*` actually does ─────────────────────────────────────\n *\n * NOT \"gets advertised to the model\": core has never offered it. `*` is core's\n * catch-all HANDLER name, and `buildFrontendTools` filters it out of the list\n * it hands the agent (`core/src/core/run-handler.ts`, at the\n * `tool.name !== WILDCARD_TOOL_NAME` clause) precisely so the model is not\n * offered a tool whose name is a glob.\n *\n * What it does instead is worse for the affected caller. When a tool call has\n * no matching frontend tool and no result yet, core reaches for\n * `getWildcardTool()` and runs `executeWildcardTool`. Inside it, the parse /\n * handler / subscriber work is guarded by `if (wildcardTool?.handler)` — but\n * the tool-result splice and the follow-up return sit OUTSIDE that guard, and\n * `toolCallResult` is initialised to `\"\"`. So a handler-less wildcard tool —\n * exactly what a caller who wanted a display-only fallback wrote — still\n * splices an EMPTY tool result for the call and still asks for another turn.\n *\n * Driving one turn through it (an assistant message calling a tool nobody\n * registered) shows the difference directly: through the old hook, two turns\n * and a spliced `{ toolCallId, content: \"\" }`; through core's `useRenderTool`,\n * one turn and no tool result. So an RN app whose author wanted a display-only\n * fallback was also auto-answering every otherwise-unanswered tool call with an\n * empty result and paying for a follow-up turn.\n *\n * The scope of that is bounded: it only bites a tool call with no exact-name\n * frontend tool AND no result yet, so a server-side tool call whose result has\n * already arrived never reaches the branch.\n *\n * The convergence deleted RN's hook and re-exported core's two instead. That is\n * a break, and this package ships in the `monorepo` release scope — 16 packages\n * versioned in lockstep — so it lands in a MINOR, not a major. The compiler is\n * therefore the only signal that reaches most consumers, and there are call\n * shapes the compiler cannot see:\n *\n * • a HOISTED config object whose `render` ignores its props (TypeScript's\n * excess-property check only fires on a fresh object literal);\n * • the old fields arriving via a SPREAD into an otherwise fresh literal;\n * • an UNTYPED or `@ts-nocheck` call site — plain-JS React Native screens are\n * common.\n *\n * In all three, core's `useRenderTool` would silently ignore `description` and\n * `handler`; and because core's renderer bridge spreads\n * `{ ...props, parameters: props.args }`, an old `render: ({ args }) => …` keeps\n * painting EXACTLY as before. The screen looks unchanged while the tool stops\n * being registered and advertised and the handler never runs again. That is the\n * failure this shim exists to prevent: it routes such calls the way the old hook\n * did, and says so out loud.\n *\n * ─── Warning idiom ───────────────────────────────────────────────────────────\n *\n * `[CopilotKit] `-prefixed `console.warn`, deduped through a module-level `Set`\n * so a render path cannot spam it — the same shape as\n * react-core's `warnedUnknownStatuses` in `use-default-render-tool.tsx`.\n *\n * The dev gate is `process.env.NODE_ENV !== \"production\"`, which is what\n * react-core's own hooks/components use and what a test can flip. Other RN\n * modules in this package gate on React Native's `__DEV__` global instead; both\n * are compile-time-inlined by Metro, so either is stripped from a release\n * bundle. `NODE_ENV` is chosen here because this module sits between two\n * react-core hooks and is asserted against directly in the suite.\n */\n\n/**\n * The two hooks a call can be routed to. Named for the core hook that ends up\n * owning the registration, because that is the thing a consumer must change\n * their call to.\n */\ntype Route = \"useFrontendTool\" | \"useRenderTool\";\n\n/**\n * Dedup key set for the deprecation warning: one warning per distinct tool\n * name, not one per render. Module-level (not a ref) so remounting the same\n * screen does not re-warn either.\n */\nconst warnedToolNames = new Set<string>();\n\n/** Tool-shaped fields that only `useFrontendTool` can honour. */\nconst LEGACY_TOOL_FIELDS = [\"description\", \"handler\"] as const;\n\n/**\n * Fields the OLD React Native hook accepted, kept optional here so the call\n * shapes the compiler cannot see (hoisted / spread / untyped) still type-check\n * and get routed rather than silently dropped.\n *\n * @typeParam A - The parsed argument type a legacy `handler` receives.\n */\ninterface LegacyToolFields<A> {\n /**\n * @deprecated A description is a TOOL field: it is what gets advertised to\n * the model. Supplying it routes this call to `useFrontendTool` — rename the\n * call to `useFrontendTool` instead.\n */\n description?: string;\n /**\n * @deprecated A handler is a TOOL field: it is what the model's call\n * executes. Supplying it routes this call to `useFrontendTool` — rename the\n * call to `useFrontendTool` instead. Note that core's handler receives a\n * SECOND argument (the {@link FrontendToolHandlerContext}, carrying\n * `stopAgent()`'s abort signal), which the old React Native hook dropped.\n */\n handler?: (args: A, context: FrontendToolHandlerContext) => Promise<unknown>;\n}\n\n/** The wildcard call shape: a fallback renderer for every unclaimed tool call. */\ntype WildcardConfig = {\n name: \"*\";\n render: (props: any) => React.ReactElement | null;\n agentId?: string;\n} & LegacyToolFields<Record<string, unknown>> & {\n /**\n * @deprecated A wildcard renderer paints tool calls it does not own, so it\n * has no schema of its own — core's wildcard path ignores this. Remove it.\n */\n parameters?: StandardSchemaV1;\n };\n\n/** The name-scoped call shape. */\ntype NamedConfig<S extends StandardSchemaV1> = {\n name: string;\n parameters: S;\n render: (props: RenderToolProps<S>) => React.ReactElement | null;\n agentId?: string;\n} & LegacyToolFields<InferSchemaOutput<S>>;\n\n/**\n * The IMPLEMENTATION-side shape: the union of both public overloads with\n * everything optional and the schema-dependent positions left as `any`.\n *\n * Deliberately permissive, and invisible to consumers — the two overloads above\n * are the public API. This is the same shape react-core gives its own\n * implementation signatures (`useRenderTool`, `defineToolCallRenderer`), and it\n * is what lets this body forward a config to either core hook without a single\n * cast: the alternative — a generic implementation signature — cannot be\n * satisfied by both a `name: \"*\"` config with no schema and a named config with\n * one.\n */\ntype ShimConfig = {\n name: string;\n // `<any, any>` rather than the bare default (`<unknown, unknown>`): a\n // schema's OUTPUT type sits in an invariant position on the Standard Schema\n // interface, so the bare default is not assignable to the\n // `StandardSchemaV1<any, Record<string, unknown>>` that core's\n // `ReactFrontendTool` declares. Bridging that variance here — in the\n // implementation-only shape — is what keeps the body cast-free.\n parameters?: StandardSchemaV1<any, any>;\n render: (props: any) => React.ReactElement | null;\n agentId?: string;\n} & LegacyToolFields<any>;\n\n/**\n * Which core hook a config routes to.\n *\n * Rule 1 — `name === \"*\"` WINS, UNCONDITIONALLY. This is deliberately not the\n * obvious reading of \"old fields mean the old hook\". The old RN hook made\n * `description` REQUIRED, so anyone who ever attempted a wildcard renderer\n * necessarily wrote it WITH the old tool fields. Routing \"has old fields\" to\n * `useFrontendTool` would therefore recreate the original `*`-named-tool bug for\n * precisely the people who had tried hardest to use the wildcard. A wildcard\n * always means renderer-only.\n *\n * Rule 2 — otherwise, `handler` or `description` present means the caller wanted\n * a tool AND its renderer, which is what the old hook actually did:\n * `useFrontendTool`.\n *\n * Rule 3 — otherwise, `useRenderTool`, i.e. core's hook, unchanged.\n *\n * One consequence worth knowing about the renderer-only routes (1 and 3): they\n * change the EFFECT PHASE the registration lands in. `useFrontendTool`\n * registers in a `useLayoutEffect`, core's `useRenderTool` in a `useEffect`, so\n * a call that used to register during the layout phase now registers one phase\n * later. Only untyped-JS callers can be affected (a typed old call site had to\n * supply the required `description`, which routes to `useFrontendTool` and\n * keeps the layout phase), and the later phase is what core's `useRenderTool`\n * has always done on the web, so this is documented rather than compensated\n * for.\n */\nfunction routeFor(config: {\n name: string;\n description?: unknown;\n handler?: unknown;\n}): Route {\n if (config.name === \"*\") return \"useRenderTool\";\n if (config.description !== undefined || config.handler !== undefined) {\n return \"useFrontendTool\";\n }\n return \"useRenderTool\";\n}\n\n/** Legacy field names actually supplied on this config, in declaration order. */\nfunction legacyFieldsOn(config: ShimConfig): string[] {\n const supplied: string[] = LEGACY_TOOL_FIELDS.filter(\n (field) => config[field] !== undefined,\n );\n // `parameters` is only a legacy field on the wildcard path, where core has no\n // use for it. On the named path it is core's own field and must not be named.\n if (config.name === \"*\" && config.parameters !== undefined) {\n supplied.push(\"parameters\");\n }\n return supplied;\n}\n\n/** `description`, `handler` -> \"`description`, `handler`\" */\nconst quoteList = (names: readonly string[]) =>\n names.map((name) => `\\`${name}\\``).join(\", \");\n\nconst SHIM_NOTICE =\n \"React Native's `useRenderTool` is a temporary compatibility shim \" +\n \"(deprecated, scheduled for removal in the next minor).\";\n\n/**\n * TEST-ONLY escape hatch for the per-name dedup above.\n *\n * Not re-exported from any package entry (`src/headless.ts` exports only the\n * hook), so it is not public API. It exists because the dedup key is the tool\n * NAME and lives for the lifetime of the module: the wildcard's name is the\n * same `\"*\"` for every caller, so without this the second test to assert the\n * wildcard's warning would silently observe zero calls and have to be written\n * order-dependently instead.\n */\nexport function __resetRenderToolShimWarnings(): void {\n warnedToolNames.clear();\n}\n\nfunction warnOnce(name: string, message: string): void {\n if (process.env.NODE_ENV === \"production\") return;\n if (warnedToolNames.has(name)) return;\n warnedToolNames.add(name);\n console.warn(message);\n}\n\n/**\n * Says what was received, which hook the call was routed to, and what to change\n * the call to. Dev-only and once per distinct tool name.\n *\n * EVERY route warns — including the renderer-only route that supplied no legacy\n * fields at all. That route looks like a no-op and is not. `description` was\n * REQUIRED on the old hook, so a TypeScript caller could never reach\n * `{ name, parameters, render }` — but an untyped JS caller could, and untyped\n * JS is the whole population this shim exists for. `FrontendTool.handler` is\n * optional (`core/src/types.ts`) and `buildFrontendTools` does not filter on\n * it, so on the old hook that same call DID register AND advertise a real tool.\n * Routing cannot recover the intent, because `{ name, parameters, render }` is\n * equally the correct NEW renderer-only spelling — so the warning has to carry\n * it, or this one shape stays silent while losing registration.\n */\nfunction warnRouted(\n name: string,\n route: Route,\n legacyFields: readonly string[],\n): void {\n if (legacyFields.length === 0) {\n // Guarded on the ROUTE, not just on the absence of legacy fields: a config\n // that HAD them on its first render and then dropped them keeps its frozen\n // `useFrontendTool` route, and calling that \"renderer only\" would be false.\n // That case already warned on the first render (and gets the drift warning\n // besides), so there is nothing to add here.\n if (route !== \"useRenderTool\") return;\n\n const registersRendererOnly =\n `[CopilotKit] \\`useRenderTool({ name: \"${name}\" })\\` from ` +\n `@copilotkit/react-native registers a RENDERER ONLY: it supplies UI for a ` +\n `tool call and registers no tool of its own. `;\n\n warnOnce(\n name,\n name === \"*\"\n ? registersRendererOnly +\n `That is the right behaviour for a wildcard, and it is NOT what the ` +\n `old React Native \\`useRenderTool\\` did: that registered a tool ` +\n `literally named \"*\", which is core's catch-all HANDLER name, so it ` +\n `auto-answered every otherwise-unanswered tool call with an empty ` +\n `tool result and asked for a follow-up turn. ${SHIM_NOTICE} Switch ` +\n `to \\`useRenderTool\\` from \\`@copilotkit/react-core\\`.`\n : registersRendererOnly +\n `On the old React Native hook this SAME call also registered and ` +\n `advertised a tool named \"${name}\" to the model, so if you relied on ` +\n `that, this call has quietly stopped doing it — use ` +\n `\\`useFrontendTool\\` instead. If you only ever wanted to supply UI ` +\n `for a tool somebody else owns, this call is already correct: switch ` +\n `it to \\`useRenderTool\\` from \\`@copilotkit/react-core\\`. ` +\n `${SHIM_NOTICE}`,\n );\n return;\n }\n\n const received =\n `[CopilotKit] \\`useRenderTool({ name: \"${name}\" })\\` from ` +\n `@copilotkit/react-native received ${quoteList(legacyFields)}. `;\n\n if (route === \"useFrontendTool\") {\n warnOnce(\n name,\n received +\n `Those are TOOL fields, so this call was routed to \\`useFrontendTool\\` — ` +\n `the hook that registers a tool AND its renderer, which is what the old ` +\n `React Native \\`useRenderTool\\` did. ${SHIM_NOTICE} Rename the call to ` +\n `\\`useFrontendTool\\` (same config object; render props rename \\`args\\` to ` +\n `\\`parameters\\`). If you only meant to supply UI for a tool somebody else ` +\n `owns, drop ${quoteList(legacyFields)} and keep \\`useRenderTool\\`.`,\n );\n return;\n }\n\n // Reached with legacy fields present but the renderer-only route in force.\n // Normally that is the wildcard (rule 1); it is also what a frozen route\n // looks like if a config grew legacy fields after its first render.\n warnOnce(\n name,\n received +\n `This call registers a RENDERER ONLY through react-core's ` +\n `\\`useRenderTool\\`, which cannot use them, so they were IGNORED. ` +\n (name === \"*\"\n ? `No tool named \"*\" is registered — the old React Native ` +\n `\\`useRenderTool\\` did register one, and that was the bug: \"*\" is ` +\n `core's catch-all HANDLER name, so it auto-answered every ` +\n `otherwise-unanswered tool call with an empty tool result and asked ` +\n `for a follow-up turn. `\n : `The route was fixed at this component's first render and cannot ` +\n `change for its lifetime. `) +\n `${SHIM_NOTICE} Remove ${quoteList(legacyFields)} from this call. ` +\n `If you meant to register a real frontend tool, give it a real name and ` +\n `use \\`useFrontendTool\\`.`,\n );\n}\n\n/**\n * Registers a wildcard (`\"*\"`) renderer for tool calls.\n *\n * @deprecated Use `useRenderTool` from `@copilotkit/react-core` (re-exported by\n * `@copilotkit/react-native/headless` once this shim is gone) for a\n * renderer-only registration, or `useFrontendTool` to register a tool and its\n * renderer together. This shim is scheduled for removal in the next minor.\n *\n * @param config - Wildcard renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n */\nexport function useRenderTool(\n config: WildcardConfig,\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * Registers a name-scoped renderer for tool calls — or, if `description` or\n * `handler` is supplied, a frontend tool and its renderer (what the old React\n * Native hook did), with a development warning.\n *\n * @deprecated Use `useRenderTool` from `@copilotkit/react-core` (re-exported by\n * `@copilotkit/react-native/headless` once this shim is gone) for a\n * renderer-only registration, or `useFrontendTool` to register a tool and its\n * renderer together. This shim is scheduled for removal in the next minor.\n *\n * @typeParam S - Schema type describing tool call parameters.\n * @param config - Named renderer configuration.\n * @param deps - Optional dependencies to refresh registration.\n */\nexport function useRenderTool<S extends StandardSchemaV1>(\n config: NamedConfig<S>,\n deps?: ReadonlyArray<unknown>,\n): void;\n\n/**\n * @deprecated Temporary compatibility shim over react-core's `useRenderTool` /\n * `useFrontendTool`; scheduled for removal in the next minor. See the routing\n * rules on {@link routeFor}.\n */\nexport function useRenderTool(\n config: ShimConfig,\n deps?: ReadonlyArray<unknown>,\n): void {\n const route = routeFor(config);\n\n // The route is FROZEN at first render. A hook cannot be called conditionally\n // unless the condition is stable for the component's lifetime, and a config\n // whose shape changes between renders (`handler: enabled ? fn : undefined`)\n // would otherwise flip which core hook is called. Freezing keeps the call\n // order constant; the drift is reported below rather than acted on, because\n // silently re-routing a live registration is the failure mode this whole shim\n // exists to prevent.\n const frozenRouteRef = useRef<Route | null>(null);\n frozenRouteRef.current ??= route;\n const frozenRoute = frozenRouteRef.current;\n\n const legacyFields = legacyFieldsOn(config);\n\n useEffect(() => {\n warnRouted(config.name, frozenRoute, legacyFields);\n // The warning is keyed on the tool name, so re-running it for a changed\n // render closure would be pure noise; `warnOnce` dedups anyway.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [config.name, frozenRoute, legacyFields.join(\",\")]);\n\n useEffect(() => {\n if (route === frozenRoute) return;\n warnOnce(\n `${config.name}:route-drift`,\n `[CopilotKit] \\`useRenderTool({ name: \"${config.name}\" })\\` from ` +\n `@copilotkit/react-native changed shape between renders: it now routes ` +\n `to \\`${route}\\` but was registered through \\`${frozenRoute}\\` and stays ` +\n `there for this component's lifetime (a hook cannot be swapped mid-life). ` +\n `Call \\`${route}\\` directly instead of varying \\`description\\`/\\`handler\\`.`,\n );\n }, [config.name, route, frozenRoute]);\n\n if (frozenRoute === \"useFrontendTool\") {\n // Registration is DELEGATED, never reimplemented: this package must own no\n // render-tool registry of its own (RN once did, and `useComponent` — which\n // registers into core's — then rendered nowhere on RN).\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useFrontendTool(toFrontendTool(config), deps);\n return;\n }\n\n if (config.name === \"*\") {\n // Rule 1: core's schema-less wildcard branch, whatever else was supplied.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCoreRenderTool(\n {\n name: \"*\",\n render: config.render,\n ...(config.agentId ? { agentId: config.agentId } : {}),\n },\n deps,\n );\n return;\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useCoreRenderTool(\n {\n name: config.name,\n parameters: config.parameters!,\n render: config.render,\n ...(config.agentId ? { agentId: config.agentId } : {}),\n },\n deps,\n );\n}\n\n/**\n * Builds the `ReactFrontendTool` for the `useFrontendTool` route.\n *\n * The renderer bridge mirrors react-core's own (`use-render-tool.tsx`): core's\n * registry invokes a renderer with `args` and an enum `status`, while this\n * hook's `render` is declared with core's public `parameters` / string-literal\n * `status` shape. Spreading per status keeps the discriminated union correlated\n * — and spreading `...props` (rather than picking fields) is also what keeps an\n * old `render: ({ args }) => …` painting unchanged at runtime.\n */\nfunction toFrontendTool(config: ShimConfig): ReactFrontendTool {\n const render: ReactFrontendTool[\"render\"] = (props) => {\n // Three byte-identical branches, deliberately: see the note above.\n if (props.status === ToolCallStatus.InProgress) {\n return config.render({ ...props, parameters: props.args });\n }\n if (props.status === ToolCallStatus.Executing) {\n return config.render({ ...props, parameters: props.args });\n }\n return config.render({ ...props, parameters: props.args });\n };\n\n return {\n name: config.name,\n ...(config.description !== undefined\n ? { description: config.description }\n : {}),\n ...(config.parameters !== undefined\n ? { parameters: config.parameters }\n : {}),\n ...(config.handler !== undefined ? { handler: config.handler } : {}),\n ...(config.agentId ? { agentId: config.agentId } : {}),\n render,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,sBAA+D,EAC1E,UACA,YACA,SAAS,aACT,aACA,mBACA,YACA,SACA,OACA,wBACI;CAEJ,MAAM,kBACJ,OAAO,gBAAgB,aAAa,aAAa,GAAG;CAKtD,MAAM,yCACE,mBAAmB,EAAE,EAC3B,CAAC,KAAK,UAAU,gBAAgB,CAAC,CAClC;CAED,MAAM,4CACE,cAAc,EAAE,EACtB,CAAC,KAAK,UAAU,WAAW,CAAC,CAC7B;CAED,MAAM,kCAA2D,KAAK;AAEtE,KAAI,cAAc,YAAY,MAAM;EAClC,MAAM,WAAwC,IAAIA,uDAAoB;GACpE;GACA,kBACE,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA;GACR,SAAS;GACT;GACA,YAAY;GACZ;GACD,CAAC;AAGF,MAAI,sBAAsB,OACxB,UAAS,qB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