@copilotkit/react-core 1.51.3-next.2 → 1.51.3-next.4

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 (63) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{chunk-OBXQSB7S.mjs → chunk-37JRY3TC.mjs} +2 -2
  3. package/dist/{chunk-QNUAXSDP.mjs → chunk-3X3I7OJV.mjs} +12 -6
  4. package/dist/chunk-3X3I7OJV.mjs.map +1 -0
  5. package/dist/{chunk-W5BKJN46.mjs → chunk-AR533FGY.mjs} +2 -2
  6. package/dist/{chunk-4MLKBZGB.mjs → chunk-K2GJI3PT.mjs} +2 -2
  7. package/dist/{chunk-F555TVE4.mjs → chunk-LMHB2D4J.mjs} +3 -3
  8. package/dist/chunk-LMHB2D4J.mjs.map +1 -0
  9. package/dist/{chunk-M7U7RZLU.mjs → chunk-LWJIFZWN.mjs} +2 -2
  10. package/dist/{chunk-2VA5EV2P.mjs → chunk-THCOOWDH.mjs} +3 -3
  11. package/dist/components/copilot-provider/copilotkit.js +13 -7
  12. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  13. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  14. package/dist/components/copilot-provider/index.js +13 -7
  15. package/dist/components/copilot-provider/index.js.map +1 -1
  16. package/dist/components/copilot-provider/index.mjs +3 -3
  17. package/dist/components/index.js +13 -7
  18. package/dist/components/index.js.map +1 -1
  19. package/dist/components/index.mjs +3 -3
  20. package/dist/context/index.js +2 -2
  21. package/dist/context/index.js.map +1 -1
  22. package/dist/context/index.mjs +1 -1
  23. package/dist/context/threads-context.js +2 -2
  24. package/dist/context/threads-context.js.map +1 -1
  25. package/dist/context/threads-context.mjs +1 -1
  26. package/dist/hooks/index.js +11 -5
  27. package/dist/hooks/index.js.map +1 -1
  28. package/dist/hooks/index.mjs +5 -5
  29. package/dist/hooks/use-coagent-state-render-bridge.js +11 -5
  30. package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
  31. package/dist/hooks/use-coagent-state-render-bridge.mjs +2 -2
  32. package/dist/hooks/use-copilot-chat-headless_c.js +11 -5
  33. package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
  34. package/dist/hooks/use-copilot-chat-headless_c.mjs +4 -4
  35. package/dist/hooks/use-copilot-chat.js +11 -5
  36. package/dist/hooks/use-copilot-chat.js.map +1 -1
  37. package/dist/hooks/use-copilot-chat.mjs +4 -4
  38. package/dist/hooks/use-copilot-chat_internal.js +11 -5
  39. package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
  40. package/dist/hooks/use-copilot-chat_internal.mjs +3 -3
  41. package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
  42. package/dist/index.js +13 -7
  43. package/dist/index.js.map +1 -1
  44. package/dist/index.mjs +7 -7
  45. package/dist/lib/copilot-task.mjs +4 -4
  46. package/dist/lib/index.mjs +4 -4
  47. package/dist/setupTests.js +3 -1
  48. package/dist/setupTests.js.map +1 -1
  49. package/dist/setupTests.mjs +3 -1
  50. package/dist/setupTests.mjs.map +1 -1
  51. package/package.json +6 -6
  52. package/src/context/__tests__/threads-context.test.tsx +28 -0
  53. package/src/context/threads-context.tsx +2 -2
  54. package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +229 -0
  55. package/src/hooks/use-coagent-state-render-bridge.tsx +15 -5
  56. package/src/setupTests.ts +2 -0
  57. package/dist/chunk-F555TVE4.mjs.map +0 -1
  58. package/dist/chunk-QNUAXSDP.mjs.map +0 -1
  59. /package/dist/{chunk-OBXQSB7S.mjs.map → chunk-37JRY3TC.mjs.map} +0 -0
  60. /package/dist/{chunk-W5BKJN46.mjs.map → chunk-AR533FGY.mjs.map} +0 -0
  61. /package/dist/{chunk-4MLKBZGB.mjs.map → chunk-K2GJI3PT.mjs.map} +0 -0
  62. /package/dist/{chunk-M7U7RZLU.mjs.map → chunk-LWJIFZWN.mjs.map} +0 -0
  63. /package/dist/{chunk-2VA5EV2P.mjs.map → chunk-THCOOWDH.mjs.map} +0 -0
