@copilotkitnext/react 0.0.27 → 0.0.29

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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AssistantMessage, Message, UserMessage, ToolCall, ToolMessage, ActivityMessage } from '@ag-ui/core';
2
2
  export * from '@ag-ui/core';
3
- import { AbstractAgent, Context } from '@ag-ui/client';
3
+ import { AbstractAgent } from '@ag-ui/client';
4
4
  export * from '@ag-ui/client';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import * as React$1 from 'react';
@@ -8,8 +8,6 @@ import React__default, { ReactNode } from 'react';
8
8
  import { Streamdown } from 'streamdown';
9
9
  import { Suggestion, CopilotKitCore, ToolCallStatus, FrontendTool, DynamicSuggestionsConfig, StaticSuggestionsConfig, CopilotKitCoreConfig, CopilotKitCoreSubscriber, CopilotKitCoreSubscription } from '@copilotkitnext/core';
10
10
  import { z } from 'zod';
11
- import * as _lit_labs_react from '@lit-labs/react';
12
- import { WebInspectorElement } from '@copilotkitnext/web-inspector';
13
11
 
14
12
  declare const CopilotChatDefaultLabels: {
15
13
  chatInputPlaceholder: string;
@@ -394,12 +392,13 @@ declare namespace CopilotPopup {
394
392
 
395
393
  declare const WildcardToolCallRender: ReactToolCallRenderer<any>;
396
394
 
397
- declare const CopilotKitInspectorBase: _lit_labs_react.ReactWebComponent<WebInspectorElement, {}>;
398
- type CopilotKitInspectorBaseProps = React$1.ComponentProps<typeof CopilotKitInspectorBase>;
399
- interface CopilotKitInspectorProps extends Omit<CopilotKitInspectorBaseProps, "core"> {
395
+ type CopilotKitInspectorBaseProps = {
400
396
  core?: CopilotKitCore | null;
397
+ [key: string]: unknown;
398
+ };
399
+ interface CopilotKitInspectorProps extends CopilotKitInspectorBaseProps {
401
400
  }
402
- declare const CopilotKitInspector: React$1.ForwardRefExoticComponent<Omit<CopilotKitInspectorProps, "ref"> & React$1.RefAttributes<WebInspectorElement>>;
401
+ declare const CopilotKitInspector: React$1.FC<CopilotKitInspectorProps>;
403
402
 
404
403
  interface UseRenderToolCallProps {
405
404
  toolCall: ToolCall;
@@ -508,7 +507,23 @@ declare function useAgent({ agentId, updates }?: UseAgentProps): {
508
507
  agent: AbstractAgent;
509
508
  };
510
509
 
511
- declare function useAgentContext(context: Context): void;
510
+ /**
511
+ * Represents any value that can be serialized to JSON.
512
+ */
513
+ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | {
514
+ [key: string]: JsonSerializable;
515
+ };
516
+ /**
517
+ * Context configuration for useAgentContext.
518
+ * Accepts any JSON-serializable value which will be converted to a string.
519
+ */
520
+ interface AgentContextInput {
521
+ /** A human-readable description of what this context represents */
522
+ description: string;
523
+ /** The context value - will be converted to a JSON string if not already a string */
524
+ value: JsonSerializable;
525
+ }
526
+ declare function useAgentContext(context: AgentContextInput): void;
512
527
 
513
528
  interface UseSuggestionsOptions {
514
529
  agentId?: string;
@@ -630,4 +645,4 @@ interface CopilotKitProviderProps {
630
645
  declare const CopilotKitProvider: React__default.FC<CopilotKitProviderProps>;
631
646
  declare const useCopilotKit: () => CopilotKitContextValue;
632
647
 
633
- export { AudioRecorderError, type AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, type CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatInput, type CopilotChatInputProps, type CopilotChatLabels, CopilotChatMessageView, type CopilotChatMessageViewProps, type CopilotChatProps, CopilotChatSuggestionPill, type CopilotChatSuggestionPillProps, CopilotChatSuggestionView, type CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, type CopilotChatToggleButtonProps, CopilotChatToolCallsView, type CopilotChatToolCallsViewProps, CopilotChatUserMessage, type CopilotChatUserMessageProps, CopilotChatView, type CopilotChatViewProps, type CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type CopilotKitCoreReactSubscriber, CopilotKitInspector, type CopilotKitInspectorBaseProps, type CopilotKitInspectorProps, CopilotKitProvider, type CopilotKitProviderProps, CopilotModalHeader, type CopilotModalHeaderProps, CopilotPopup, type CopilotPopupProps, CopilotPopupView, type CopilotPopupViewProps, CopilotSidebar, type CopilotSidebarProps, CopilotSidebarView, type CopilotSidebarViewProps, type ReactActivityMessageRenderer, type ReactCustomMessageRenderer, type ReactCustomMessageRendererPosition, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type ToolsMenuItem, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderToolCall, useSuggestions };
648
+ export { type AgentContextInput, AudioRecorderError, type AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, type CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatInput, type CopilotChatInputProps, type CopilotChatLabels, CopilotChatMessageView, type CopilotChatMessageViewProps, type CopilotChatProps, CopilotChatSuggestionPill, type CopilotChatSuggestionPillProps, CopilotChatSuggestionView, type CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, type CopilotChatToggleButtonProps, CopilotChatToolCallsView, type CopilotChatToolCallsViewProps, CopilotChatUserMessage, type CopilotChatUserMessageProps, CopilotChatView, type CopilotChatViewProps, type CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type CopilotKitCoreReactSubscriber, CopilotKitInspector, type CopilotKitInspectorProps, CopilotKitProvider, type CopilotKitProviderProps, CopilotModalHeader, type CopilotModalHeaderProps, CopilotPopup, type CopilotPopupProps, CopilotPopupView, type CopilotPopupViewProps, CopilotSidebar, type CopilotSidebarProps, CopilotSidebarView, type CopilotSidebarViewProps, type JsonSerializable, type ReactActivityMessageRenderer, type ReactCustomMessageRenderer, type ReactCustomMessageRendererPosition, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type ToolsMenuItem, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderToolCall, useSuggestions };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AssistantMessage, Message, UserMessage, ToolCall, ToolMessage, ActivityMessage } from '@ag-ui/core';
2
2
  export * from '@ag-ui/core';
3
- import { AbstractAgent, Context } from '@ag-ui/client';
3
+ import { AbstractAgent } from '@ag-ui/client';
4
4
  export * from '@ag-ui/client';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import * as React$1 from 'react';
@@ -8,8 +8,6 @@ import React__default, { ReactNode } from 'react';
8
8
  import { Streamdown } from 'streamdown';
9
9
  import { Suggestion, CopilotKitCore, ToolCallStatus, FrontendTool, DynamicSuggestionsConfig, StaticSuggestionsConfig, CopilotKitCoreConfig, CopilotKitCoreSubscriber, CopilotKitCoreSubscription } from '@copilotkitnext/core';
10
10
  import { z } from 'zod';
11
- import * as _lit_labs_react from '@lit-labs/react';
12
- import { WebInspectorElement } from '@copilotkitnext/web-inspector';
13
11
 
14
12
  declare const CopilotChatDefaultLabels: {
15
13
  chatInputPlaceholder: string;
@@ -394,12 +392,13 @@ declare namespace CopilotPopup {
394
392
 
395
393
  declare const WildcardToolCallRender: ReactToolCallRenderer<any>;
396
394
 
397
- declare const CopilotKitInspectorBase: _lit_labs_react.ReactWebComponent<WebInspectorElement, {}>;
398
- type CopilotKitInspectorBaseProps = React$1.ComponentProps<typeof CopilotKitInspectorBase>;
399
- interface CopilotKitInspectorProps extends Omit<CopilotKitInspectorBaseProps, "core"> {
395
+ type CopilotKitInspectorBaseProps = {
400
396
  core?: CopilotKitCore | null;
397
+ [key: string]: unknown;
398
+ };
399
+ interface CopilotKitInspectorProps extends CopilotKitInspectorBaseProps {
401
400
  }
402
- declare const CopilotKitInspector: React$1.ForwardRefExoticComponent<Omit<CopilotKitInspectorProps, "ref"> & React$1.RefAttributes<WebInspectorElement>>;
401
+ declare const CopilotKitInspector: React$1.FC<CopilotKitInspectorProps>;
403
402
 
404
403
  interface UseRenderToolCallProps {
405
404
  toolCall: ToolCall;
@@ -508,7 +507,23 @@ declare function useAgent({ agentId, updates }?: UseAgentProps): {
508
507
  agent: AbstractAgent;
509
508
  };
510
509
 
511
- declare function useAgentContext(context: Context): void;
510
+ /**
511
+ * Represents any value that can be serialized to JSON.
512
+ */
513
+ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | {
514
+ [key: string]: JsonSerializable;
515
+ };
516
+ /**
517
+ * Context configuration for useAgentContext.
518
+ * Accepts any JSON-serializable value which will be converted to a string.
519
+ */
520
+ interface AgentContextInput {
521
+ /** A human-readable description of what this context represents */
522
+ description: string;
523
+ /** The context value - will be converted to a JSON string if not already a string */
524
+ value: JsonSerializable;
525
+ }
526
+ declare function useAgentContext(context: AgentContextInput): void;
512
527
 
513
528
  interface UseSuggestionsOptions {
514
529
  agentId?: string;
@@ -630,4 +645,4 @@ interface CopilotKitProviderProps {
630
645
  declare const CopilotKitProvider: React__default.FC<CopilotKitProviderProps>;
631
646
  declare const useCopilotKit: () => CopilotKitContextValue;
632
647
 
633
- export { AudioRecorderError, type AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, type CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatInput, type CopilotChatInputProps, type CopilotChatLabels, CopilotChatMessageView, type CopilotChatMessageViewProps, type CopilotChatProps, CopilotChatSuggestionPill, type CopilotChatSuggestionPillProps, CopilotChatSuggestionView, type CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, type CopilotChatToggleButtonProps, CopilotChatToolCallsView, type CopilotChatToolCallsViewProps, CopilotChatUserMessage, type CopilotChatUserMessageProps, CopilotChatView, type CopilotChatViewProps, type CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type CopilotKitCoreReactSubscriber, CopilotKitInspector, type CopilotKitInspectorBaseProps, type CopilotKitInspectorProps, CopilotKitProvider, type CopilotKitProviderProps, CopilotModalHeader, type CopilotModalHeaderProps, CopilotPopup, type CopilotPopupProps, CopilotPopupView, type CopilotPopupViewProps, CopilotSidebar, type CopilotSidebarProps, CopilotSidebarView, type CopilotSidebarViewProps, type ReactActivityMessageRenderer, type ReactCustomMessageRenderer, type ReactCustomMessageRendererPosition, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type ToolsMenuItem, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderToolCall, useSuggestions };
648
+ export { type AgentContextInput, AudioRecorderError, type AudioRecorderState, CopilotChat, CopilotChatAssistantMessage, type CopilotChatAssistantMessageProps, CopilotChatAudioRecorder, CopilotChatConfigurationProvider, type CopilotChatConfigurationProviderProps, type CopilotChatConfigurationValue, CopilotChatInput, type CopilotChatInputProps, type CopilotChatLabels, CopilotChatMessageView, type CopilotChatMessageViewProps, type CopilotChatProps, CopilotChatSuggestionPill, type CopilotChatSuggestionPillProps, CopilotChatSuggestionView, type CopilotChatSuggestionViewProps, CopilotChatToggleButton, DefaultCloseIcon as CopilotChatToggleButtonCloseIcon, DefaultOpenIcon as CopilotChatToggleButtonOpenIcon, type CopilotChatToggleButtonProps, CopilotChatToolCallsView, type CopilotChatToolCallsViewProps, CopilotChatUserMessage, type CopilotChatUserMessageProps, CopilotChatView, type CopilotChatViewProps, type CopilotKitContextValue, CopilotKitCoreReact, type CopilotKitCoreReactConfig, type CopilotKitCoreReactSubscriber, CopilotKitInspector, type CopilotKitInspectorProps, CopilotKitProvider, type CopilotKitProviderProps, CopilotModalHeader, type CopilotModalHeaderProps, CopilotPopup, type CopilotPopupProps, CopilotPopupView, type CopilotPopupViewProps, CopilotSidebar, type CopilotSidebarProps, CopilotSidebarView, type CopilotSidebarViewProps, type JsonSerializable, type ReactActivityMessageRenderer, type ReactCustomMessageRenderer, type ReactCustomMessageRendererPosition, type ReactFrontendTool, type ReactHumanInTheLoop, type ReactToolCallRenderer, type ToolsMenuItem, WildcardToolCallRender, defineToolCallRenderer, useAgent, useAgentContext, useConfigureSuggestions, useCopilotChatConfiguration, useCopilotKit, useFrontendTool, useHumanInTheLoop, useRenderActivityMessage, useRenderCustomMessages, useRenderToolCall, useSuggestions };
package/dist/index.js CHANGED
@@ -1483,32 +1483,23 @@ var CopilotKitCoreReact = class extends import_core.CopilotKitCore {
1483
1483
  // src/components/CopilotKitInspector.tsx
1484
1484
  var React4 = __toESM(require("react"));
1485
1485
  var import_react5 = require("@lit-labs/react");
1486
- var import_web_inspector = require("@copilotkitnext/web-inspector");
1487
1486
  var import_jsx_runtime7 = require("react/jsx-runtime");
1488
- (0, import_web_inspector.defineWebInspector)();
1489
- var CopilotKitInspectorBase = (0, import_react5.createComponent)({
1490
- tagName: import_web_inspector.WEB_INSPECTOR_TAG,
1491
- elementClass: import_web_inspector.WebInspectorElement,
1492
- react: React4
1493
- });
1494
- var CopilotKitInspector = React4.forwardRef(
1495
- ({ core, ...rest }, ref) => {
1496
- const innerRef = React4.useRef(null);
1497
- React4.useImperativeHandle(ref, () => innerRef.current, []);
1498
- React4.useEffect(() => {
1499
- if (innerRef.current) {
1500
- innerRef.current.core = core ?? null;
1501
- }
1502
- }, [core]);
1503
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1504
- CopilotKitInspectorBase,
1505
- {
1506
- ...rest,
1507
- ref: innerRef
1508
- }
1509
- );
1487
+ var CopilotKitInspectorBase = React4.lazy(() => {
1488
+ if (typeof window === "undefined") {
1489
+ const NullComponent = () => null;
1490
+ return Promise.resolve({ default: NullComponent });
1510
1491
  }
1511
- );
1492
+ return import("@copilotkitnext/web-inspector").then((mod) => {
1493
+ mod.defineWebInspector?.();
1494
+ const Component = (0, import_react5.createComponent)({
1495
+ tagName: mod.WEB_INSPECTOR_TAG,
1496
+ elementClass: mod.WebInspectorElement,
1497
+ react: React4
1498
+ });
1499
+ return { default: Component };
1500
+ });
1501
+ });
1502
+ var CopilotKitInspector = ({ core, ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(React4.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotKitInspectorBase, { ...rest, core: core ?? null }) });
1512
1503
  CopilotKitInspector.displayName = "CopilotKitInspector";
1513
1504
 
1514
1505
  // src/providers/CopilotKitProvider.tsx
@@ -2124,13 +2115,19 @@ var import_react13 = require("react");
2124
2115
  function useAgentContext(context) {
2125
2116
  const { description, value } = context;
2126
2117
  const { copilotkit } = useCopilotKit();
2118
+ const stringValue = (0, import_react13.useMemo)(() => {
2119
+ if (typeof value === "string") {
2120
+ return value;
2121
+ }
2122
+ return JSON.stringify(value);
2123
+ }, [value]);
2127
2124
  (0, import_react13.useEffect)(() => {
2128
2125
  if (!copilotkit) return;
2129
- const id = copilotkit.addContext(context);
2126
+ const id = copilotkit.addContext({ description, value: stringValue });
2130
2127
  return () => {
2131
2128
  copilotkit.removeContext(id);
2132
2129
  };
2133
- }, [description, value, copilotkit]);
2130
+ }, [description, stringValue, copilotkit]);
2134
2131
  }
2135
2132
 
2136
2133
  // src/hooks/use-suggestions.tsx