@copilotkit/react-native 1.63.2 → 1.63.3-canary.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.
- package/USAGE.md +30 -0
- package/dist/{RenderToolContext-CszHyes6.mjs → RenderToolContext-D8M-JhD1.mjs} +1 -1
- package/dist/{RenderToolContext-CszHyes6.mjs.map → RenderToolContext-D8M-JhD1.mjs.map} +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/headless.cjs +100 -0
- package/dist/headless.d.cts +6 -0
- package/dist/headless.d.mts +6 -0
- package/dist/headless.mjs +6 -0
- package/dist/index.cjs +3 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -163
- package/dist/index.d.mts +5 -163
- package/dist/index.mjs +7 -161
- package/dist/index.mjs.map +1 -1
- package/dist/polyfills.cjs +2 -204
- package/dist/polyfills.cjs.map +1 -1
- package/dist/polyfills.mjs +1 -202
- package/dist/polyfills.mjs.map +1 -1
- package/dist/streaming-fetch-BTESzLKX.cjs +211 -0
- package/dist/streaming-fetch-BTESzLKX.cjs.map +1 -0
- package/dist/streaming-fetch-BnQh3vBz.mjs +205 -0
- package/dist/streaming-fetch-BnQh3vBz.mjs.map +1 -0
- package/dist/useRenderTool-9YDIfZ0D.d.mts +164 -0
- package/dist/useRenderTool-BugVTDoM.d.cts +164 -0
- package/dist/useRenderTool-DLavcsVB.cjs +176 -0
- package/dist/useRenderTool-DLavcsVB.cjs.map +1 -0
- package/dist/useRenderTool-DUqpS97B.mjs +164 -0
- package/dist/useRenderTool-DUqpS97B.mjs.map +1 -0
- package/package.json +9 -4
- package/src/__tests__/headless-entry-surface.test.ts +151 -0
- package/src/headless.ts +110 -0
- package/src/index.ts +19 -89
- package/tsdown.config.ts +1 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,73 +1,11 @@
|
|
|
1
|
+
import { a as useRenderToolRegistry, i as RenderToolProvider, n as useRenderTool, o as CopilotKitNativeProviderProps, r as RenderToolProps, s as CopilotKitProvider, t as UseRenderToolOptions } from "./useRenderTool-9YDIfZ0D.mjs";
|
|
2
|
+
import { AbstractAgent, AgentCapabilities, AgentContextInput, AssistantMessageType, CopilotChatConfigurationValue, CopilotChatDefaultLabels, CopilotChatLabels, CopilotKitContext, CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, FrontendTool, Interrupt, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, Message, ReactFrontendTool, ReactHumanInTheLoop, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, ResumeEntry, ResumeStatus, Suggestion, Thread, ToolCall, ToolCallStatus, ToolMessage, UseAgentUpdate, UseInterruptConfig, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads } from "./headless.mjs";
|
|
1
3
|
import React, { ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { AgentContextInput, CopilotChatConfigurationValue, CopilotChatDefaultLabels, CopilotChatLabels, Interrupt, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, ReactFrontendTool, ReactHumanInTheLoop, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, ResumeEntry, ResumeStatus, Thread, UseAgentUpdate, UseInterruptConfig, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useFrontendTool, useHumanInTheLoop, useInterrupt, useSuggestions, useThreads } from "@copilotkit/react-core/v2/headless";
|
|
4
|
-
import { Attachment, AttachmentUploadErrorReason, AttachmentUploadResult, DebugConfig, StandardSchemaV1 } from "@copilotkit/shared";
|
|
4
|
+
import { Attachment, AttachmentUploadErrorReason, AttachmentUploadResult } from "@copilotkit/shared";
|
|
5
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
6
|
import { ViewStyle } from "react-native";
|
|
7
|
-
import { CopilotKitCoreErrorCode
|
|
8
|
-
import { AbstractAgent, AgentCapabilities, AssistantMessage as AssistantMessageType, Message, ToolCall, ToolMessage } from "@ag-ui/client";
|
|
7
|
+
import { CopilotKitCoreErrorCode as CopilotKitCoreErrorCode$1 } from "@copilotkit/core";
|
|
9
8
|
|
|
10
|
-
//#region src/CopilotKitProvider.d.ts
|
|
11
|
-
interface CopilotKitNativeProviderProps {
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
/** URL of the CopilotKit runtime endpoint */
|
|
14
|
-
runtimeUrl: string;
|
|
15
|
-
/** Custom headers sent with every request */
|
|
16
|
-
headers?: Record<string, string> | (() => Record<string, string>);
|
|
17
|
-
/**
|
|
18
|
-
* Credentials mode for fetch requests (e.g., "include" for HTTP-only cookies in cross-origin requests).
|
|
19
|
-
*/
|
|
20
|
-
credentials?: RequestCredentials;
|
|
21
|
-
/** Whether the runtime uses a single-route endpoint */
|
|
22
|
-
useSingleEndpoint?: boolean;
|
|
23
|
-
/** Custom properties forwarded to agents */
|
|
24
|
-
properties?: Record<string, unknown>;
|
|
25
|
-
/**
|
|
26
|
-
* Error handler called when CopilotKit encounters an error.
|
|
27
|
-
* Fires for all error types (runtime connection failures, agent errors, tool errors).
|
|
28
|
-
* If not provided, errors are logged to console.error.
|
|
29
|
-
*/
|
|
30
|
-
onError?: (event: {
|
|
31
|
-
error: Error;
|
|
32
|
-
code: CopilotKitCoreErrorCode$1;
|
|
33
|
-
context: Record<string, any>;
|
|
34
|
-
}) => void | Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Enable debug logging for the client-side event pipeline.
|
|
37
|
-
* When `true`, enables verbose logging from the core instance.
|
|
38
|
-
*/
|
|
39
|
-
debug?: DebugConfig;
|
|
40
|
-
/**
|
|
41
|
-
* Default throttle interval (ms) for `onMessagesChanged` / `onStateChanged`
|
|
42
|
-
* subscriptions. Individual subscriptions can override with their own `throttleMs`.
|
|
43
|
-
*/
|
|
44
|
-
defaultThrottleMs?: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* CopilotKit provider for React Native.
|
|
48
|
-
*
|
|
49
|
-
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
50
|
-
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
51
|
-
*
|
|
52
|
-
* Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
|
|
53
|
-
* so a separate `import "@copilotkit/react-native/polyfills"` is no longer
|
|
54
|
-
* required (though it remains available for advanced use).
|
|
55
|
-
*
|
|
56
|
-
* Usage:
|
|
57
|
-
* ```tsx
|
|
58
|
-
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
59
|
-
*
|
|
60
|
-
* function App() {
|
|
61
|
-
* return (
|
|
62
|
-
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
63
|
-
* <ChatScreen />
|
|
64
|
-
* </CopilotKitProvider>
|
|
65
|
-
* );
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
declare const CopilotKitProvider: React.FC<CopilotKitNativeProviderProps>;
|
|
70
|
-
//#endregion
|
|
71
9
|
//#region src/hooks/use-attachments.d.ts
|
|
72
10
|
/**
|
|
73
11
|
* Platform-neutral file descriptor for React Native.
|
|
@@ -437,101 +375,5 @@ interface CopilotPopupHandle {
|
|
|
437
375
|
*/
|
|
438
376
|
declare const CopilotPopup: React.ForwardRefExoticComponent<CopilotPopupProps & React.RefAttributes<CopilotPopupHandle>>;
|
|
439
377
|
//#endregion
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Props passed to a render tool function.
|
|
443
|
-
*/
|
|
444
|
-
interface RenderToolProps<T = Record<string, unknown>> {
|
|
445
|
-
args: T;
|
|
446
|
-
status: "executing" | "complete";
|
|
447
|
-
result?: string;
|
|
448
|
-
}
|
|
449
|
-
/**
|
|
450
|
-
* A render function that returns a React Native element for a tool call.
|
|
451
|
-
* Returns `ReactElement | null` (not ReactNode) because React Native's
|
|
452
|
-
* FlatList cannot render strings or portals.
|
|
453
|
-
*/
|
|
454
|
-
type RenderToolFunction<T = Record<string, unknown>> = (props: RenderToolProps<T>) => React.ReactElement | null;
|
|
455
|
-
/**
|
|
456
|
-
* The registry maps tool names to their render functions.
|
|
457
|
-
*/
|
|
458
|
-
type RenderToolRegistry = Map<string, RenderToolFunction>;
|
|
459
|
-
/**
|
|
460
|
-
* Provider that maintains the render tool registry.
|
|
461
|
-
* Should be nested inside CopilotKitProvider.
|
|
462
|
-
*/
|
|
463
|
-
declare function RenderToolProvider({
|
|
464
|
-
children
|
|
465
|
-
}: {
|
|
466
|
-
children: React.ReactNode;
|
|
467
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
468
|
-
/**
|
|
469
|
-
* Returns the current render tool registry (a Map of tool name to render function).
|
|
470
|
-
* Re-renders when the registry changes.
|
|
471
|
-
*
|
|
472
|
-
* @throws if called outside of RenderToolProvider
|
|
473
|
-
*/
|
|
474
|
-
declare function useRenderToolRegistry(): RenderToolRegistry;
|
|
475
|
-
//#endregion
|
|
476
|
-
//#region src/hooks/useRenderTool.d.ts
|
|
477
|
-
/**
|
|
478
|
-
* Options for the useRenderTool hook.
|
|
479
|
-
*/
|
|
480
|
-
interface UseRenderToolOptions<T extends Record<string, unknown>> {
|
|
481
|
-
/** Unique name for the tool. Must match what the agent calls. */
|
|
482
|
-
name: string;
|
|
483
|
-
/** Human-readable description shown to the agent. */
|
|
484
|
-
description: string;
|
|
485
|
-
/**
|
|
486
|
-
* Schema describing the tool's parameters.
|
|
487
|
-
* Accepts any StandardSchemaV1-compatible schema (Zod, Valibot, ArkType, etc.).
|
|
488
|
-
*/
|
|
489
|
-
parameters: StandardSchemaV1<unknown, T>;
|
|
490
|
-
/**
|
|
491
|
-
* Render function that returns a React Native element for the tool call.
|
|
492
|
-
* Called by CopilotChat when it encounters a tool call message for this tool.
|
|
493
|
-
*
|
|
494
|
-
* Returns ReactElement | null (not ReactNode) because React Native's
|
|
495
|
-
* FlatList cannot render strings or portals.
|
|
496
|
-
*/
|
|
497
|
-
render: RenderToolFunction<T>;
|
|
498
|
-
/**
|
|
499
|
-
* Optional handler executed when the tool is called.
|
|
500
|
-
* If omitted, the tool is render-only (the render function shows UI
|
|
501
|
-
* but the tool returns no result to the agent).
|
|
502
|
-
*/
|
|
503
|
-
handler?: (args: T) => Promise<unknown>;
|
|
504
|
-
/**
|
|
505
|
-
* Optional agent ID to scope this tool to a specific agent.
|
|
506
|
-
*/
|
|
507
|
-
agentId?: string;
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Hook that registers a frontend tool AND a render function for it.
|
|
511
|
-
*
|
|
512
|
-
* This bridges `useFrontendTool` (which handles tool registration and
|
|
513
|
-
* handler execution) with a render registry so that CopilotChat can
|
|
514
|
-
* render React Native elements inline when it encounters tool call messages.
|
|
515
|
-
*
|
|
516
|
-
* @example
|
|
517
|
-
* ```tsx
|
|
518
|
-
* useRenderTool({
|
|
519
|
-
* name: "showWeather",
|
|
520
|
-
* description: "Display weather information",
|
|
521
|
-
* parameters: z.object({ city: z.string(), temp: z.number() }),
|
|
522
|
-
* render: ({ args, status }) => (
|
|
523
|
-
* <View>
|
|
524
|
-
* <Text>{args.city}: {args.temp}</Text>
|
|
525
|
-
* {status === "executing" && <ActivityIndicator />}
|
|
526
|
-
* </View>
|
|
527
|
-
* ),
|
|
528
|
-
* handler: async ({ city }) => {
|
|
529
|
-
* return { forecast: "sunny" };
|
|
530
|
-
* },
|
|
531
|
-
* });
|
|
532
|
-
* ```
|
|
533
|
-
*/
|
|
534
|
-
declare function useRenderTool<T extends Record<string, unknown> = Record<string, unknown>>(options: UseRenderToolOptions<T>, deps?: ReadonlyArray<unknown>): void;
|
|
535
|
-
//#endregion
|
|
536
|
-
export { type AbstractAgent, type AgentCapabilities, type AgentContextInput, type AssistantMessageType, CopilotChat, type CopilotChatConfigurationValue, type CopilotChatContextValue, CopilotChatDefaultLabels, type CopilotChatLabels, type CopilotChatProps, CopilotKitContext, type CopilotKitContextValue, type CopilotKitCoreErrorCode, type CopilotKitCoreRuntimeConnectionStatus, type CopilotKitNativeProviderProps, type CopilotKitNativeProviderProps as CopilotKitProviderProps, CopilotKitProvider, CopilotModal, type CopilotModalProps, CopilotPopup, type CopilotPopupHandle, type CopilotPopupProps, CopilotSidebar, type CopilotSidebarHandle, type CopilotSidebarProps, type FrontendTool, type Interrupt, type InterruptEvent, type InterruptHandlerProps, type InterruptRenderProps, type JsonSerializable, type Message, type NativeAttachmentsConfig, type NativeFileInput, type ReactFrontendTool, type ReactHumanInTheLoop, type RenderToolCompleteProps, type RenderToolExecutingProps, type RenderToolInProgressProps, type RenderToolProps, RenderToolProvider, type ResumeEntry, type ResumeStatus, type Suggestion, type Thread, type ToolCall, type ToolCallStatus, type ToolMessage, type UseAgentUpdate, type UseInterruptConfig, type UseNativeAttachmentsProps, type UseNativeAttachmentsReturn, type UseRenderToolOptions, type UseThreadsInput, type UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useAttachments, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatContext, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolRegistry, useSuggestions, useThreads };
|
|
378
|
+
export { AbstractAgent, AgentCapabilities, AgentContextInput, AssistantMessageType, CopilotChat, CopilotChatConfigurationValue, type CopilotChatContextValue, CopilotChatDefaultLabels, CopilotChatLabels, type CopilotChatProps, CopilotKitContext, CopilotKitContextValue, CopilotKitCoreErrorCode, CopilotKitCoreRuntimeConnectionStatus, CopilotKitNativeProviderProps, CopilotKitNativeProviderProps as CopilotKitProviderProps, CopilotKitProvider, CopilotModal, type CopilotModalProps, CopilotPopup, type CopilotPopupHandle, type CopilotPopupProps, CopilotSidebar, type CopilotSidebarHandle, type CopilotSidebarProps, FrontendTool, Interrupt, InterruptEvent, InterruptHandlerProps, InterruptRenderProps, JsonSerializable, Message, type NativeAttachmentsConfig, type NativeFileInput, ReactFrontendTool, ReactHumanInTheLoop, RenderToolCompleteProps, RenderToolExecutingProps, RenderToolInProgressProps, RenderToolProps, RenderToolProvider, ResumeEntry, ResumeStatus, Suggestion, Thread, ToolCall, ToolCallStatus, ToolMessage, UseAgentUpdate, UseInterruptConfig, type UseNativeAttachmentsProps, type UseNativeAttachmentsReturn, UseRenderToolOptions, UseThreadsInput, UseThreadsResult, defineToolCallRenderer, useAgent, useAgentContext, useAttachments, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatContext, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolRegistry, useSuggestions, useThreads };
|
|
537
379
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,124 +1,15 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import { n as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { r as useRenderToolRegistry, t as RenderToolProvider } from "./RenderToolContext-D8M-JhD1.mjs";
|
|
2
|
+
import { n as CopilotKitProvider, t as useRenderTool } from "./useRenderTool-DUqpS97B.mjs";
|
|
3
|
+
import { CopilotChatDefaultLabels, CopilotKitContext, defineToolCallRenderer, useAgent, useAgentContext, useCapabilities, useComponent, useConfigureSuggestions, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useSuggestions, useThreads } from "./headless.mjs";
|
|
4
|
+
import React, { createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
5
|
+
import { useCopilotKit as useCopilotKit$1 } from "@copilotkit/react-core/v2/context";
|
|
6
|
+
import { useAgent as useAgent$1 } from "@copilotkit/react-core/v2/headless";
|
|
7
|
+
import { DEFAULT_AGENT_ID, formatFileSize, getModalityFromMimeType, randomUUID } from "@copilotkit/shared";
|
|
7
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import * as DocumentPicker from "expo-document-picker";
|
|
9
10
|
import * as FileSystem from "expo-file-system";
|
|
10
11
|
import { Animated, Modal, Pressable, StyleSheet, Text, TouchableOpacity, View, useWindowDimensions } from "react-native";
|
|
11
12
|
|
|
12
|
-
//#region src/CopilotKitProvider.tsx
|
|
13
|
-
/**
|
|
14
|
-
* CopilotKit provider for React Native.
|
|
15
|
-
*
|
|
16
|
-
* A lightweight alternative to the web CopilotKitProvider that avoids
|
|
17
|
-
* web-only dependencies (DOM, CSS, Radix UI, Lit, etc).
|
|
18
|
-
*
|
|
19
|
-
* Polyfills are auto-imported when `@copilotkit/react-native` is loaded,
|
|
20
|
-
* so a separate `import "@copilotkit/react-native/polyfills"` is no longer
|
|
21
|
-
* required (though it remains available for advanced use).
|
|
22
|
-
*
|
|
23
|
-
* Usage:
|
|
24
|
-
* ```tsx
|
|
25
|
-
* import { CopilotKitProvider } from "@copilotkit/react-native";
|
|
26
|
-
*
|
|
27
|
-
* function App() {
|
|
28
|
-
* return (
|
|
29
|
-
* <CopilotKitProvider runtimeUrl="https://your-runtime/api/copilotkit">
|
|
30
|
-
* <ChatScreen />
|
|
31
|
-
* </CopilotKitProvider>
|
|
32
|
-
* );
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp, credentials, useSingleEndpoint, properties, onError, debug, defaultThrottleMs }) => {
|
|
37
|
-
const resolvedHeaders = typeof headersProp === "function" ? headersProp() : headersProp;
|
|
38
|
-
const stableHeaders = useMemo(() => resolvedHeaders ?? {}, [JSON.stringify(resolvedHeaders)]);
|
|
39
|
-
const stableProperties = useMemo(() => properties ?? {}, [JSON.stringify(properties)]);
|
|
40
|
-
const copilotkitRef = useRef(null);
|
|
41
|
-
if (copilotkitRef.current === null) {
|
|
42
|
-
const instance = new CopilotKitCoreReact({
|
|
43
|
-
runtimeUrl,
|
|
44
|
-
runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
|
|
45
|
-
headers: stableHeaders,
|
|
46
|
-
credentials,
|
|
47
|
-
properties: stableProperties,
|
|
48
|
-
debug
|
|
49
|
-
});
|
|
50
|
-
if (defaultThrottleMs !== void 0) instance.setDefaultThrottleMs(defaultThrottleMs);
|
|
51
|
-
copilotkitRef.current = instance;
|
|
52
|
-
}
|
|
53
|
-
const copilotkit = copilotkitRef.current;
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
56
|
-
copilotkit.setRuntimeTransport(useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto");
|
|
57
|
-
copilotkit.setHeaders(stableHeaders);
|
|
58
|
-
copilotkit.setCredentials(credentials);
|
|
59
|
-
copilotkit.setProperties(stableProperties);
|
|
60
|
-
copilotkit.setDebug(debug);
|
|
61
|
-
}, [
|
|
62
|
-
runtimeUrl,
|
|
63
|
-
useSingleEndpoint,
|
|
64
|
-
stableHeaders,
|
|
65
|
-
credentials,
|
|
66
|
-
stableProperties,
|
|
67
|
-
debug,
|
|
68
|
-
copilotkit
|
|
69
|
-
]);
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
copilotkit.setDefaultThrottleMs(defaultThrottleMs);
|
|
72
|
-
}, [copilotkit, defaultThrottleMs]);
|
|
73
|
-
const [executingToolCallIds, setExecutingToolCallIds] = useState(() => /* @__PURE__ */ new Set());
|
|
74
|
-
const [runtimeLicenseStatus, setRuntimeLicenseStatus] = useState(void 0);
|
|
75
|
-
const onErrorRef = useRef(onError);
|
|
76
|
-
useEffect(() => {
|
|
77
|
-
onErrorRef.current = onError;
|
|
78
|
-
}, [onError]);
|
|
79
|
-
useEffect(() => {
|
|
80
|
-
const subscription = copilotkit.subscribe({
|
|
81
|
-
onToolExecutionStart: ({ toolCallId }) => {
|
|
82
|
-
setExecutingToolCallIds((prev) => {
|
|
83
|
-
if (prev.has(toolCallId)) return prev;
|
|
84
|
-
const next = new Set(prev);
|
|
85
|
-
next.add(toolCallId);
|
|
86
|
-
return next;
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
onToolExecutionEnd: ({ toolCallId }) => {
|
|
90
|
-
setExecutingToolCallIds((prev) => {
|
|
91
|
-
if (!prev.has(toolCallId)) return prev;
|
|
92
|
-
const next = new Set(prev);
|
|
93
|
-
next.delete(toolCallId);
|
|
94
|
-
return next;
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
onError: (event) => {
|
|
98
|
-
if (onErrorRef.current) onErrorRef.current(event);
|
|
99
|
-
else console.error(`[CopilotKit] Error (${event.code}):`, event.error, event.context ?? {});
|
|
100
|
-
},
|
|
101
|
-
onRuntimeConnectionStatusChanged: () => {
|
|
102
|
-
setRuntimeLicenseStatus(copilotkit.licenseStatus);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return () => subscription.unsubscribe();
|
|
106
|
-
}, [copilotkit]);
|
|
107
|
-
const contextValue = useMemo(() => ({
|
|
108
|
-
copilotkit,
|
|
109
|
-
executingToolCallIds
|
|
110
|
-
}), [copilotkit, executingToolCallIds]);
|
|
111
|
-
const licenseContextValue = useMemo(() => createLicenseContextValue(runtimeLicenseStatus), [runtimeLicenseStatus]);
|
|
112
|
-
return /* @__PURE__ */ jsx(CopilotKitContext$1.Provider, {
|
|
113
|
-
value: contextValue,
|
|
114
|
-
children: /* @__PURE__ */ jsx(LicenseContext.Provider, {
|
|
115
|
-
value: licenseContextValue,
|
|
116
|
-
children: /* @__PURE__ */ jsx(RenderToolProvider, { children })
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
13
|
//#region src/hooks/use-attachments.ts
|
|
123
14
|
const DEFAULT_MAX_SIZE = 20 * 1024 * 1024;
|
|
124
15
|
/**
|
|
@@ -808,51 +699,6 @@ const styles = StyleSheet.create({
|
|
|
808
699
|
chatContainer: { flex: 1 }
|
|
809
700
|
});
|
|
810
701
|
|
|
811
|
-
//#endregion
|
|
812
|
-
//#region src/hooks/useRenderTool.ts
|
|
813
|
-
/**
|
|
814
|
-
* Hook that registers a frontend tool AND a render function for it.
|
|
815
|
-
*
|
|
816
|
-
* This bridges `useFrontendTool` (which handles tool registration and
|
|
817
|
-
* handler execution) with a render registry so that CopilotChat can
|
|
818
|
-
* render React Native elements inline when it encounters tool call messages.
|
|
819
|
-
*
|
|
820
|
-
* @example
|
|
821
|
-
* ```tsx
|
|
822
|
-
* useRenderTool({
|
|
823
|
-
* name: "showWeather",
|
|
824
|
-
* description: "Display weather information",
|
|
825
|
-
* parameters: z.object({ city: z.string(), temp: z.number() }),
|
|
826
|
-
* render: ({ args, status }) => (
|
|
827
|
-
* <View>
|
|
828
|
-
* <Text>{args.city}: {args.temp}</Text>
|
|
829
|
-
* {status === "executing" && <ActivityIndicator />}
|
|
830
|
-
* </View>
|
|
831
|
-
* ),
|
|
832
|
-
* handler: async ({ city }) => {
|
|
833
|
-
* return { forecast: "sunny" };
|
|
834
|
-
* },
|
|
835
|
-
* });
|
|
836
|
-
* ```
|
|
837
|
-
*/
|
|
838
|
-
function useRenderTool(options, deps) {
|
|
839
|
-
const { name, description, parameters, render, handler, agentId } = options;
|
|
840
|
-
const { register } = useRenderToolContext();
|
|
841
|
-
useFrontendTool$1({
|
|
842
|
-
name,
|
|
843
|
-
description,
|
|
844
|
-
parameters,
|
|
845
|
-
handler,
|
|
846
|
-
agentId
|
|
847
|
-
}, deps);
|
|
848
|
-
const renderRef = useRef(render);
|
|
849
|
-
renderRef.current = render;
|
|
850
|
-
useEffect(() => {
|
|
851
|
-
const stableRender = (props) => renderRef.current(props);
|
|
852
|
-
return register(name, stableRender);
|
|
853
|
-
}, [name, register]);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
702
|
//#endregion
|
|
857
703
|
export { CopilotChat, CopilotChatDefaultLabels, CopilotKitContext, CopilotKitProvider, CopilotModal, CopilotPopup, CopilotSidebar, RenderToolProvider, defineToolCallRenderer, useAgent, useAgentContext, useAttachments, useCapabilities, useComponent, useConfigureSuggestions, useCopilotChatContext, useCopilotKit, useFrontendTool, useHumanInTheLoop, useInterrupt, useLicenseContext, useRenderTool, useRenderToolRegistry, useSuggestions, useThreads };
|
|
858
704
|
//# sourceMappingURL=index.mjs.map
|