@@ -3,7 +3,7 @@ import "../chunk-SPCZTZCY.mjs";
3
3
  import {
4
4
  CopilotKit,
5
5
  defaultCopilotContextCategories
6
- } from "../chunk-2VA5EV2P.mjs";
6
+ } from "../chunk-THCOOWDH.mjs";
7
7
  import "../chunk-FJEI7IBX.mjs";
8
8
  import "../chunk-CYDWEPFL.mjs";
9
9
  import "../chunk-2IDV5OHF.mjs";
@@ -14,9 +14,9 @@ import "../chunk-PMAFHQ7P.mjs";
14
14
  import "../chunk-YYN33GSG.mjs";
15
15
  import "../chunk-BVBFFI7K.mjs";
16
16
  import "../chunk-O7ARI5CV.mjs";
17
- import "../chunk-QNUAXSDP.mjs";
17
+ import "../chunk-3X3I7OJV.mjs";
18
18
  import "../chunk-NB2FKV2V.mjs";
19
- import "../chunk-F555TVE4.mjs";
19
+ import "../chunk-LMHB2D4J.mjs";
20
20
  import "../chunk-WF65O6HX.mjs";
21
21
  import "../chunk-EFL5OBKN.mjs";
22
22
  import "../chunk-6ZLPNY7X.mjs";
@@ -249,8 +249,8 @@ var import_shared = require("@copilotkit/shared");
249
249
  var import_jsx_runtime2 = require("react/jsx-runtime");
250
250
  var ThreadsContext = (0, import_react4.createContext)(void 0);
