@copilotkit/react-native 1.83.0 → 2.0.0-rc.1

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.
Files changed (67) hide show
  1. package/USAGE.md +2 -2
  2. package/dist/{CopilotKitProvider-BUVBq9LN.d.mts → CopilotKitProvider-BWjzCdHN.d.mts} +29 -2
  3. package/dist/{CopilotKitProvider-BVPr5t83.d.cts → CopilotKitProvider-Btm10msB.d.cts} +29 -2
  4. package/dist/{CopilotKitProvider-CjoPnabW.cjs → CopilotKitProvider-Byw3cqe2.cjs} +13 -10
  5. package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +1 -0
  6. package/dist/{CopilotKitProvider-D8sn7G_C.mjs → CopilotKitProvider-CE4bc6CP.mjs} +9 -5
  7. package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +1 -0
  8. package/dist/Markdown-1ips7myr.d.cts +52 -0
  9. package/dist/Markdown-C6AsLHmd.mjs +47 -0
  10. package/dist/Markdown-C6AsLHmd.mjs.map +1 -0
  11. package/dist/Markdown-C_9Re36O.cjs +60 -0
  12. package/dist/Markdown-C_9Re36O.cjs.map +1 -0
  13. package/dist/Markdown-JsYh7oSA.d.mts +52 -0
  14. package/dist/MarkdownRendererContext-BRNe808d.cjs +72 -0
  15. package/dist/MarkdownRendererContext-BRNe808d.cjs.map +1 -0
  16. package/dist/MarkdownRendererContext-CAnuohIS.mjs +21 -0
  17. package/dist/MarkdownRendererContext-CAnuohIS.mjs.map +1 -0
  18. package/dist/components/index.cjs +20 -106
  19. package/dist/components/index.cjs.map +1 -1
  20. package/dist/components/index.d.cts +1 -46
  21. package/dist/components/index.d.mts +1 -46
  22. package/dist/components/index.mjs +13 -98
  23. package/dist/components/index.mjs.map +1 -1
  24. package/dist/headless.cjs +22 -22
  25. package/dist/headless.d.cts +4 -3
  26. package/dist/headless.d.mts +4 -3
  27. package/dist/headless.mjs +3 -3
  28. package/dist/index.cjs +32 -27
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +3 -2
  31. package/dist/index.d.mts +3 -2
  32. package/dist/index.mjs +6 -4
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/polyfills/encoding.cjs +1 -1
  35. package/dist/polyfills/streams.cjs +1 -1
  36. package/package.json +6 -9
  37. package/scripts/measure-headless.mjs +2 -2
  38. package/src/CopilotChat.tsx +2 -2
  39. package/src/CopilotKitProvider.tsx +17 -4
  40. package/src/__mocks__/test-copilotkit.tsx +3 -3
  41. package/src/__tests__/attachments-integration.test.tsx +2 -2
  42. package/src/__tests__/copilot-chat-agentid.test.tsx +2 -2
  43. package/src/__tests__/copilot-chat-attachments.test.tsx +2 -2
  44. package/src/__tests__/copilot-popup.test.tsx +2 -2
  45. package/src/__tests__/copilot-sidebar.test.tsx +2 -2
  46. package/src/__tests__/copilotkit-provider.test.tsx +2 -2
  47. package/src/__tests__/headless-entry-surface.test.ts +33 -12
  48. package/src/__tests__/headless-integration.test.tsx +4 -2
  49. package/src/__tests__/headless-value-exports.test.ts +2 -2
  50. package/src/components/CopilotChat.tsx +2 -5
  51. package/src/components/Markdown.tsx +62 -100
  52. package/src/components/MarkdownRendererContext.tsx +40 -0
  53. package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +2 -2
  54. package/src/components/__tests__/CopilotChat.test.tsx +2 -2
  55. package/src/components/__tests__/Markdown.code-alias.test.tsx +59 -0
  56. package/src/components/__tests__/Markdown.test.tsx +6 -75
  57. package/src/components/messages/AssistantMessage.tsx +22 -1
  58. package/src/components/messages/__tests__/AssistantMessage.provider-renderer.test.tsx +73 -0
  59. package/src/components/messages/__tests__/markdown-renderer-config.test.tsx +66 -0
  60. package/src/headless.ts +8 -8
  61. package/src/index.ts +19 -2
  62. package/tsdown.config.ts +0 -1
  63. package/vitest.config.mjs +0 -7
  64. package/dist/CopilotKitProvider-CjoPnabW.cjs.map +0 -1
  65. package/dist/CopilotKitProvider-D8sn7G_C.mjs.map +0 -1
  66. package/dist/chunk-C0xms8kb.cjs +0 -34
  67. package/src/__mocks__/react-native-streamdown.ts +0 -16
