@copilotkit/react-native 2.0.0-rc.5 → 2.0.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +334 -2
- package/USAGE.md +382 -21
- package/dist/CopilotKitProvider-CBVQLdzn.d.cts +77 -0
- package/dist/{CopilotKitProvider-CE4bc6CP.mjs → CopilotKitProvider-CCBBonxr.mjs} +63 -43
- package/dist/CopilotKitProvider-CCBBonxr.mjs.map +1 -0
- package/dist/CopilotKitProvider-CtQg_0S-.d.mts +77 -0
- package/dist/{CopilotKitProvider-Byw3cqe2.cjs → CopilotKitProvider-QdcQrrSA.cjs} +69 -42
- package/dist/CopilotKitProvider-QdcQrrSA.cjs.map +1 -0
- package/dist/{Markdown-C_9Re36O.cjs → Markdown-DLopAh5W.cjs} +10 -10
- package/dist/Markdown-DLopAh5W.cjs.map +1 -0
- package/dist/{Markdown-JsYh7oSA.d.mts → Markdown-Du-b_Qpr.d.mts} +3 -3
- package/dist/{Markdown-1ips7myr.d.cts → Markdown-UXZdDjzs.d.cts} +3 -3
- package/dist/{Markdown-C6AsLHmd.mjs → Markdown-VxtPJ_yh.mjs} +4 -4
- package/dist/Markdown-VxtPJ_yh.mjs.map +1 -0
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs → MarkdownRendererContext-EobUsERg.mjs} +1 -1
- package/dist/{MarkdownRendererContext-CAnuohIS.mjs.map → MarkdownRendererContext-EobUsERg.mjs.map} +1 -1
- package/dist/MarkdownRendererContext-cDEHvbw9.cjs +40 -0
- package/dist/{MarkdownRendererContext-BRNe808d.cjs.map → MarkdownRendererContext-cDEHvbw9.cjs.map} +1 -1
- package/dist/chunk-C0xms8kb.cjs +34 -0
- package/dist/components/index.cjs +78 -175
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +76 -174
- package/dist/components/index.mjs.map +1 -1
- package/dist/generative-ui/index.cjs +612 -0
- package/dist/generative-ui/index.cjs.map +1 -0
- package/dist/generative-ui/index.d.cts +341 -0
- package/dist/generative-ui/index.d.mts +341 -0
- package/dist/generative-ui/index.mjs +549 -0
- package/dist/generative-ui/index.mjs.map +1 -0
- package/dist/headless.cjs +3 -2
- package/dist/headless.d.cts +3 -3
- package/dist/headless.d.mts +3 -3
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +132 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +37 -19
- package/dist/index.d.mts +37 -19
- package/dist/index.mjs +131 -162
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills/encoding.cjs +115 -5
- package/dist/polyfills/encoding.cjs.map +1 -1
- package/dist/polyfills/encoding.d.cts +31 -1
- package/dist/polyfills/encoding.d.mts +31 -1
- package/dist/polyfills/encoding.mjs +113 -6
- package/dist/polyfills/encoding.mjs.map +1 -1
- package/dist/polyfills/streams.cjs +1 -1
- package/dist/polyfills.cjs +218 -2
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +217 -1
- package/dist/polyfills.mjs.map +1 -1
- package/package.json +51 -21
- package/project.json +6 -1
- package/scripts/__tests__/verify-polyfill-barrel.test.mjs +150 -0
- package/scripts/verify-polyfill-barrel.mjs +158 -11
- package/src/CopilotChat.tsx +114 -93
- package/src/CopilotKitProvider.tsx +101 -130
- package/src/CopilotPopup.tsx +2 -2
- package/src/CopilotSidebar.tsx +7 -5
- package/src/__mocks__/react-native.ts +31 -0
- package/src/__mocks__/test-copilotkit.tsx +9 -3
- package/src/__tests__/attachments-integration.test.tsx +15 -2
- package/src/__tests__/copilot-chat-agentid.test.tsx +15 -2
- package/src/__tests__/copilot-chat-attachments.test.tsx +15 -2
- package/src/__tests__/copilot-chat-configuration.test.tsx +82 -0
- package/src/__tests__/copilot-chat-threads.test.tsx +232 -0
- package/src/__tests__/copilot-popup.test.tsx +15 -2
- package/src/__tests__/copilot-sidebar.test.tsx +15 -2
- package/src/__tests__/copilotkit-alias-exports.test.ts +16 -0
- package/src/__tests__/copilotkit-provider.test.tsx +68 -73
- package/src/__tests__/generative-ui-harness.tsx +243 -0
- package/src/__tests__/generative-ui-provider-props.test-d.tsx +106 -0
- package/src/__tests__/generative-ui-rn-mock.tsx +54 -0
- package/src/__tests__/generative-ui-wiring.test.tsx +720 -0
- package/src/__tests__/generative-ui.test.tsx +1000 -0
- package/src/__tests__/headless-entry-surface.test.ts +979 -61
- package/src/__tests__/headless-integration.test.tsx +11 -1
- package/src/__tests__/use-attachments.test.ts +27 -2
- package/src/components/CopilotChat.tsx +106 -233
- package/src/components/CopilotModal.tsx +1 -1
- package/src/components/Markdown.tsx +4 -4
- package/src/components/__tests__/CopilotChat-edge-cases.test.tsx +5 -1
- package/src/components/__tests__/CopilotChat.test.tsx +12 -4
- package/src/components/__tests__/CopilotChatInterrupt.test.tsx +208 -0
- package/src/components/__tests__/Markdown.code-alias.test.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/messages/AssistantMessage.tsx +3 -3
- package/src/components/messages/TypingIndicator.tsx +4 -4
- package/src/generative-ui/GenerativeUIActivity.tsx +235 -0
- package/src/generative-ui/GenerativeUIProvider.tsx +171 -0
- package/src/generative-ui/GenerativeUISurface.tsx +303 -0
- package/src/generative-ui/host.tsx +138 -0
- package/src/generative-ui/index.ts +93 -0
- package/src/generative-ui/internal.ts +55 -0
- package/src/headless.ts +4 -0
- package/src/hooks/use-attachments.ts +95 -139
- package/src/index.ts +10 -4
- package/src/polyfills/__tests__/encoding-utf8.test.ts +112 -0
- package/src/polyfills/encoding.ts +160 -4
- package/src/types.d.ts +0 -13
- package/tsdown.config.ts +1 -0
- package/dist/CopilotKitProvider-BWjzCdHN.d.mts +0 -121
- package/dist/CopilotKitProvider-Btm10msB.d.cts +0 -121
- package/dist/CopilotKitProvider-Byw3cqe2.cjs.map +0 -1
- package/dist/CopilotKitProvider-CE4bc6CP.mjs.map +0 -1
- package/dist/Markdown-C6AsLHmd.mjs.map +0 -1
- package/dist/Markdown-C_9Re36O.cjs.map +0 -1
- package/dist/MarkdownRendererContext-BRNe808d.cjs +0 -72
- package/dist/streaming-fetch-Bm91EsRc.cjs +0 -225
- package/dist/streaming-fetch-Bm91EsRc.cjs.map +0 -1
- package/dist/streaming-fetch-Dm1oN4f2.mjs +0 -219
- package/dist/streaming-fetch-Dm1oN4f2.mjs.map +0 -1
package/dist/headless.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./Markdown-
|
|
2
|
-
import {
|
|
1
|
+
import "./Markdown-UXZdDjzs.cjs";
|
|
2
|
+
import { i as CopilotKitProvider, n as CopilotKitNativeProviderProps, r as CopilotKitProps, t as CopilotKit } from "./CopilotKitProvider-CBVQLdzn.cjs";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { AgentContextInput, CopilotChatConfigurationValue, CopilotChatDefaultLabels, CopilotChatLabels, Interrupt, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ReactToolCallRenderer as ReactToolCallRenderer$1, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, RenderToolProps, ResumeEntry, ResumeStatus, Thread, UseAgentUpdate, UseInterruptConfig, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderTool, useRenderToolCall, useSuggestions, useThreads } from "@copilotkit/react-core/headless";
|
|
5
5
|
import { CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, FrontendTool, Suggestion, ToolCallStatus } from "@copilotkit/core";
|
|
@@ -59,5 +59,5 @@ import { AbstractAgent, AgentCapabilities, AssistantMessage as AssistantMessageT
|
|
|
59
59
|
*/
|
|
60
60
|
type FrontendToolRenderFunction<T extends Record<string, unknown> = Record<string, unknown>> = (props: React.ComponentProps<ReactToolCallRenderer$1<T>["render"]>) => React.ReactElement | null;
|
|
61
61
|
//#endregion
|
|
62
|
-
export { AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessageType, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKitContext, type CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, CopilotKitProvider, type FrontendTool, FrontendToolRenderFunction, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type ResumeEntry, type ResumeStatus, type Suggestion, type Thread, type ToolCall, ToolCallStatus, type ToolMessage, UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
|
62
|
+
export { AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessageType, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKit, CopilotKitContext, type CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, type CopilotKitProps, CopilotKitProvider, type FrontendTool, FrontendToolRenderFunction, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type ResumeEntry, type ResumeStatus, type Suggestion, type Thread, type ToolCall, ToolCallStatus, type ToolMessage, UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
|
63
63
|
//# sourceMappingURL=headless.d.cts.map
|
package/dist/headless.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./Markdown-
|
|
2
|
-
import {
|
|
1
|
+
import "./Markdown-Du-b_Qpr.mjs";
|
|
2
|
+
import { i as CopilotKitProvider, n as CopilotKitNativeProviderProps, r as CopilotKitProps, t as CopilotKit } from "./CopilotKitProvider-CtQg_0S-.mjs";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { CopilotKitContext, CopilotKitContextValue, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/context";
|
|
5
5
|
import { AgentContextInput, CopilotChatConfigurationValue, CopilotChatDefaultLabels, CopilotChatLabels, Interrupt, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, ReactFrontendTool, ReactHumanInTheLoop, ReactToolCallRenderer, ReactToolCallRenderer as ReactToolCallRenderer$1, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, RenderToolProps, ResumeEntry, ResumeStatus, Thread, UseAgentUpdate, UseInterruptConfig, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderTool, useRenderToolCall, useSuggestions, useThreads } from "@copilotkit/react-core/headless";
|
|
@@ -59,5 +59,5 @@ import { AbstractAgent, AgentCapabilities, AssistantMessage as AssistantMessageT
|
|
|
59
59
|
*/
|
|
60
60
|
type FrontendToolRenderFunction<T extends Record<string, unknown> = Record<string, unknown>> = (props: React.ComponentProps<ReactToolCallRenderer$1<T>["render"]>) => React.ReactElement | null;
|
|
61
61
|
//#endregion
|
|
62
|
-
export { AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessageType, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKitContext, type CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, CopilotKitProvider, type FrontendTool, FrontendToolRenderFunction, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type ResumeEntry, type ResumeStatus, type Suggestion, type Thread, type ToolCall, ToolCallStatus, type ToolMessage, UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
|
62
|
+
export { AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessageType, type CopilotChatConfigurationValue, CopilotChatDefaultLabels, type CopilotChatLabels, CopilotKit, CopilotKitContext, type CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, type CopilotKitProps, CopilotKitProvider, type FrontendTool, FrontendToolRenderFunction, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, type ResumeEntry, type ResumeStatus, type Suggestion, type Thread, type ToolCall, ToolCallStatus, type ToolMessage, UseAgentUpdate, type UseInterruptConfig, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
|
63
63
|
//# sourceMappingURL=headless.d.mts.map
|
package/dist/headless.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "./polyfills.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as CopilotKitProvider, t as CopilotKit } from "./CopilotKitProvider-CCBBonxr.mjs";
|
|
3
3
|
import { CopilotKitContext, useCopilotKit, useLicenseContext } from "@copilotkit/react-core/context";
|
|
4
4
|
import { CopilotChatDefaultLabels, UseAgentUpdate, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useRenderTool, useRenderToolCall, useSuggestions, useThreads } from "@copilotkit/react-core/headless";
|
|
5
5
|
import { CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, ToolCallStatus } from "@copilotkit/core";
|
|
6
6
|
import { AbstractAgent } from "@ag-ui/client";
|
|
7
7
|
|
|
8
|
-
export { AbstractAgent, CopilotChatDefaultLabels, CopilotKitContext, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, CopilotKitProvider, ToolCallStatus, UseAgentUpdate, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
|
8
|
+
export { AbstractAgent, CopilotChatDefaultLabels, CopilotKit, CopilotKitContext, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, CopilotKitProvider, ToolCallStatus, UseAgentUpdate, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolCall, useSuggestions, useThreads };
|
package/dist/index.cjs
CHANGED
|
@@ -1,119 +1,89 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
|
|
2
|
+
const require_chunk = require('./chunk-C0xms8kb.cjs');
|
|
3
|
+
require('./polyfills.cjs');
|
|
4
|
+
const require_MarkdownRendererContext = require('./MarkdownRendererContext-cDEHvbw9.cjs');
|
|
5
|
+
const require_CopilotKitProvider = require('./CopilotKitProvider-QdcQrrSA.cjs');
|
|
4
6
|
require('./headless.cjs');
|
|
5
|
-
const require_Markdown = require('./Markdown-
|
|
7
|
+
const require_Markdown = require('./Markdown-DLopAh5W.cjs');
|
|
6
8
|
let react = require("react");
|
|
7
|
-
react =
|
|
9
|
+
react = require_chunk.__toESM(react);
|
|
8
10
|
let _copilotkit_react_core_context = require("@copilotkit/react-core/context");
|
|
9
11
|
let _copilotkit_react_core_headless = require("@copilotkit/react-core/headless");
|
|
12
|
+
let _copilotkit_core = require("@copilotkit/core");
|
|
10
13
|
let _copilotkit_shared = require("@copilotkit/shared");
|
|
11
14
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
15
|
let expo_document_picker = require("expo-document-picker");
|
|
13
|
-
expo_document_picker =
|
|
16
|
+
expo_document_picker = require_chunk.__toESM(expo_document_picker);
|
|
14
17
|
let expo_file_system = require("expo-file-system");
|
|
15
|
-
expo_file_system =
|
|
18
|
+
expo_file_system = require_chunk.__toESM(expo_file_system);
|
|
16
19
|
let react_native = require("react-native");
|
|
17
20
|
let _ag_ui_client = require("@ag-ui/client");
|
|
18
|
-
let _copilotkit_core = require("@copilotkit/core");
|
|
19
21
|
|
|
20
22
|
//#region src/hooks/use-attachments.ts
|
|
21
|
-
const
|
|
23
|
+
const nativeFiles = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
/**
|
|
25
|
+
* Wraps a native file for core's `ɵAttachmentQueue`, which is typed for the
|
|
26
|
+
* web `File`. The queue reads only `name`, `size` and `type`, because the
|
|
27
|
+
* config from {@link toQueueConfig} always uploads through `onUpload` and the
|
|
28
|
+
* queue never reads the bytes itself.
|
|
29
|
+
*/
|
|
30
|
+
function toQueueFile(file) {
|
|
31
|
+
const queued = {
|
|
32
|
+
name: file.name,
|
|
33
|
+
size: file.size,
|
|
34
|
+
type: file.mimeType
|
|
35
|
+
};
|
|
36
|
+
nativeFiles.set(queued, file);
|
|
37
|
+
return queued;
|
|
38
|
+
}
|
|
39
|
+
function toNativeFile(file) {
|
|
40
|
+
const native = nativeFiles.get(file);
|
|
41
|
+
if (!native) throw new Error(`[CopilotKit] "${file.name}" was not picked natively`);
|
|
42
|
+
return native;
|
|
43
|
+
}
|
|
44
|
+
/** Reads a picked file as base64 with expo-file-system. */
|
|
45
|
+
async function readNativeFile(file) {
|
|
46
|
+
return {
|
|
47
|
+
type: "data",
|
|
48
|
+
value: await expo_file_system.readAsStringAsync(file.uri, { encoding: expo_file_system.EncodingType.Base64 }),
|
|
49
|
+
mimeType: file.mimeType
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The RN config as core's queue takes it. Uploads go through the app's
|
|
54
|
+
* `onUpload`, or through expo-file-system when there is none.
|
|
55
|
+
*/
|
|
56
|
+
function toQueueConfig(config) {
|
|
57
|
+
if (!config) return void 0;
|
|
58
|
+
const { onUpload, onUploadFailed, ...rest } = config;
|
|
59
|
+
return {
|
|
60
|
+
...rest,
|
|
61
|
+
onUpload: (file) => {
|
|
62
|
+
const native = toNativeFile(file);
|
|
63
|
+
return onUpload ? onUpload(native) : readNativeFile(native);
|
|
64
|
+
},
|
|
65
|
+
onUploadFailed: onUploadFailed ? ({ file, ...error }) => onUploadFailed({
|
|
66
|
+
...error,
|
|
67
|
+
file: toNativeFile(file)
|
|
68
|
+
}) : void 0
|
|
69
|
+
};
|
|
70
|
+
}
|
|
22
71
|
/**
|
|
23
72
|
* React Native hook that manages file attachment state -- picking, uploading,
|
|
24
|
-
* and lifecycle. All returned callbacks are referentially stable
|
|
73
|
+
* and lifecycle. All returned callbacks are referentially stable.
|
|
25
74
|
*
|
|
26
|
-
*
|
|
27
|
-
* `@copilotkit/
|
|
28
|
-
*
|
|
75
|
+
* The queue itself (accept filter, size check, uploads, ready state) is
|
|
76
|
+
* `@copilotkit/core`'s `ɵAttachmentQueue`, shared with the web chats. This
|
|
77
|
+
* hook adds the native glue: expo-document-picker to pick files and
|
|
78
|
+
* expo-file-system to read them.
|
|
29
79
|
*/
|
|
30
80
|
function useAttachments({ config }) {
|
|
31
81
|
const enabled = config?.enabled ?? false;
|
|
32
|
-
const [attachments, setAttachments] = (0, react.useState)([]);
|
|
33
82
|
const configRef = (0, react.useRef)(config);
|
|
34
83
|
configRef.current = config;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* Simple MIME accept filter for NativeFileInput.
|
|
39
|
-
* Handles wildcards like "image/*" and exact types like "application/pdf".
|
|
40
|
-
* Comma-separated lists are supported.
|
|
41
|
-
*/
|
|
42
|
-
const matchesAccept = (0, react.useCallback)((file, accept) => {
|
|
43
|
-
if (!accept || accept === "*/*") return true;
|
|
44
|
-
return accept.split(",").map((f) => f.trim()).some((filter) => {
|
|
45
|
-
if (filter.startsWith(".")) return file.name.toLowerCase().endsWith(filter.toLowerCase());
|
|
46
|
-
if (filter.endsWith("/*")) {
|
|
47
|
-
const prefix = filter.slice(0, -2);
|
|
48
|
-
return file.mimeType.startsWith(prefix + "/");
|
|
49
|
-
}
|
|
50
|
-
return file.mimeType === filter;
|
|
51
|
-
});
|
|
52
|
-
}, []);
|
|
53
|
-
const processFiles = (0, react.useCallback)(async (files) => {
|
|
54
|
-
const cfg = configRef.current;
|
|
55
|
-
const accept = cfg?.accept ?? "*/*";
|
|
56
|
-
const maxSize = cfg?.maxSize ?? DEFAULT_MAX_SIZE;
|
|
57
|
-
const rejectedFiles = files.filter((f) => !matchesAccept(f, accept));
|
|
58
|
-
for (const file of rejectedFiles) cfg?.onUploadFailed?.({
|
|
59
|
-
reason: "invalid-type",
|
|
60
|
-
file,
|
|
61
|
-
message: `File "${file.name}" is not accepted. Supported types: ${accept}`
|
|
62
|
-
});
|
|
63
|
-
const validFiles = files.filter((f) => matchesAccept(f, accept));
|
|
64
|
-
for (const file of validFiles) {
|
|
65
|
-
if (file.size > maxSize) {
|
|
66
|
-
cfg?.onUploadFailed?.({
|
|
67
|
-
reason: "file-too-large",
|
|
68
|
-
file,
|
|
69
|
-
message: `File "${file.name}" exceeds the maximum size of ${(0, _copilotkit_shared.formatFileSize)(maxSize)}`
|
|
70
|
-
});
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
const modality = (0, _copilotkit_shared.getModalityFromMimeType)(file.mimeType);
|
|
74
|
-
const placeholderId = (0, _copilotkit_shared.randomUUID)();
|
|
75
|
-
const placeholder = {
|
|
76
|
-
id: placeholderId,
|
|
77
|
-
type: modality,
|
|
78
|
-
source: {
|
|
79
|
-
type: "data",
|
|
80
|
-
value: "",
|
|
81
|
-
mimeType: file.mimeType
|
|
82
|
-
},
|
|
83
|
-
filename: file.name,
|
|
84
|
-
size: file.size,
|
|
85
|
-
status: "uploading"
|
|
86
|
-
};
|
|
87
|
-
setAttachments((prev) => [...prev, placeholder]);
|
|
88
|
-
try {
|
|
89
|
-
let source;
|
|
90
|
-
let uploadMetadata;
|
|
91
|
-
if (cfg?.onUpload) {
|
|
92
|
-
const { metadata: meta, ...uploadSource } = await cfg.onUpload(file);
|
|
93
|
-
source = uploadSource;
|
|
94
|
-
uploadMetadata = meta;
|
|
95
|
-
} else source = {
|
|
96
|
-
type: "data",
|
|
97
|
-
value: await expo_file_system.readAsStringAsync(file.uri, { encoding: expo_file_system.EncodingType.Base64 }),
|
|
98
|
-
mimeType: file.mimeType
|
|
99
|
-
};
|
|
100
|
-
setAttachments((prev) => prev.map((att) => att.id === placeholderId ? {
|
|
101
|
-
...att,
|
|
102
|
-
source,
|
|
103
|
-
status: "ready",
|
|
104
|
-
metadata: uploadMetadata
|
|
105
|
-
} : att));
|
|
106
|
-
} catch (error) {
|
|
107
|
-
setAttachments((prev) => prev.filter((att) => att.id !== placeholderId));
|
|
108
|
-
console.error(`[CopilotKit] Failed to upload "${file.name}":`, error);
|
|
109
|
-
cfg?.onUploadFailed?.({
|
|
110
|
-
reason: "upload-failed",
|
|
111
|
-
file,
|
|
112
|
-
message: error instanceof Error ? error.message : `Failed to upload "${file.name}"`
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}, [matchesAccept]);
|
|
84
|
+
const [queue] = (0, react.useState)(() => new _copilotkit_core.ɵAttachmentQueue(() => toQueueConfig(configRef.current)));
|
|
85
|
+
const attachments = (0, react.useSyncExternalStore)((0, react.useCallback)((onChange) => queue.subscribe(onChange), [queue]), () => queue.getSnapshot(), () => queue.getSnapshot());
|
|
86
|
+
const processFiles = (0, react.useCallback)((files) => queue.processFiles(files.map(toQueueFile)), [queue]);
|
|
117
87
|
return {
|
|
118
88
|
attachments,
|
|
119
89
|
enabled,
|
|
@@ -137,15 +107,8 @@ function useAttachments({ config }) {
|
|
|
137
107
|
}
|
|
138
108
|
}, [processFiles]),
|
|
139
109
|
processFiles,
|
|
140
|
-
removeAttachment: (0, react.useCallback)((id) =>
|
|
141
|
-
|
|
142
|
-
}, []),
|
|
143
|
-
consumeAttachments: (0, react.useCallback)(() => {
|
|
144
|
-
const ready = attachmentsRef.current.filter((a) => a.status === "ready");
|
|
145
|
-
if (ready.length === 0) return ready;
|
|
146
|
-
setAttachments((prev) => prev.filter((a) => a.status !== "ready"));
|
|
147
|
-
return ready;
|
|
148
|
-
}, [])
|
|
110
|
+
removeAttachment: (0, react.useCallback)((id) => queue.remove(id), [queue]),
|
|
111
|
+
consumeAttachments: (0, react.useCallback)(() => queue.consumeReady(), [queue])
|
|
149
112
|
};
|
|
150
113
|
}
|
|
151
114
|
|
|
@@ -170,6 +133,16 @@ function useCopilotChatContext() {
|
|
|
170
133
|
*
|
|
171
134
|
* Children can access chat state via `useCopilotChatContext()`.
|
|
172
135
|
*
|
|
136
|
+
* Hooks inside the chat, such as `useAgent` and `useInterrupt`, use this
|
|
137
|
+
* chat's agent when they do not pass an `agentId`. When the chat has a
|
|
138
|
+
* `threadId`, `useAgent` inside the chat sets that thread on each agent it
|
|
139
|
+
* returns, also on an agent that the hook names with its own `agentId`. Only
|
|
140
|
+
* `useAgent({ agentId, runtimeAgentId, threadId })` keeps a different thread.
|
|
141
|
+
*
|
|
142
|
+
* A chat inside another chat uses the outer chat's agent when it has no
|
|
143
|
+
* `agentId`. When the outer chat has a `threadId` and the inner chat does not,
|
|
144
|
+
* the inner chat uses the outer thread. The web `CopilotChat` does the same.
|
|
145
|
+
*
|
|
173
146
|
* ```tsx
|
|
174
147
|
* import { CopilotChat, useCopilotChatContext } from "@copilotkit/react-native";
|
|
175
148
|
*
|
|
@@ -184,7 +157,8 @@ function useCopilotChatContext() {
|
|
|
184
157
|
* ```
|
|
185
158
|
*/
|
|
186
159
|
function CopilotChat({ agentId, agentName, threadId, onError, throttleMs, attachments: attachmentsConfig, children, ..._rest }) {
|
|
187
|
-
const
|
|
160
|
+
const chatConfig = (0, _copilotkit_react_core_headless.useCopilotChatConfiguration)();
|
|
161
|
+
const resolvedAgentId = agentId ?? agentName ?? chatConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
188
162
|
const warnedRef = (0, react.useRef)(false);
|
|
189
163
|
(0, react.useEffect)(() => {
|
|
190
164
|
if (agentName !== void 0 && agentId === void 0 && !warnedRef.current) {
|
|
@@ -192,72 +166,62 @@ function CopilotChat({ agentId, agentName, threadId, onError, throttleMs, attach
|
|
|
192
166
|
if (typeof __DEV__ === "undefined" || __DEV__) console.warn("[CopilotKit] agentName is deprecated, use agentId instead");
|
|
193
167
|
}
|
|
194
168
|
}, [agentName, agentId]);
|
|
169
|
+
const providedThreadId = threadId ?? chatConfig?.threadId;
|
|
170
|
+
const [freshThreadId] = (0, react.useState)(() => new _copilotkit_core.ɵFreshThreadId());
|
|
171
|
+
const resolvedThreadId = (0, react.useMemo)(() => freshThreadId.resolve(providedThreadId), [freshThreadId, providedThreadId]);
|
|
172
|
+
const hasExplicitThreadId = !!threadId || !!chatConfig?.hasExplicitThreadId;
|
|
195
173
|
const { agent } = (0, _copilotkit_react_core_headless.useAgent)({
|
|
196
174
|
agentId: resolvedAgentId,
|
|
197
175
|
throttleMs
|
|
198
176
|
});
|
|
199
|
-
(0, react.useEffect)(() => {
|
|
200
|
-
if (threadId) agent.threadId = threadId;
|
|
201
|
-
}, [agent, threadId]);
|
|
202
177
|
const { copilotkit } = (0, _copilotkit_react_core_context.useCopilotKit)();
|
|
178
|
+
const [connection] = (0, react.useState)(() => new _copilotkit_core.ɵChatConnection({ core: copilotkit }));
|
|
179
|
+
const { threads } = connection;
|
|
180
|
+
(0, react.useEffect)(() => {
|
|
181
|
+
const handle = connection.open({
|
|
182
|
+
agent,
|
|
183
|
+
threadId: resolvedThreadId,
|
|
184
|
+
explicit: hasExplicitThreadId
|
|
185
|
+
});
|
|
186
|
+
return () => handle.release();
|
|
187
|
+
}, [
|
|
188
|
+
connection,
|
|
189
|
+
agent,
|
|
190
|
+
resolvedThreadId,
|
|
191
|
+
hasExplicitThreadId
|
|
192
|
+
]);
|
|
203
193
|
const onErrorRef = (0, react.useRef)(onError);
|
|
204
194
|
(0, react.useEffect)(() => {
|
|
205
195
|
onErrorRef.current = onError;
|
|
206
196
|
}, [onError]);
|
|
207
197
|
(0, react.useEffect)(() => {
|
|
208
198
|
if (!onErrorRef.current) return;
|
|
209
|
-
|
|
210
|
-
if (event.context?.agentId === resolvedAgentId || !event.context?.agentId) onErrorRef.current?.({
|
|
211
|
-
error: event.error,
|
|
212
|
-
code: event.code,
|
|
213
|
-
context: event.context
|
|
214
|
-
});
|
|
215
|
-
} });
|
|
216
|
-
return () => {
|
|
217
|
-
subscription.unsubscribe();
|
|
218
|
-
};
|
|
199
|
+
return (0, _copilotkit_core.ɵsubscribeToAgentErrors)(copilotkit, resolvedAgentId, (event) => onErrorRef.current?.(event));
|
|
219
200
|
}, [copilotkit, resolvedAgentId]);
|
|
220
201
|
const { attachments: selectedAttachments, enabled: attachmentsEnabled, openPicker, removeAttachment, consumeAttachments } = useAttachments({ config: attachmentsConfig });
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
content: contentParts
|
|
245
|
-
});
|
|
246
|
-
} else agent.addMessage({
|
|
247
|
-
id: (0, _copilotkit_shared.randomUUID)(),
|
|
248
|
-
role: "user",
|
|
249
|
-
content: value
|
|
250
|
-
});
|
|
251
|
-
try {
|
|
252
|
-
await copilotkit.runAgent({ agent });
|
|
253
|
-
} catch (error) {
|
|
254
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
255
|
-
}
|
|
256
|
-
}, [
|
|
257
|
-
agent,
|
|
258
|
-
selectedAttachments,
|
|
259
|
-
consumeAttachments
|
|
260
|
-
]);
|
|
202
|
+
const attachmentsRef = (0, react.useRef)(selectedAttachments);
|
|
203
|
+
(0, react.useLayoutEffect)(() => {
|
|
204
|
+
attachmentsRef.current = selectedAttachments;
|
|
205
|
+
});
|
|
206
|
+
const agentRef = (0, react.useRef)(agent);
|
|
207
|
+
(0, react.useLayoutEffect)(() => {
|
|
208
|
+
agentRef.current = agent;
|
|
209
|
+
});
|
|
210
|
+
const [submitter] = (0, react.useState)(() => (0, _copilotkit_core.ɵcreateChatSubmitter)({
|
|
211
|
+
core: copilotkit,
|
|
212
|
+
getAgent: () => agentRef.current,
|
|
213
|
+
input: {
|
|
214
|
+
get: () => "",
|
|
215
|
+
set: () => {}
|
|
216
|
+
},
|
|
217
|
+
attachments: {
|
|
218
|
+
isUploading: () => attachmentsRef.current.some((a) => a.status === "uploading"),
|
|
219
|
+
consumeReady: () => consumeAttachments()
|
|
220
|
+
},
|
|
221
|
+
threads
|
|
222
|
+
}));
|
|
223
|
+
(0, react.useEffect)(() => () => submitter.showNotice(null), [submitter]);
|
|
224
|
+
const submitMessage = (0, react.useCallback)((value) => submitter.submit(value), [submitter]);
|
|
261
225
|
const contextValue = {
|
|
262
226
|
agent,
|
|
263
227
|
isRunning: agent.isRunning,
|
|
@@ -268,9 +232,14 @@ function CopilotChat({ agentId, agentName, threadId, onError, throttleMs, attach
|
|
|
268
232
|
removeAttachment,
|
|
269
233
|
submitMessage
|
|
270
234
|
};
|
|
271
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
272
|
-
|
|
273
|
-
|
|
235
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_copilotkit_react_core_headless.CopilotChatConfigurationProvider, {
|
|
236
|
+
agentId: resolvedAgentId,
|
|
237
|
+
threadId: resolvedThreadId,
|
|
238
|
+
hasExplicitThreadId,
|
|
239
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopilotChatCtx.Provider, {
|
|
240
|
+
value: contextValue,
|
|
241
|
+
children
|
|
242
|
+
})
|
|
274
243
|
});
|
|
275
244
|
}
|
|
276
245
|
|
|
@@ -329,7 +298,7 @@ const CopilotSidebar = (0, react.forwardRef)(function CopilotSidebar({ agentId,
|
|
|
329
298
|
const { width: screenWidth } = (0, react_native.useWindowDimensions)();
|
|
330
299
|
const drawerWidth = resolveWidth(widthProp, screenWidth);
|
|
331
300
|
const [isOpen, setIsOpen] = (0, react.useState)(defaultOpen);
|
|
332
|
-
const slideAnim = (0, react.
|
|
301
|
+
const [slideAnim] = (0, react.useState)(() => new react_native.Animated.Value(defaultOpen ? 0 : drawerWidth));
|
|
333
302
|
(0, react.useEffect)(() => {
|
|
334
303
|
if (!isOpen) slideAnim.setValue(drawerWidth);
|
|
335
304
|
}, [
|
|
@@ -720,6 +689,7 @@ Object.defineProperty(exports, 'CopilotChatDefaultLabels', {
|
|
|
720
689
|
return _copilotkit_react_core_headless.CopilotChatDefaultLabels;
|
|
721
690
|
}
|
|
722
691
|
});
|
|
692
|
+
exports.CopilotKit = require_CopilotKitProvider.CopilotKit;
|
|
723
693
|
Object.defineProperty(exports, 'CopilotKitContext', {
|
|
724
694
|
enumerable: true,
|
|
725
695
|
get: function () {
|