251
251
  function ThreadsProvider({ children, threadId: explicitThreadId }) {
252
- const [internalThreadId, setThreadId] = (0, import_react4.useState)(explicitThreadId != null ? explicitThreadId : (0, import_shared.randomUUID)());
253
- const threadId = internalThreadId;
252
+ const [internalThreadId, setThreadId] = (0, import_react4.useState)(() => (0, import_shared.randomUUID)());
253
+ const threadId = explicitThreadId != null ? explicitThreadId : internalThreadId;
254
254
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
255
255
  ThreadsContext.Provider,
256
256
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx","../../src/context/coagent-state-renders-context.tsx","../../src/context/threads-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport {\n CoAgentStateRendersContext,\n CoAgentStateRendersProvider,\n useCoAgentStateRenders,\n} from \"./coagent-state-renders-context\";\nexport { ThreadsContext, ThreadsProvider, useThreads } from \"./threads-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\nexport type { CoAgentStateRendersContextValue } from \"./coagent-state-renders-context\";\nexport type { ThreadsContextValue, ThreadsProviderProps } from \"./threads-context\";\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptRender,\n LangGraphInterruptActionSetter,\n QueuedInterruptEvent,\n} from \"../types/interrupt-action\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | React.JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | React.JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // registered actions for component-based rendering\n setRegisteredActions: (actionConfig: any) => string;\n removeRegisteredAction: (actionKey: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n interruptActions: Record<string, LangGraphInterruptRender>;\n setInterruptAction: LangGraphInterruptActionSetter;\n removeInterruptAction: (actionId: string) => void;\n interruptEventQueue: Record<string, QueuedInterruptEvent[]>;\n addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;\n resolveInterruptEvent: (threadId: string, eventId: string, response: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n setRegisteredActions: () => \"\",\n removeRegisteredAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n interruptActions: {},\n setInterruptAction: () => {},\n removeInterruptAction: () => {},\n interruptEventQueue: {},\n addInterruptEvent: () => {},\n resolveInterruptEvent: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>; // suggestions state\n suggestions: Suggestion[];\n setSuggestions: React.Dispatch<React.SetStateAction<Suggestion[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n // suggestions state\n suggestions: [],\n setSuggestions: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n","import React, {\n createContext,\n useContext,\n useCallback,\n useState,\n useRef,\n ReactNode,\n RefObject,\n} from \"react\";\nimport { CoAgentStateRender } from \"../types/coagent-action\";\n\ninterface StateRenderClaim {\n stateRenderId: string;\n stateSnapshot?: any;\n runId?: string;\n locked?: boolean;\n}\n\ntype ClaimsRef = Record<string, StateRenderClaim>;\n\nexport interface CoAgentStateRendersContextValue {\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n claimsRef: RefObject<ClaimsRef>;\n}\n\nconst CoAgentStateRendersContext = createContext<CoAgentStateRendersContextValue | undefined>(\n undefined,\n);\n\nexport function CoAgentStateRendersProvider({ children }: { children: ReactNode }) {\n const [coAgentStateRenders, setCoAgentStateRenders] = useState<\n Record<string, CoAgentStateRender<any>>\n >({});\n\n const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {\n setCoAgentStateRenders((prevPoints) => ({\n ...prevPoints,\n [id]: stateRender,\n }));\n }, []);\n\n const removeCoAgentStateRender = useCallback((id: string) => {\n setCoAgentStateRenders((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const claimsRef = useRef<ClaimsRef>({});\n\n return (\n <CoAgentStateRendersContext.Provider\n value={{\n coAgentStateRenders,\n setCoAgentStateRender,\n removeCoAgentStateRender,\n claimsRef,\n }}\n >\n {children}\n </CoAgentStateRendersContext.Provider>\n );\n}\n\nexport function useCoAgentStateRenders() {\n const context = useContext(CoAgentStateRendersContext);\n if (!context) {\n throw new Error(\"useCoAgentStateRenders must be used within CoAgentStateRendersProvider\");\n }\n return context;\n}\n\nexport { CoAgentStateRendersContext };\n","import React, { createContext, useContext, useState, ReactNode, SetStateAction } from \"react\";\nimport { randomUUID } from \"@copilotkit/shared\";\n\nexport interface ThreadsContextValue {\n threadId: string;\n setThreadId: (value: SetStateAction<string>) => void;\n}\n\nconst ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);\n\nexport interface ThreadsProviderProps {\n children: ReactNode;\n threadId?: string;\n}\n\nexport function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {\n const [internalThreadId, setThreadId] = useState<string>(explicitThreadId ?? randomUUID());\n\n const threadId = internalThreadId;\n\n return (\n <ThreadsContext.Provider\n value={{\n threadId,\n setThreadId,\n }}\n >\n {children}\n </ThreadsContext.Provider>\n );\n}\n\nexport function useThreads() {\n const context = useContext(ThreadsContext);\n if (!context) {\n throw new Error(\"useThreads must be used within ThreadsProvider\");\n }\n return context;\n}\n\nexport { ThreadsContext };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,mBAAkB;AAuOlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,sBAAsB,MAAM;AAAA,EAC5B,wBAAwB,MAAM;AAAA,EAAC;AAAA,EAE/B,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,k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AC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;","names":["React","import_react","emptyCopilotContext","React","import_react","import_react","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx","../../src/context/coagent-state-renders-context.tsx","../../src/context/threads-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport {\n CoAgentStateRendersContext,\n CoAgentStateRendersProvider,\n useCoAgentStateRenders,\n} from \"./coagent-state-renders-context\";\nexport { ThreadsContext, ThreadsProvider, useThreads } from \"./threads-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\nexport type { CoAgentStateRendersContextValue } from \"./coagent-state-renders-context\";\nexport type { ThreadsContextValue, ThreadsProviderProps } from \"./threads-context\";\n","import {\n CopilotCloudConfig,\n FunctionCallHandler,\n CopilotErrorHandler,\n CopilotKitError,\n} from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptRender,\n LangGraphInterruptActionSetter,\n QueuedInterruptEvent,\n} from \"../types/interrupt-action\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | React.JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | React.JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // registered actions for component-based rendering\n setRegisteredActions: (actionConfig: any) => string;\n removeRegisteredAction: (actionKey: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Partial<Pick<ForwardedParametersInput, \"temperature\">>;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n interruptActions: Record<string, LangGraphInterruptRender>;\n setInterruptAction: LangGraphInterruptActionSetter;\n removeInterruptAction: (actionId: string) => void;\n interruptEventQueue: Record<string, QueuedInterruptEvent[]>;\n addInterruptEvent: (queuedEvent: QueuedInterruptEvent) => void;\n resolveInterruptEvent: (threadId: string, eventId: string, response: string) => void;\n\n /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError: CopilotErrorHandler;\n\n // banner error state\n bannerError: CopilotKitError | null;\n setBannerError: React.Dispatch<React.SetStateAction<CopilotKitError | null>>;\n // Internal error handlers\n // These are used to handle errors that occur during the execution of the chat.\n // They are not intended for use by the developer. A component can register itself an error listener to be activated somewhere else as needed\n internalErrorHandlers: Record<string, CopilotErrorHandler>;\n setInternalErrorHandler: (handler: Record<string, CopilotErrorHandler>) => void;\n removeInternalErrorHandler: (id: string) => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n setRegisteredActions: () => \"\",\n removeRegisteredAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n interruptActions: {},\n setInterruptAction: () => {},\n removeInterruptAction: () => {},\n interruptEventQueue: {},\n addInterruptEvent: () => {},\n resolveInterruptEvent: () => {},\n onError: () => {},\n bannerError: null,\n setBannerError: () => {},\n internalErrorHandlers: {},\n setInternalErrorHandler: () => {},\n removeInternalErrorHandler: () => {},\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\nimport { Suggestion } from \"@copilotkitnext/core\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>; // suggestions state\n suggestions: Suggestion[];\n setSuggestions: React.Dispatch<React.SetStateAction<Suggestion[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n // suggestions state\n suggestions: [],\n setSuggestions: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n","import React, {\n createContext,\n useContext,\n useCallback,\n useState,\n useRef,\n ReactNode,\n RefObject,\n} from \"react\";\nimport { CoAgentStateRender } from \"../types/coagent-action\";\n\ninterface StateRenderClaim {\n stateRenderId: string;\n stateSnapshot?: any;\n runId?: string;\n locked?: boolean;\n}\n\ntype ClaimsRef = Record<string, StateRenderClaim>;\n\nexport interface CoAgentStateRendersContextValue {\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n claimsRef: RefObject<ClaimsRef>;\n}\n\nconst CoAgentStateRendersContext = createContext<CoAgentStateRendersContextValue | undefined>(\n undefined,\n);\n\nexport function CoAgentStateRendersProvider({ children }: { children: ReactNode }) {\n const [coAgentStateRenders, setCoAgentStateRenders] = useState<\n Record<string, CoAgentStateRender<any>>\n >({});\n\n const setCoAgentStateRender = useCallback((id: string, stateRender: CoAgentStateRender<any>) => {\n setCoAgentStateRenders((prevPoints) => ({\n ...prevPoints,\n [id]: stateRender,\n }));\n }, []);\n\n const removeCoAgentStateRender = useCallback((id: string) => {\n setCoAgentStateRenders((prevPoints) => {\n const newPoints = { ...prevPoints };\n delete newPoints[id];\n return newPoints;\n });\n }, []);\n\n const claimsRef = useRef<ClaimsRef>({});\n\n return (\n <CoAgentStateRendersContext.Provider\n value={{\n coAgentStateRenders,\n setCoAgentStateRender,\n removeCoAgentStateRender,\n claimsRef,\n }}\n >\n {children}\n </CoAgentStateRendersContext.Provider>\n );\n}\n\nexport function useCoAgentStateRenders() {\n const context = useContext(CoAgentStateRendersContext);\n if (!context) {\n throw new Error(\"useCoAgentStateRenders must be used within CoAgentStateRendersProvider\");\n }\n return context;\n}\n\nexport { CoAgentStateRendersContext };\n","import React, { createContext, useContext, useState, ReactNode, SetStateAction } from \"react\";\nimport { randomUUID } from \"@copilotkit/shared\";\n\nexport interface ThreadsContextValue {\n threadId: string;\n setThreadId: (value: SetStateAction<string>) => void;\n}\n\nconst ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);\n\nexport interface ThreadsProviderProps {\n children: ReactNode;\n threadId?: string;\n}\n\nexport function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {\n const [internalThreadId, setThreadId] = useState<string>(() => randomUUID());\n\n const threadId = explicitThreadId ?? internalThreadId;\n\n return (\n <ThreadsContext.Provider\n value={{\n threadId,\n setThreadId,\n }}\n >\n {children}\n </ThreadsContext.Provider>\n );\n}\n\nexport function useThreads() {\n const context = useContext(ThreadsContext);\n if (!context) {\n throw new Error(\"useThreads must be used within ThreadsProvider\");\n }\n return context;\n}\n\nexport { ThreadsContext };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,mBAAkB;AAuOlB,IAAM,sBAA4C;AAAA,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AAW,QAAI,wBAAiB,UAAM,0BAAW,CAAC;AAE3E,QAAM,WAAW,8CAAoB;AAErC,SACE;AAAA,IAAC,eAAe;AAAA,IAAf;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,SAAS,aAAa;AAC3B,QAAM,cAAU,0BAAW,cAAc;AACzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;","names":["React","import_react","emptyCopilotContext","React","import_react","import_react","import_jsx_runtime"]}
@@ -3,7 +3,7 @@ import {
3
3
  ThreadsContext,
4
4
  ThreadsProvider,
5
5
  useThreads
6
- } from "../chunk-F555TVE4.mjs";
6
+ } from "../chunk-LMHB2D4J.mjs";
7
7
  import {
8
8
  CoAgentStateRendersContext,
9
9
  CoAgentStateRendersProvider,
@@ -30,8 +30,8 @@ var import_shared = require("@copilotkit/shared");
30
30
  var import_jsx_runtime = require("react/jsx-runtime");
31
31
  var ThreadsContext = (0, import_react.createContext)(void 0);
32
32
  function ThreadsProvider({ children, threadId: explicitThreadId }) {
33
- const [internalThreadId, setThreadId] = (0, import_react.useState)(explicitThreadId != null ? explicitThreadId : (0, import_shared.randomUUID)());
34
- const threadId = internalThreadId;
33
+ const [internalThreadId, setThreadId] = (0, import_react.useState)(() => (0, import_shared.randomUUID)());
34
+ const threadId = explicitThreadId != null ? explicitThreadId : internalThreadId;
35
35
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
36
36
  ThreadsContext.Provider,
37
37
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/threads-context.tsx"],"sourcesContent":["import React, { createContext, useContext, useState, ReactNode, SetStateAction } from \"react\";\nimport { randomUUID } from \"@copilotkit/shared\";\n\nexport interface ThreadsContextValue {\n threadId: string;\n setThreadId: (value: SetStateAction<string>) => void;\n}\n\nconst ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);\n\nexport interface ThreadsProviderProps {\n children: ReactNode;\n threadId?: string;\n}\n\nexport function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {\n const [internalThreadId, setThreadId] = useState<string>(explicitThreadId ?? randomUUID());\n\n const threadId = internalThreadId;\n\n return (\n <ThreadsContext.Provider\n value={{\n threadId,\n setThreadId,\n }}\n >\n {children}\n </ThreadsContext.Provider>\n );\n}\n\nexport function useThreads() {\n const context = useContext(ThreadsContext);\n if (!context) {\n throw new Error(\"useThreads must be used within ThreadsProvider\");\n }\n return context;\n}\n\nexport { ThreadsContext };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsF;AACtF,oBAA2B;AAoBvB;AAbJ,IAAM,qBAAiB,4BAA+C,MAAS;AAOxE,SAAS,gBAAgB,EAAE,UAAU,UAAU,iBAAiB,GAAyB;AAC9F,QAAM,CAAC,kBAAkB,WAAW,QAAI,uBAAiB,kDAAoB,0BAAW,CAAC;AAEzF,QAAM,WAAW;AAEjB,SACE;AAAA,IAAC,eAAe;AAAA,IAAf;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,SAAS,aAAa;AAC3B,QAAM,cAAU,yBAAW,cAAc;AACzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/context/threads-context.tsx"],"sourcesContent":["import React, { createContext, useContext, useState, ReactNode, SetStateAction } from \"react\";\nimport { randomUUID } from \"@copilotkit/shared\";\n\nexport interface ThreadsContextValue {\n threadId: string;\n setThreadId: (value: SetStateAction<string>) => void;\n}\n\nconst ThreadsContext = createContext<ThreadsContextValue | undefined>(undefined);\n\nexport interface ThreadsProviderProps {\n children: ReactNode;\n threadId?: string;\n}\n\nexport function ThreadsProvider({ children, threadId: explicitThreadId }: ThreadsProviderProps) {\n const [internalThreadId, setThreadId] = useState<string>(() => randomUUID());\n\n const threadId = explicitThreadId ?? internalThreadId;\n\n return (\n <ThreadsContext.Provider\n value={{\n threadId,\n setThreadId,\n }}\n >\n {children}\n </ThreadsContext.Provider>\n );\n}\n\nexport function useThreads() {\n const context = useContext(ThreadsContext);\n if (!context) {\n throw new Error(\"useThreads must be used within ThreadsProvider\");\n }\n return context;\n}\n\nexport { ThreadsContext };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsF;AACtF,oBAA2B;AAoBvB;AAbJ,IAAM,qBAAiB,4BAA+C,MAAS;AAOxE,SAAS,gBAAgB,EAAE,UAAU,UAAU,iBAAiB,GAAyB;AAC9F,QAAM,CAAC,kBAAkB,WAAW,QAAI,uBAAiB,UAAM,0BAAW,CAAC;AAE3E,QAAM,WAAW,8CAAoB;AAErC,SACE;AAAA,IAAC,eAAe;AAAA,IAAf;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,SAAS,aAAa;AAC3B,QAAM,cAAU,yBAAW,cAAc;AACzC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,SAAO;AACT;","names":[]}
@@ -2,7 +2,7 @@ import {
2
2
  ThreadsContext,
3
3
  ThreadsProvider,
4
4
  useThreads
5
- } from "../chunk-F555TVE4.mjs";
5
+ } from "../chunk-LMHB2D4J.mjs";
6
6
  import "../chunk-SKC7AJIV.mjs";
