@copilotkit/react-core 1.5.12-next.6 → 1.5.12

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 (100) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/{chunk-5SXKKYAY.mjs → chunk-6BQUI465.mjs} +26 -5
  3. package/dist/chunk-6BQUI465.mjs.map +1 -0
  4. package/dist/{chunk-SDMANO6S.mjs → chunk-CBWNO2FP.mjs} +2 -2
  5. package/dist/{chunk-KHZO2WMR.mjs → chunk-EXX267DG.mjs} +2 -2
  6. package/dist/chunk-IFBUUIU7.mjs +53 -0
  7. package/dist/chunk-IFBUUIU7.mjs.map +1 -0
  8. package/dist/{chunk-HIUT2NLX.mjs → chunk-J6UBNKIR.mjs} +2 -2
  9. package/dist/{chunk-27ONDUGD.mjs → chunk-KGCYVAIN.mjs} +14 -8
  10. package/dist/chunk-KGCYVAIN.mjs.map +1 -0
  11. package/dist/{chunk-ANHSORJR.mjs → chunk-MF4F77OY.mjs} +3 -3
  12. package/dist/{chunk-5TSAQCRY.mjs → chunk-MYCYEMIM.mjs} +25 -7
  13. package/dist/chunk-MYCYEMIM.mjs.map +1 -0
  14. package/dist/{chunk-FQ53HQYZ.mjs → chunk-N37EFAUX.mjs} +2 -2
  15. package/dist/{chunk-NO6F42WV.mjs → chunk-VEGDEDID.mjs} +2 -2
  16. package/dist/{chunk-EUSQWVOS.mjs → chunk-X62FIPVR.mjs} +10 -7
  17. package/dist/chunk-X62FIPVR.mjs.map +1 -0
  18. package/dist/{chunk-WXREY7UP.mjs → chunk-YVQNSJ4Z.mjs} +6 -3
  19. package/dist/chunk-YVQNSJ4Z.mjs.map +1 -0
  20. package/dist/components/copilot-provider/copilot-messages.js +125 -2
  21. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  22. package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
  23. package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -0
  24. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  25. package/dist/components/copilot-provider/copilotkit.js +54 -7
  26. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  27. package/dist/components/copilot-provider/copilotkit.mjs +3 -3
  28. package/dist/components/copilot-provider/index.js +54 -7
  29. package/dist/components/copilot-provider/index.js.map +1 -1
  30. package/dist/components/copilot-provider/index.mjs +3 -3
  31. package/dist/components/index.js +54 -7
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +3 -3
  34. package/dist/context/copilot-context.d.ts +5 -3
  35. package/dist/context/copilot-context.js +5 -2
  36. package/dist/context/copilot-context.js.map +1 -1
  37. package/dist/context/copilot-context.mjs +1 -1
  38. package/dist/context/index.js +5 -2
  39. package/dist/context/index.js.map +1 -1
  40. package/dist/context/index.mjs +1 -1
  41. package/dist/hooks/index.js +42 -13
  42. package/dist/hooks/index.js.map +1 -1
  43. package/dist/hooks/index.mjs +11 -11
  44. package/dist/hooks/use-chat.d.ts +11 -3
  45. package/dist/hooks/use-chat.js +11 -6
  46. package/dist/hooks/use-chat.js.map +1 -1
  47. package/dist/hooks/use-chat.mjs +1 -1
  48. package/dist/hooks/use-coagent-state-render.js +5 -2
  49. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  50. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  51. package/dist/hooks/use-coagent.js +42 -13
  52. package/dist/hooks/use-coagent.js.map +1 -1
  53. package/dist/hooks/use-coagent.mjs +6 -6
  54. package/dist/hooks/use-copilot-action.js +5 -2
  55. package/dist/hooks/use-copilot-action.js.map +1 -1
  56. package/dist/hooks/use-copilot-action.mjs +2 -2
  57. package/dist/hooks/use-copilot-authenticated-action.js +5 -2
  58. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  59. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  60. package/dist/hooks/use-copilot-chat.js +22 -11
  61. package/dist/hooks/use-copilot-chat.js.map +1 -1
  62. package/dist/hooks/use-copilot-chat.mjs +5 -5
  63. package/dist/hooks/use-copilot-readable.js +5 -2
  64. package/dist/hooks/use-copilot-readable.js.map +1 -1
  65. package/dist/hooks/use-copilot-readable.mjs +2 -2
  66. package/dist/hooks/use-make-copilot-document-readable.js +5 -2
  67. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  68. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  69. package/dist/index.js +122 -56
  70. package/dist/index.js.map +1 -1
  71. package/dist/index.mjs +12 -12
  72. package/dist/lib/copilot-task.js.map +1 -1
  73. package/dist/lib/copilot-task.mjs +4 -4
  74. package/dist/lib/index.js.map +1 -1
  75. package/dist/lib/index.mjs +4 -4
  76. package/dist/utils/extract.js.map +1 -1
  77. package/dist/utils/extract.mjs +3 -3
  78. package/dist/utils/index.js.map +1 -1
  79. package/dist/utils/index.mjs +3 -3
  80. package/package.json +3 -3
  81. package/src/components/copilot-provider/copilot-messages.tsx +24 -2
  82. package/src/components/copilot-provider/copilotkit-props.tsx +5 -0
  83. package/src/components/copilot-provider/copilotkit.tsx +30 -4
  84. package/src/context/copilot-context.tsx +13 -4
  85. package/src/hooks/use-chat.ts +27 -7
  86. package/src/hooks/use-coagent.ts +30 -4
  87. package/src/hooks/use-copilot-chat.ts +5 -2
  88. package/dist/chunk-27ONDUGD.mjs.map +0 -1
  89. package/dist/chunk-5SXKKYAY.mjs.map +0 -1
  90. package/dist/chunk-5TSAQCRY.mjs.map +0 -1
  91. package/dist/chunk-EUSQWVOS.mjs.map +0 -1
  92. package/dist/chunk-WXREY7UP.mjs.map +0 -1
  93. package/dist/chunk-XXR4QFAQ.mjs +0 -29
  94. package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
  95. /package/dist/{chunk-SDMANO6S.mjs.map → chunk-CBWNO2FP.mjs.map} +0 -0
  96. /package/dist/{chunk-KHZO2WMR.mjs.map → chunk-EXX267DG.mjs.map} +0 -0
  97. /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-J6UBNKIR.mjs.map} +0 -0
  98. /package/dist/{chunk-ANHSORJR.mjs.map → chunk-MF4F77OY.mjs.map} +0 -0
  99. /package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-N37EFAUX.mjs.map} +0 -0
  100. /package/dist/{chunk-NO6F42WV.mjs.map → chunk-VEGDEDID.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } 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 { CopilotRuntimeClient, ForwardedParametersInput } from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\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\nexport type InChatRenderFunction = (\n props: ActionRenderProps<any> | CatchAllActionRenderProps<any>,\n) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | 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;\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 // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: 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 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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\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 | null;\n setThreadId: React.Dispatch<React.SetStateAction<string | null>>;\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 // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates?: Record<ActionName, AuthState>;\n setAuthStates?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\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: \"auto\",\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: null,\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAkC;;;ACMlC,mBAAkB;AA+LlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,eAAe,CAAC;AAAA,EAEhB,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IAEA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAA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3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } 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\";\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\nexport type InChatRenderFunction = (\n props: ActionRenderProps<any> | CatchAllActionRenderProps<any>,\n) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | 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;\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 // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: 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 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 // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean | \"auto\";\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 // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates?: Record<ActionName, AuthState>;\n setAuthStates?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\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: \"auto\",\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};\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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../chunk-HIUT2NLX.mjs";