@@ -0,0 +1,73 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, it, expect, vi } from "vitest";
4
+
5
+ vi.mock("react-native", () => {
6
+ const R = require("react");
7
+ const View = R.forwardRef(
8
+ ({ children, style, testID, ...rest }: any, ref: any) =>
9
+ R.createElement(
10
+ "div",
11
+ { ref, style, "data-testid": testID, ...rest },
12
+ children,
13
+ ),
14
+ );
15
+ View.displayName = "View";
16
+ const Text = R.forwardRef(({ children, style, ...rest }: any, ref: any) =>
17
+ R.createElement("span", { ref, style, ...rest }, children),
18
+ );
19
+ Text.displayName = "Text";
20
+ return {
21
+ View,
22
+ Text,
23
+ StyleSheet: { create: (s: any) => s, flatten: (s: any) => s },
24
+ };
25
+ });
26
+
27
+ // The typing indicator pulls in the RN Animated API which the minimal mock
28
+ // above does not provide; it is irrelevant to renderer resolution.
29
+ vi.mock("../TypingIndicator", () => ({ TypingIndicator: () => null }));
30
+
31
+ import { AssistantMessage } from "../AssistantMessage";
32
+ import { MarkdownRendererProvider } from "../../MarkdownRendererContext";
33
+
34
+ describe("AssistantMessage provider markdown renderer (slot -> provider -> built-in)", () => {
35
+ it("uses a provider-level renderer when CopilotKitProvider sets one", () => {
36
+ const Custom = ({
37
+ content,
38
+ isStreaming,
39
+ }: {
40
+ content: string;
41
+ isStreaming?: boolean;
42
+ }) =>
43
+ React.createElement(
44
+ "span",
45
+ {
46
+ "data-testid": "custom-renderer",
47
+ "data-streaming": String(!!isStreaming),
48
+ },
49
+ content,
50
+ );
51
+
52
+ const { getByTestId } = render(
53
+ <MarkdownRendererProvider renderer={Custom}>
54
+ <AssistantMessage content="hello world" isLoading />
55
+ </MarkdownRendererProvider>,
56
+ );
57
+
58
+ const el = getByTestId("custom-renderer");
59
+ // Regression: previously AssistantMessage always used CopilotMarkdown and
60
+ // silently ignored the provider renderer, contradicting the migration guide.
61
+ expect(el.textContent).toBe("hello world");
62
+ // `isLoading` (streaming) must flow through as `isStreaming`.
63
+ expect(el.getAttribute("data-streaming")).toBe("true");
64
+ });
65
+
66
+ it("falls back to the built-in renderer when no provider renderer is set", () => {
67
+ const { queryByTestId, container } = render(
68
+ <AssistantMessage content="hello world" />,
69
+ );
70
+ expect(queryByTestId("custom-renderer")).toBeNull();
71
+ expect(container.textContent).toContain("hello world");
72
+ });
73
+ });
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react";
3
+ import { describe, it, expect, vi } from "vitest";
4
+
5
+ vi.mock("react-native", () => {
6
+ const R = require("react");
7
+ // RN accepts array styles (style={[a, b]}); a DOM element needs a plain
8
+ // object, so flatten before forwarding or react-dom rejects the array.
9
+ const flatten = (s: any) =>
10
+ Array.isArray(s)
11
+ ? Object.assign({}, ...s.flat(Infinity).filter(Boolean))
12
+ : s;
13
+ const View = R.forwardRef(
14
+ ({ children, style, testID, ...rest }: any, ref: any) =>
15
+ R.createElement(
16
+ "div",
17
+ { ref, style: flatten(style), "data-testid": testID, ...rest },
18
+ children,
19
+ ),
20
+ );
21
+ View.displayName = "View";
22
+ const Text = R.forwardRef(({ children, style, ...rest }: any, ref: any) =>
23
+ R.createElement("span", { ref, style: flatten(style), ...rest }, children),
24
+ );
25
+ Text.displayName = "Text";
26
+ return { View, Text, StyleSheet: { create: (s: any) => s, flatten } };
27
+ });
28
+ vi.mock("../TypingIndicator", () => ({ TypingIndicator: () => null }));
29
+
30
+ const captured: any[] = [];
31
+ vi.mock("../../Markdown", () => ({
32
+ CopilotMarkdown: (props: any) => {
33
+ captured.push(props);
34
+ return null;
35
+ },
36
+ }));
37
+
38
+ import { AssistantMessage } from "../AssistantMessage";
39
+ import { MarkdownRendererProvider } from "../../MarkdownRendererContext";
40
+
41
+ describe("RN markdownRenderer config", () => {
42
+ it("config object configures the built-in CopilotMarkdown (style + animate)", () => {
43
+ captured.length = 0;
44
+ const style = { paragraph: { color: "red" } };
45
+ render(
46
+ <MarkdownRendererProvider renderer={{ style, animate: true }}>
47
+ <AssistantMessage content="hello" />
48
+ </MarkdownRendererProvider>,
49
+ );
50
+ expect(captured[0].style).toEqual(style);
51
+ expect(captured[0].streamingAnimation).toBe(true);
52
+ });
53
+
54
+ it("component replaces the renderer (escape hatch)", () => {
55
+ captured.length = 0;
56
+ const Custom = ({ content }: { content: string }) =>
57
+ React.createElement("span", { "data-testid": "custom" }, content);
58
+ const { getByTestId } = render(
59
+ <MarkdownRendererProvider renderer={Custom}>
60
+ <AssistantMessage content="hello" isLoading />
61
+ </MarkdownRendererProvider>,
62
+ );
63
+ expect(getByTestId("custom").textContent).toBe("hello");
64
+ expect(captured).toHaveLength(0); // built-in CopilotMarkdown was bypassed
65
+ });
66
+ });
package/src/headless.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  * import { CopilotKitProvider, useAgent, useFrontendTool } from "@copilotkit/react-native/headless";
20
20
  * ```
21
21
  *
22
- * Mirrors `@copilotkit/react-core/v2/headless` (issue #4893 / PR #5883), which
22
+ * Mirrors `@copilotkit/react-core/headless` (issue #4893 / PR #5883), which
23
23
  * this entry builds on. The default barrel re-exports everything here plus the
24
24
  * chat UI, so existing imports from `@copilotkit/react-native` are unchanged.
25
25
  */
@@ -30,7 +30,7 @@ import "./polyfills";
30
30
 
31
31
  // Type-only, so both are erased and neither can run before the polyfills above.
32
32
  import type React from "react";
33
- import type { ReactToolCallRenderer } from "@copilotkit/react-core/v2/headless";
33
+ import type { ReactToolCallRenderer } from "@copilotkit/react-core/headless";
34
34
 
35
35
  // React Native provider (no web deps, no bottom-sheet, no expo native modules)
36
36
  export { CopilotKitProvider } from "./CopilotKitProvider";
@@ -45,7 +45,7 @@ export {
45
45
  useLicenseContext,
46
46
  CopilotKitContext,
47
47
  type CopilotKitContextValue,
48
- } from "@copilotkit/react-core/v2/context";
48
+ } from "@copilotkit/react-core/context";
49
49
 
50
50
  // Re-export hooks that work without web deps
51
51
  // These consume the CopilotKitContext which our provider sets
@@ -86,7 +86,7 @@ export {
86
86
  type RenderToolInProgressProps,
87
87
  type RenderToolExecutingProps,
88
88
  type RenderToolCompleteProps,
89
- } from "@copilotkit/react-core/v2/headless";
89
+ } from "@copilotkit/react-core/headless";
90
90
 
91
91
  // Re-export core runtime ENUMS as values. Each of these is `export enum` in
92
92
  // @copilotkit/core, and each is the type of a prop or field a consumer has to
@@ -136,15 +136,15 @@ export type {
136
136
  // both names and fails the build if any module in this entry's graph grows a
137
137
  // registry. Contract and migration notes:
138
138
  // /reference/react-native/hooks/useRenderTool.
139
- export { useRenderTool } from "@copilotkit/react-core/v2/headless";
140
- export type { RenderToolProps } from "@copilotkit/react-core/v2/headless";
139
+ export { useRenderTool } from "@copilotkit/react-core/headless";
140
+ export type { RenderToolProps } from "@copilotkit/react-core/headless";
141
141
 
142
142
  // Render tool consumption. react-core's hook is platform-agnostic — it pulls no
143
143
  // DOM and no chat-UI stack, and it returns ReactElement | null, which is exactly
144
144
  // what FlatList's renderItem requires. Use it to render a registered component
145
145
  // on any surface, chat or not.
146
- export { useRenderToolCall } from "@copilotkit/react-core/v2/headless";
147
- export type { ReactToolCallRenderer } from "@copilotkit/react-core/v2/headless";
146
+ export { useRenderToolCall } from "@copilotkit/react-core/headless";
147
+ export type { ReactToolCallRenderer } from "@copilotkit/react-core/headless";
148
148
 
149
149
  /**
150
150
  * A tool-call render function whose return type is narrowed to React Native's
package/src/index.ts CHANGED
@@ -53,7 +53,7 @@ export type { CopilotPopupProps, CopilotPopupHandle } from "./CopilotPopup";
53
53
  // above (`export * from "./headless"`).
54
54
  //
55
55
  // Deliberately NOT re-exported — these genuinely render host DOM or link the
56
- // web chat-message stack, from @copilotkit/react-core/v2 (the fat entry):
56
+ // web chat-message stack, from @copilotkit/react-core (the fat entry):
57
57
  // useDefaultRenderTool — DefaultToolCallRenderer uses <div>, <svg>, etc.
58
58
  // useRenderCustomMessages / useRenderActivityMessage — link @copilotkit/a2ui-renderer
59
59
  //
@@ -62,5 +62,22 @@ export type { CopilotPopupProps, CopilotPopupHandle } from "./CopilotPopup";
62
62
  // which was never true of the hook itself; it was only reachable through the fat
63
63
  // /v2 entry, whose weight is the real hazard (#4893). PR #5883 moved it into
64
64
  // /v2/headless, and we consume it from there. Never import from bare
65
- // "@copilotkit/react-core/v2" in this package — the import-graph guard in
65
+ // "@copilotkit/react-core" in this package — the import-graph guard in
66
66
  // src/__tests__/headless-entry-surface.test.ts fails the build if you do.
67
+
68
+ // Pluggable markdown renderer context
69
+ export {
70
+ MarkdownRendererProvider,
71
+ useMarkdownRenderer,
72
+ } from "./components/MarkdownRendererContext";
73
+ export type {
74
+ NativeMarkdownRenderer,
75
+ NativeMarkdownRendererProps,
76
+ } from "./components/MarkdownRendererContext";
77
+
78
+ // Built-in markdown renderer
79
+ export { CopilotMarkdown, defaultMarkdownStyles } from "./components/Markdown";
80
+ export type {
81
+ CopilotMarkdownProps,
82
+ MarkdownStyle,
83
+ } from "./components/Markdown";
package/tsdown.config.ts CHANGED
@@ -26,7 +26,6 @@ export default defineConfig({
26
26
  "@copilotkit/shared",
27
27
  "@ag-ui/client",
28
28
  "@gorhom/bottom-sheet",
29
- "react-native-streamdown",
30
29
  "react-native-gesture-handler",
31
30
  "react-native-reanimated",
32
31
  "react-native-enriched-markdown",
package/vitest.config.mjs CHANGED
@@ -18,13 +18,6 @@ export default defineConfig({
18
18
  // react-native uses Flow syntax that vite/rollup cannot parse.
19
19
  // This alias redirects to a minimal stub for test environments.
20
20
  "react-native": path.resolve(__dirname, "src/__mocks__/react-native.ts"),
21
- // react-native-streamdown is a peer dependency that won't be installed
22
- // in the monorepo dev environment; tests mock it via vi.mock().
23
- // This alias prevents vite's import-analysis from failing on the import.
24
- "react-native-streamdown": path.resolve(
25
- __dirname,
26
- "src/__mocks__/react-native-streamdown.ts",
27
- ),
28
21
  },
29
22
  },
30
23
  test: {
@@ -1 +0,0 @@
1
- {"version":3,"file":"CopilotKitProvider-CjoPnabW.cjs","names":["CopilotKitCoreReact","CopilotKitContext","LicenseContext"],"sources":["../src/CopilotKitProvider.tsx"],"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 {\n CopilotKitCoreErrorCode,\n CopilotKitMessageFilter,\n} 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 /**\n * Rewrites the message list sent to runtime agents on every run.\n *\n * CopilotKit sends the whole thread each time. When your agent already\n * stores the conversation, most of that payload is waste, and an agent that\n * merges the inbound list with its own store can show the model every turn\n * twice. Return the messages to send:\n *\n * ```tsx\n * <CopilotKitProvider\n * runtimeUrl=\"/api/copilotkit\"\n * messageFilter={(messages) => messages.slice(-1)}\n * />\n * ```\n *\n * The filter changes the request body only. The transcript the UI renders is\n * untouched. Broken tool-call pairs are repaired before the request is sent,\n * so a filter this blunt cannot strand a tool result mid-HITL.\n *\n * Agents reached through your CopilotRuntime honor this. An agent your app\n * passes in directly does not, and neither Intelligence runs nor suggestion\n * runs are ever filtered.\n *\n * Prefer a stable reference (`useCallback`). An inline arrow re-registers the\n * filter on every render, which is harmless but needless.\n */\n messageFilter?: CopilotKitMessageFilter;\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 messageFilter,\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 messageFilter,\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.setMessageFilter(messageFilter);\n copilotkit.setProperties(stableProperties);\n copilotkit.setDebug(debug);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n credentials,\n messageFilter,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,sBAA+D,EAC1E,UACA,YACA,SAAS,aACT,aACA,eACA,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;GACA,YAAY;GACZ;GACD,CAAC;AAGF,MAAI,sBAAsB,OACxB,UAAS,qBAAqB,kBAAkB;AAElD,gBAAc,UAAU;;CAG1B,MAAM,aAAa,cAAc;AAGjC,4BAAgB;AACd,aAAW,cAAc,WAAW;AACpC,aAAW,oBACT,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA,OACP;AACD,aAAW,WAAW,cAAc;AACpC,aAAW,eAAe,YAAY;AACtC,aAAW,iBAAiB,cAAc;AAC1C,aAAW,cAAc,iBAAiB;AAC1C,aAAW,SAAS,MAAM;IACzB;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAKF,4BAAgB;AACd,aAAW,qBAAqB,kBAAkB;IACjD,CAAC,YAAY,kBAAkB,CAAC;CAKnC,MAAM,CAAC,sBAAsB,qEAErB,IAAI,KAAK,CAAC;CAElB,MAAM,CAAC,sBAAsB,+CAE3B,OAAU;CAGZ,MAAM,+BAAoB,QAAQ;AAClC,4BAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAKb,4BAAgB;EACd,MAAM,eAAe,WAAW,UAAU;GACxC,uBAAuB,EAAE,iBAAiB;AACxC,6BAAyB,SAAS;AAChC,SAAI,KAAK,IAAI,WAAW,CAAE,QAAO;KACjC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,IAAI,WAAW;AACpB,YAAO;MACP;;GAEJ,qBAAqB,EAAE,iBAAiB;AACtC,6BAAyB,SAAS;AAChC,SAAI,CAAC,KAAK,IAAI,WAAW,CAAE,QAAO;KAClC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,OAAO,WAAW;AACvB,YAAO;MACP;;GAEJ,UAAU,UAAU;AAClB,QAAI,WAAW,QACb,YAAW,QAAQ,MAAM;QAEzB,SAAQ,MACN,uBAAuB,MAAM,KAAK,KAClC,MAAM,OACN,MAAM,WAAW,EAAE,CACpB;;GAGL,wCAAwC;AACtC,4BAAwB,WAAW,cAAc;;GAEpD,CAAC;AACF,eAAa,aAAa,aAAa;IACtC,CAAC,WAAW,CAAC;CAEhB,MAAM,yCACG;EACL;EACA;EACD,GACD,CAAC,YAAY,qBAAqB,CACnC;CAGD,MAAM,iGAC4B,qBAAqB,EACrD,CAAC,qBAAqB,CACvB;AAED,QACE,2CAACC,oDAAkB;EAAS,OAAO;YACjC,2CAACC,iDAAe;GAAS,OAAO;GAC7B;IACuB;GACC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CopilotKitProvider-D8sn7G_C.mjs","names":[],"sources":["../src/CopilotKitProvider.tsx"],"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 {\n CopilotKitCoreErrorCode,\n CopilotKitMessageFilter,\n} 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 /**\n * Rewrites the message list sent to runtime agents on every run.\n *\n * CopilotKit sends the whole thread each time. When your agent already\n * stores the conversation, most of that payload is waste, and an agent that\n * merges the inbound list with its own store can show the model every turn\n * twice. Return the messages to send:\n *\n * ```tsx\n * <CopilotKitProvider\n * runtimeUrl=\"/api/copilotkit\"\n * messageFilter={(messages) => messages.slice(-1)}\n * />\n * ```\n *\n * The filter changes the request body only. The transcript the UI renders is\n * untouched. Broken tool-call pairs are repaired before the request is sent,\n * so a filter this blunt cannot strand a tool result mid-HITL.\n *\n * Agents reached through your CopilotRuntime honor this. An agent your app\n * passes in directly does not, and neither Intelligence runs nor suggestion\n * runs are ever filtered.\n *\n * Prefer a stable reference (`useCallback`). An inline arrow re-registers the\n * filter on every render, which is harmless but needless.\n */\n messageFilter?: CopilotKitMessageFilter;\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 messageFilter,\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 messageFilter,\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.setMessageFilter(messageFilter);\n copilotkit.setProperties(stableProperties);\n copilotkit.setDebug(debug);\n }, [\n runtimeUrl,\n useSingleEndpoint,\n stableHeaders,\n credentials,\n messageFilter,\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,sBAA+D,EAC1E,UACA,YACA,SAAS,aACT,aACA,eACA,mBACA,YACA,SACA,OACA,wBACI;CAEJ,MAAM,kBACJ,OAAO,gBAAgB,aAAa,aAAa,GAAG;CAKtD,MAAM,gBAAgB,cACd,mBAAmB,EAAE,EAC3B,CAAC,KAAK,UAAU,gBAAgB,CAAC,CAClC;CAED,MAAM,mBAAmB,cACjB,cAAc,EAAE,EACtB,CAAC,KAAK,UAAU,WAAW,CAAC,CAC7B;CAED,MAAM,gBAAgB,OAA2C,KAAK;AAEtE,KAAI,cAAc,YAAY,MAAM;EAClC,MAAM,WAAwC,IAAI,oBAAoB;GACpE;GACA,kBACE,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA;GACR,SAAS;GACT;GACA;GACA,YAAY;GACZ;GACD,CAAC;AAGF,MAAI,sBAAsB,OACxB,UAAS,qBAAqB,kBAAkB;AAElD,gBAAc,UAAU;;CAG1B,MAAM,aAAa,cAAc;AAGjC,iBAAgB;AACd,aAAW,cAAc,WAAW;AACpC,aAAW,oBACT,sBAAsB,OAClB,WACA,sBAAsB,QACpB,SACA,OACP;AACD,aAAW,WAAW,cAAc;AACpC,aAAW,eAAe,YAAY;AACtC,aAAW,iBAAiB,cAAc;AAC1C,aAAW,cAAc,iBAAiB;AAC1C,aAAW,SAAS,MAAM;IACzB;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAKF,iBAAgB;AACd,aAAW,qBAAqB,kBAAkB;IACjD,CAAC,YAAY,kBAAkB,CAAC;CAKnC,MAAM,CAAC,sBAAsB,2BAA2B,+BAEhD,IAAI,KAAK,CAAC;CAElB,MAAM,CAAC,sBAAsB,2BAA2B,SAEtD,OAAU;CAGZ,MAAM,aAAa,OAAO,QAAQ;AAClC,iBAAgB;AACd,aAAW,UAAU;IACpB,CAAC,QAAQ,CAAC;AAKb,iBAAgB;EACd,MAAM,eAAe,WAAW,UAAU;GACxC,uBAAuB,EAAE,iBAAiB;AACxC,6BAAyB,SAAS;AAChC,SAAI,KAAK,IAAI,WAAW,CAAE,QAAO;KACjC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,IAAI,WAAW;AACpB,YAAO;MACP;;GAEJ,qBAAqB,EAAE,iBAAiB;AACtC,6BAAyB,SAAS;AAChC,SAAI,CAAC,KAAK,IAAI,WAAW,CAAE,QAAO;KAClC,MAAM,OAAO,IAAI,IAAI,KAAK;AAC1B,UAAK,OAAO,WAAW;AACvB,YAAO;MACP;;GAEJ,UAAU,UAAU;AAClB,QAAI,WAAW,QACb,YAAW,QAAQ,MAAM;QAEzB,SAAQ,MACN,uBAAuB,MAAM,KAAK,KAClC,MAAM,OACN,MAAM,WAAW,EAAE,CACpB;;GAGL,wCAAwC;AACtC,4BAAwB,WAAW,cAAc;;GAEpD,CAAC;AACF,eAAa,aAAa,aAAa;IACtC,CAAC,WAAW,CAAC;CAEhB,MAAM,eAAuC,eACpC;EACL;EACA;EACD,GACD,CAAC,YAAY,qBAAqB,CACnC;CAGD,MAAM,sBAAsB,cACpB,0BAA0B,qBAAqB,EACrD,CAAC,qBAAqB,CACvB;AAED,QACE,oBAAC,kBAAkB;EAAS,OAAO;YACjC,oBAAC,eAAe;GAAS,OAAO;GAC7B;IACuB;GACC"}
@@ -1,34 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
-
29
- Object.defineProperty(exports, '__toESM', {
30
- enumerable: true,
31
- get: function () {
32
- return __toESM;
33
- }
34
- });
@@ -1,16 +0,0 @@
1
- /**
2
- * Fallback module for react-native-streamdown.
3
- *
4
- * react-native-streamdown is a peer dependency that isn't installed during
5
- * monorepo development. This stub satisfies vite's import resolution so
6
- * that vi.mock() in test files can override it at runtime.
7
- */
8
- import React from "react";
9
-
10
- export function StreamdownText(props: {
11
- markdown: string;
12
- markdownStyle?: Record<string, unknown>;
13
- streamingAnimation?: boolean;
14
- }) {
15
- return React.createElement("div", null, props.markdown);
16
- }