7
7
  export {
8
8
  ThreadsContext,
@@ -552,12 +552,16 @@ function useCoagentStateRenderBridge(agentId, props) {
552
552
  const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
553
553
  const { agent } = (0, import_react11.useAgent)({ agentId });
554
554
  const [nodeName, setNodeName] = (0, import_react12.useState)(void 0);
555
+ const [, forceUpdate] = (0, import_react12.useState)(0);
555
556
  const runId = (_a = props.runId) != null ? _a : message.runId;
556
557
  const effectiveRunId = runId || "pending";
557
558
  (0, import_react12.useEffect)(() => {
558
559
  if (!agent)
559
560
  return;
560
561
  const subscriber = {
562
+ onStateChanged: () => {
563
+ forceUpdate((value) => value + 1);
564
+ },
561
565
  onStepStartedEvent: ({ event }) => {
562
566
  if (event.stepName !== nodeName) {
563
567
  setNodeName(event.stepName);
@@ -635,12 +639,14 @@ function useCoagentStateRenderBridge(agentId, props) {
635
639
  if (!canRender) {
636
640
  return null;
637
641
  }
638
- if (snapshot && !claimsRef.current[message.id].locked) {
639
- if (stateSnapshot) {
640
- claimsRef.current[message.id].stateSnapshot = snapshot;
641
- claimsRef.current[message.id].locked = true;
642
- } else {
642
+ if (snapshot) {
643
+ const existingSnapshot = claimsRef.current[message.id].stateSnapshot;
644
+ const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
645
+ if (!claimsRef.current[message.id].locked || snapshotChanged) {
643
646
  claimsRef.current[message.id].stateSnapshot = snapshot;
647
+ if (stateSnapshot) {
648
+ claimsRef.current[message.id].locked = true;
649
+ }
644
650
  }
645
651
  }
646
652
  if (stateRender.handler) {