4
- import "../chunk-WXREY7UP.mjs";
3
+ } from "../chunk-J6UBNKIR.mjs";
4
+ import "../chunk-YVQNSJ4Z.mjs";
5
5
  import "../chunk-SKC7AJIV.mjs";
6
6
  export {
7
7
  useMakeCopilotDocumentReadable
package/dist/index.js CHANGED
@@ -164,14 +164,17 @@ var emptyCopilotContext = {
164
164
  },
165
165
  forwardedParameters: {},
166
166
  agentLock: null,
167
- threadId: null,
167
+ threadId: "",
168
168
  setThreadId: () => {
169
169
  },
170
170
  runId: null,
171
171
  setRunId: () => {
172
172
  },
173
173
  chatAbortControllerRef: { current: null },
174
- availableAgents: []
174
+ availableAgents: [],
175
+ extensions: {},
176
+ setExtensions: () => {
177
+ }
175
178
  };
176
179
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
177
180
  function useCopilotContext() {
@@ -407,10 +410,30 @@ function useCopilotMessagesContext() {
407
410
  }
408
411
 
409
412
  // src/components/copilot-provider/copilot-messages.tsx
413
+ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
410
414
  var import_jsx_runtime = require("react/jsx-runtime");
411
415
  function CopilotMessages(_a) {
412
416
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
413
417
  const [messages, setMessages] = (0, import_react5.useState)([]);
418
+ const { threadId, agentSession, runtimeClient } = useCopilotContext();
419
+ (0, import_react5.useEffect)(() => {
420
+ if (agentSession == null ? void 0 : agentSession.agentName) {
421
+ const fetchAgentState = () => __async(this, null, function* () {
422
+ var _a2, _b2, _c, _d;
423
+ const result = yield runtimeClient.loadAgentState({
424
+ threadId,
425
+ agentName: agentSession.agentName
426
+ });
427
+ if ((_b2 = (_a2 = result.data) == null ? void 0 : _a2.loadAgentState) == null ? void 0 : _b2.threadExists) {
428
+ const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(
429
+ JSON.parse(((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.messages) || "[]")
430
+ );
431
+ setMessages(messages2);
432
+ }
433
+ });
434
+ void fetchAgentState();
435
+ }
436
+ }, [threadId, (agentSession == null ? void 0 : agentSession.agentName) !== void 0]);
414
437
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
415
438
  CopilotMessagesContext.Provider,
416
439
  {
@@ -680,13 +703,13 @@ function Toast({
680
703
  }
681
704
 
682
705
  // src/hooks/use-copilot-runtime-client.ts
683
- var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
706
+ var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
684
707
  var import_react8 = require("react");
685
708
  var useCopilotRuntimeClient = (options) => {
686
709
  const { addGraphQLErrorsToast } = useToast();
687
710
  const addErrorToast = useErrorToast();
688
711
  const runtimeClient = (0, import_react8.useMemo)(() => {
689
- return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
712
+ return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
690
713
  handleGQLErrors: (error) => {
691
714
  if (error.graphQLErrors.length) {
692
715
  addGraphQLErrorsToast(error.graphQLErrors);
@@ -701,8 +724,8 @@ var useCopilotRuntimeClient = (options) => {
701
724
 
702
725
  // src/utils/extract.ts
703
726
  var import_shared3 = require("@copilotkit/shared");
704
- var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
705
727
  var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
728
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
706
729
  function extract(_0) {
707
730
  return __async(this, arguments, function* ({
708
731
  context,
@@ -712,7 +735,7 @@ function extract(_0) {
712
735
  data,
713
736
  abortSignal,
714
737
  stream,
715
- requestType = import_runtime_client_gql2.CopilotRequestType.Task,
738
+ requestType = import_runtime_client_gql3.CopilotRequestType.Task,
716
739
  forwardedParameters
717
740
  }) {
718
741
  var _a, _b;
@@ -733,13 +756,13 @@ function extract(_0) {
733
756
  if (includeReadable) {
734
757
  contextString += context.getContextString([], defaultCopilotContextCategories);
735
758
  }
736
- const systemMessage = new import_runtime_client_gql2.TextMessage({
759
+ const systemMessage = new import_runtime_client_gql3.TextMessage({
737
760
  content: makeSystemMessage(contextString, instructions),
738
- role: import_runtime_client_gql2.Role.System
761
+ role: import_runtime_client_gql3.Role.System
739
762
  });
740
- const instructionsMessage = new import_runtime_client_gql2.TextMessage({
763
+ const instructionsMessage = new import_runtime_client_gql3.TextMessage({
741
764
  content: makeInstructionsMessage(instructions),
742
- role: import_runtime_client_gql2.Role.User
765
+ role: import_runtime_client_gql3.Role.User
743
766
  });
744
767
  const response = context.runtimeClient.asStream(
745
768
  context.runtimeClient.generateCopilotResponse({
@@ -754,8 +777,8 @@ function extract(_0) {
754
777
  ],
755
778
  url: window.location.href
756
779
  },
757
- messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(
758
- includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql3.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
780
+ messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)(
781
+ includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql4.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
759
782
  ),
760
783
  metadata: {
761
784
  requestType
@@ -780,7 +803,7 @@ function extract(_0) {
780
803
  if (abortSignal == null ? void 0 : abortSignal.aborted) {
781
804
  throw new Error("Aborted");
782
805
  }
783
- actionExecutionMessage = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
806
+ actionExecutionMessage = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
784
807
  value.generateCopilotResponse.messages
785
808
  ).find((msg) => msg.isActionExecutionMessage());
786
809
  if (!actionExecutionMessage) {
@@ -901,6 +924,7 @@ function CopilotKitInternal(_a) {
901
924
  const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
902
925
  const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
903
926
  const [authStates, setAuthStates] = (0, import_react10.useState)({});
927
+ const [extensions, setExtensions] = (0, import_react10.useState)({});
904
928
  const {
905
929
  addElement: addDocument,
906
930
  removeElement: removeDocument,
@@ -1085,7 +1109,21 @@ ${nonDocumentStrings}`;
1085
1109
  };
1086
1110
  }
1087
1111
  const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
1088
- const [threadId, setThreadId] = (0, import_react10.useState)(null);
1112
+ const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared4.randomUUID)());
1113
+ const setThreadId = (0, import_react10.useCallback)(
1114
+ (value) => {
1115
+ if (props.threadId) {
1116
+ throw new Error("Cannot call setThreadId() when threadId is provided via props.");
1117
+ }
1118
+ setInternalThreadId(value);
1119
+ },
1120
+ [props.threadId]
1121
+ );
1122
+ (0, import_react10.useEffect)(() => {
1123
+ if (props.threadId !== void 0) {
1124
+ setInternalThreadId(props.threadId);
1125
+ }
1126
+ }, [props.threadId]);
1089
1127
  const [runId, setRunId] = (0, import_react10.useState)(null);
1090
1128
  const chatAbortControllerRef = (0, import_react10.useRef)(null);
1091
1129
  const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
@@ -1125,7 +1163,7 @@ ${nonDocumentStrings}`;
1125
1163
  runtimeClient,
1126
1164
  forwardedParameters: props.forwardedParameters || {},
1127
1165
  agentLock: props.agent || null,
1128
- threadId,
1166
+ threadId: internalThreadId,
1129
1167
  setThreadId,
1130
1168
  runId,
1131
1169
  setRunId,
@@ -1133,7 +1171,9 @@ ${nonDocumentStrings}`;
1133
1171
  availableAgents,
1134
1172
  authConfig: props.authConfig,
1135
1173
  authStates,
1136
- setAuthStates
1174
+ setAuthStates,
1175
+ extensions,
1176
+ setExtensions
1137
1177
  },
1138
1178
  children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
1139
1179
  }
@@ -1168,27 +1208,27 @@ function entryPointsToFunctionCallHandler(actions) {
1168
1208
 
1169
1209
  // src/hooks/use-copilot-chat.ts
1170
1210
  var import_react12 = require("react");
1171
- var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
1211
+ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1172
1212
 
1173
1213
  // src/hooks/use-chat.ts
1174
1214
  var import_react11 = require("react");
1175
1215
  var import_shared6 = require("@copilotkit/shared");
1176
- var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1216
+ var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
1177
1217
 
1178
1218
  // src/types/frontend-action.ts
1179
- var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
1219
+ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1180
1220
  var import_shared5 = require("@copilotkit/shared");
1181
1221
  function processActionsForRuntimeRequest(actions) {
1182
1222
  const filteredActions = actions.filter(
1183
- (action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
1223
+ (action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
1184
1224
  ).map((action) => {
1185
- let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
1225
+ let available = import_runtime_client_gql5.ActionInputAvailability.Enabled;
1186
1226
  if (action.disabled) {
1187
- available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
1227
+ available = import_runtime_client_gql5.ActionInputAvailability.Disabled;
1188
1228
  } else if (action.available === "disabled") {
1189
- available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
1229
+ available = import_runtime_client_gql5.ActionInputAvailability.Disabled;
1190
1230
  } else if (action.available === "remote") {
1191
- available = import_runtime_client_gql4.ActionInputAvailability.Remote;
1231
+ available = import_runtime_client_gql5.ActionInputAvailability.Remote;
1192
1232
  }
1193
1233
  return {
1194
1234
  name: action.name,
@@ -1222,16 +1262,18 @@ function useChat(options) {
1222
1262
  runId,
1223
1263
  setRunId,
1224
1264
  chatAbortControllerRef,
1225
- agentLock
1265
+ agentLock,
1266
+ extensions,
1267
+ setExtensions
1226
1268
  } = options;
1227
1269
  const runChatCompletionRef = (0, import_react11.useRef)();
1228
1270
  const addErrorToast = useErrorToast();
1229
1271
  const agentSessionRef = (0, import_react11.useRef)(agentSession);
1230
1272
  agentSessionRef.current = agentSession;
1231
- const threadIdRef = (0, import_react11.useRef)(threadId);
1232
- threadIdRef.current = threadId;
1233
1273
  const runIdRef = (0, import_react11.useRef)(runId);
1234
1274
  runIdRef.current = runId;
1275
+ const extensionsRef = (0, import_react11.useRef)(extensions);
1276
+ extensionsRef.current = extensions;
1235
1277
  const publicApiKey = copilotConfig.publicApiKey;
1236
1278
  const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
1237
1279
  const runtimeClient = useCopilotRuntimeClient({
@@ -1245,9 +1287,9 @@ function useChat(options) {
1245
1287
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1246
1288
  setIsLoading(true);
1247
1289
  let newMessages = [
1248
- new import_runtime_client_gql5.TextMessage({
1290
+ new import_runtime_client_gql6.TextMessage({
1249
1291
  content: "",
1250
- role: import_runtime_client_gql5.Role.Assistant
1292
+ role: import_runtime_client_gql6.Role.Assistant
1251
1293
  })
1252
1294
  ];
1253
1295
  chatAbortControllerRef.current = new AbortController();
@@ -1262,9 +1304,10 @@ function useChat(options) {
1262
1304
  actions: processActionsForRuntimeRequest(actions),
1263
1305
  url: window.location.href
1264
1306
  },
1265
- threadId: threadIdRef.current,
1307
+ threadId,
1266
1308
  runId: runIdRef.current,
1267
- messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messagesWithContext))
1309
+ extensions: extensionsRef.current,
1310
+ messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messagesWithContext))
1268
1311
  }, copilotConfig.cloud ? {
1269
1312
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
1270
1313
  guardrails: {
@@ -1276,7 +1319,7 @@ function useChat(options) {
1276
1319
  } : {})
1277
1320
  } : {}), {
1278
1321
  metadata: {
1279
- requestType: import_runtime_client_gql5.CopilotRequestType.Chat
1322
+ requestType: import_runtime_client_gql6.CopilotRequestType.Chat
1280
1323
  }
1281
1324
  }), agentSessionRef.current ? {
1282
1325
  agentSession: agentSessionRef.current
@@ -1316,12 +1359,14 @@ function useChat(options) {
1316
1359
  if (!(value == null ? void 0 : value.generateCopilotResponse)) {
1317
1360
  continue;
1318
1361
  }
1319
- threadIdRef.current = value.generateCopilotResponse.threadId || null;
1320
1362
  runIdRef.current = value.generateCopilotResponse.runId || null;
1321
- setThreadId(threadIdRef.current);
1363
+ extensionsRef.current = import_runtime_client_gql6.CopilotRuntimeClient.removeGraphQLTypename(
1364
+ value.generateCopilotResponse.extensions || {}
1365
+ );
1322
1366
  setRunId(runIdRef.current);
1323
- messages2 = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
1324
- (0, import_runtime_client_gql5.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
1367
+ setExtensions(extensionsRef.current);
1368
+ messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
1369
+ (0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
1325
1370
  );
1326
1371
  if (messages2.length === 0) {
1327
1372
  continue;
@@ -1329,8 +1374,8 @@ function useChat(options) {
1329
1374
  newMessages = [];
1330
1375
  if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
1331
1376
  newMessages = [
1332
- new import_runtime_client_gql5.TextMessage({
1333
- role: import_runtime_client_gql5.MessageRole.Assistant,
1377
+ new import_runtime_client_gql6.TextMessage({
1378
+ role: import_runtime_client_gql6.MessageRole.Assistant,
1334
1379
  content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
1335
1380
  })
1336
1381
  ];
@@ -1354,7 +1399,7 @@ function useChat(options) {
1354
1399
  const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
1355
1400
  if (lastAgentStateMessage) {
1356
1401
  if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
1357
- syncedMessages = (0, import_runtime_client_gql5.loadMessagesFromJsonRepresentation)(
1402
+ syncedMessages = (0, import_runtime_client_gql6.loadMessagesFromJsonRepresentation)(
1358
1403
  lastAgentStateMessage.state.messages
1359
1404
  );
1360
1405
  }
@@ -1398,7 +1443,7 @@ function useChat(options) {
1398
1443
  const lastMessages = [];
1399
1444
  for (let i = finalMessages.length - 1; i >= 0; i--) {
1400
1445
  const message = finalMessages[i];
1401
- if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql5.MessageStatusCode.Pending) {
1446
+ if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
1402
1447
  lastMessages.unshift(message);
1403
1448
  } else {
1404
1449
  break;
@@ -1446,9 +1491,9 @@ function useChat(options) {
1446
1491
  finalMessages.splice(
1447
1492
  messageIndex + 1,
1448
1493
  0,
1449
- new import_runtime_client_gql5.ResultMessage({
1494
+ new import_runtime_client_gql6.ResultMessage({
1450
1495
  id: "result-" + message.id,
1451
- result: import_runtime_client_gql5.ResultMessage.encodeResult(
1496
+ result: import_runtime_client_gql6.ResultMessage.encodeResult(
1452
1497
  error ? {
1453
1498
  content: result,
1454
1499
  error: JSON.parse(
@@ -1605,7 +1650,9 @@ function useCopilotChat(_a = {}) {
1605
1650
  setThreadId,
1606
1651
  runId,
1607
1652
  setRunId,
1608
- chatAbortControllerRef
1653
+ chatAbortControllerRef,
1654
+ extensions,
1655
+ setExtensions
1609
1656
  } = useCopilotContext();
1610
1657
  const { messages, setMessages } = useCopilotMessagesContext();
1611
1658
  const latestGetContextString = useUpdatedRef(getContextString);
@@ -1618,9 +1665,9 @@ function useCopilotChat(_a = {}) {
1618
1665
  const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
1619
1666
  const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
1620
1667
  const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
1621
- return new import_runtime_client_gql6.TextMessage({
1668
+ return new import_runtime_client_gql7.TextMessage({
1622
1669
  content: systemMessageMaker(contextString, chatInstructions),
1623
- role: import_runtime_client_gql6.Role.System
1670
+ role: import_runtime_client_gql7.Role.System
1624
1671
  });
1625
1672
  }, [getContextString, makeSystemMessage2, chatInstructions]);
1626
1673
  const onCoAgentStateRender = useAsyncCallback(
@@ -1662,7 +1709,9 @@ function useCopilotChat(_a = {}) {
1662
1709
  runId,
1663
1710
  setRunId,
1664
1711
  chatAbortControllerRef,
1665
- agentLock
1712
+ agentLock,
1713
+ extensions,
1714
+ setExtensions
1666
1715
  }));
1667
1716
  const latestAppend = useUpdatedRef(append);
1668
1717
  const latestAppendFunc = useAsyncCallback(
@@ -1700,7 +1749,6 @@ function useCopilotChat(_a = {}) {
1700
1749
  const reset = (0, import_react12.useCallback)(() => {
1701
1750
  latestStopFunc();
1702
1751
  setMessages([]);
1703
- setThreadId(null);
1704
1752
  setRunId(null);
1705
1753
  setCoagentStatesWithRef({});
1706
1754
  let initialAgentSession = null;
@@ -1967,7 +2015,7 @@ function useCoAgent(options) {
1967
2015
  };
1968
2016
  const messagesContext = useCopilotMessagesContext();
1969
2017
  const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
1970
- const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
2018
+ const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
1971
2019
  const { appendMessage, runChatCompletion } = useCopilotChat();
1972
2020
  const getCoagentState = (coagentStates2, name2) => {
1973
2021
  if (coagentStates2[name2]) {
@@ -1984,6 +2032,11 @@ function useCoAgent(options) {
1984
2032
  };
1985
2033
  }
1986
2034
  };
2035
+ const runtimeClient = useCopilotRuntimeClient({
2036
+ url: copilotApiConfig.chatApiEndpoint,
2037
+ publicApiKey: copilotApiConfig.publicApiKey,
2038
+ credentials: copilotApiConfig.credentials
2039
+ });
1987
2040
  const setState = (newState) => {
1988
2041
  let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
1989
2042
  const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
@@ -1993,8 +2046,21 @@ function useCoAgent(options) {
1993
2046
  })
1994
2047
  }));
1995
2048
  };
2049
+ (0, import_react17.useEffect)(() => {
2050
+ const fetchAgentState = () => __async(this, null, function* () {
2051
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2052
+ const result = yield runtimeClient.loadAgentState({
2053
+ threadId,
2054
+ agentName: name
2055
+ });
2056
+ if (((_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.threadExists) && ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.state) && ((_f = (_e = result.data) == null ? void 0 : _e.loadAgentState) == null ? void 0 : _f.state) != "{}") {
2057
+ const fetchedState = JSON.parse((_h = (_g = result.data) == null ? void 0 : _g.loadAgentState) == null ? void 0 : _h.state);
2058
+ isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
2059
+ }
2060
+ });
2061
+ void fetchAgentState();
2062
+ }, [threadId]);
1996
2063
  const coagentState = getCoagentState(coagentStates, name);
1997
- const state = isExternalStateManagement(options) ? options.state : coagentState.state;
1998
2064
  (0, import_react17.useEffect)(() => {
1999
2065
  if (isExternalStateManagement(options)) {
2000
2066
  setState(options.state);
@@ -2124,7 +2190,7 @@ function useCopilotAuthenticatedAction(action, dependencies) {
2124
2190
  }
2125
2191
 
2126
2192
  // src/lib/copilot-task.ts
2127
- var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
2193
+ var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
2128
2194
  var CopilotTask = class {
2129
2195
  constructor(config) {
2130
2196
  this.instructions = config.instructions;
@@ -2152,12 +2218,12 @@ var CopilotTask = class {
2152
2218
  if (this.includeCopilotReadable) {
2153
2219
  contextString += context.getContextString([], defaultCopilotContextCategories);
2154
2220
  }
2155
- const systemMessage = new import_runtime_client_gql7.TextMessage({
2221
+ const systemMessage = new import_runtime_client_gql8.TextMessage({
2156
2222
  content: taskSystemMessage(contextString, this.instructions),
2157
- role: import_runtime_client_gql7.Role.System
2223
+ role: import_runtime_client_gql8.Role.System
2158
2224
  });
2159
2225
  const messages = [systemMessage];
2160
- const runtimeClient = new import_runtime_client_gql7.CopilotRuntimeClient({
2226
+ const runtimeClient = new import_runtime_client_gql8.CopilotRuntimeClient({
2161
2227
  url: context.copilotApiConfig.chatApiEndpoint,
2162
2228
  publicApiKey: context.copilotApiConfig.publicApiKey,
2163
2229
  headers: context.copilotApiConfig.headers,
@@ -2169,9 +2235,9 @@ var CopilotTask = class {
2169
2235
  actions: processActionsForRuntimeRequest(Object.values(actions)),
2170
2236
  url: window.location.href
2171
2237
  },
2172
- messages: (0, import_runtime_client_gql7.convertMessagesToGqlInput)((0, import_runtime_client_gql7.filterAgentStateMessages)(messages)),
2238
+ messages: (0, import_runtime_client_gql8.convertMessagesToGqlInput)((0, import_runtime_client_gql8.filterAgentStateMessages)(messages)),
2173
2239
  metadata: {
2174
- requestType: import_runtime_client_gql7.CopilotRequestType.Task
2240
+ requestType: import_runtime_client_gql8.CopilotRequestType.Task
2175
2241
  },
2176
2242
  forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
2177
2243
  toolChoice: "required"
@@ -2180,7 +2246,7 @@ var CopilotTask = class {
2180
2246
  properties: context.copilotApiConfig.properties
2181
2247
  }).toPromise();
2182
2248
  const functionCallHandler = context.getFunctionCallHandler(actions);
2183
- const functionCalls = (0, import_runtime_client_gql7.convertGqlOutputToMessages)(
2249
+ const functionCalls = (0, import_runtime_client_gql8.convertGqlOutputToMessages)(
2184
2250
  ((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
2185
2251
  ).filter((m) => m.isActionExecutionMessage());
2186
2252
  for (const functionCall of functionCalls) {