@copilotkit/react-core 1.6.0-next.1 → 1.6.0-next.11

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 (76) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
  3. package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
  4. package/dist/{chunk-VMYLY5KI.mjs → chunk-4EC4JK7H.mjs} +58 -48
  5. package/dist/chunk-4EC4JK7H.mjs.map +1 -0
  6. package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
  7. package/dist/chunk-F7O6L7C3.mjs.map +1 -0
  8. package/dist/{chunk-2DPTBHGN.mjs → chunk-FUO5LKSJ.mjs} +115 -63
  9. package/dist/chunk-FUO5LKSJ.mjs.map +1 -0
  10. package/dist/{chunk-4ED56DQX.mjs → chunk-HBCP2KNA.mjs} +3 -4
  11. package/dist/chunk-HBCP2KNA.mjs.map +1 -0
  12. package/dist/{chunk-Z3U4UBG2.mjs → chunk-T4CAQC6B.mjs} +2 -2
  13. package/dist/{chunk-JFCNSGNU.mjs → chunk-Y2T56VSE.mjs} +2 -2
  14. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
  15. package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
  16. package/dist/components/copilot-provider/index.d.ts +1 -2
  17. package/dist/components/index.d.ts +1 -2
  18. package/dist/context/copilot-context.d.ts +10 -148
  19. package/dist/context/index.d.ts +1 -2
  20. package/dist/copilot-context-9ae8990b.d.ts +183 -0
  21. package/dist/hooks/index.d.ts +1 -2
  22. package/dist/hooks/index.js +180 -123
  23. package/dist/hooks/index.js.map +1 -1
  24. package/dist/hooks/index.mjs +6 -6
  25. package/dist/hooks/use-chat.d.ts +1 -2
  26. package/dist/hooks/use-chat.js +113 -64
  27. package/dist/hooks/use-chat.js.map +1 -1
  28. package/dist/hooks/use-chat.mjs +2 -2
  29. package/dist/hooks/use-coagent.d.ts +1 -2
  30. package/dist/hooks/use-coagent.js +171 -112
  31. package/dist/hooks/use-coagent.js.map +1 -1
  32. package/dist/hooks/use-coagent.mjs +4 -4
  33. package/dist/hooks/use-copilot-chat.d.ts +1 -2
  34. package/dist/hooks/use-copilot-chat.js +116 -67
  35. package/dist/hooks/use-copilot-chat.js.map +1 -1
  36. package/dist/hooks/use-copilot-chat.mjs +3 -3
  37. package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
  38. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  39. package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
  40. package/dist/hooks/use-langgraph-interrupt.d.ts +9 -2
  41. package/dist/hooks/use-langgraph-interrupt.js +117 -69
  42. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  43. package/dist/hooks/use-langgraph-interrupt.mjs +4 -4
  44. package/dist/index.d.ts +1 -2
  45. package/dist/index.js +187 -130
  46. package/dist/index.js.map +1 -1
  47. package/dist/index.mjs +7 -7
  48. package/dist/lib/copilot-task.d.ts +1 -2
  49. package/dist/lib/copilot-task.js +1 -1
  50. package/dist/lib/copilot-task.js.map +1 -1
  51. package/dist/lib/copilot-task.mjs +2 -2
  52. package/dist/lib/index.d.ts +1 -2
  53. package/dist/lib/index.js +1 -1
  54. package/dist/lib/index.js.map +1 -1
  55. package/dist/lib/index.mjs +2 -2
  56. package/dist/types/frontend-action.d.ts +2 -1
  57. package/dist/types/frontend-action.js +1 -1
  58. package/dist/types/frontend-action.js.map +1 -1
  59. package/dist/types/frontend-action.mjs +1 -1
  60. package/dist/types/interrupt-action.d.ts +10 -35
  61. package/dist/types/interrupt-action.js.map +1 -1
  62. package/dist/utils/extract.d.ts +1 -2
  63. package/dist/utils/index.d.ts +1 -2
  64. package/package.json +3 -3
  65. package/src/hooks/use-chat.ts +134 -61
  66. package/src/hooks/use-coagent.ts +70 -56
  67. package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
  68. package/src/hooks/use-langgraph-interrupt.ts +1 -2
  69. package/src/types/frontend-action.ts +5 -2
  70. package/src/types/interrupt-action.ts +16 -12
  71. package/dist/chunk-2DPTBHGN.mjs.map +0 -1
  72. package/dist/chunk-4ED56DQX.mjs.map +0 -1
  73. package/dist/chunk-VMYLY5KI.mjs.map +0 -1
  74. package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
  75. /package/dist/{chunk-Z3U4UBG2.mjs.map → chunk-T4CAQC6B.mjs.map} +0 -0
  76. /package/dist/{chunk-JFCNSGNU.mjs.map → chunk-Y2T56VSE.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-langgraph-interrupt-render.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useCopilotContext } from \"../context\";\nimport React, { useCallback } from \"react\";\nimport { executeConditions } from \"@copilotkit/shared\";\n\ntype InterruptProps = {\n event: any;\n result: any;\n render: (props: {\n event: any;\n result: any;\n resolve: (response: string) => void;\n }) => string | React.ReactElement;\n resolve: (response: string) => void;\n};\n\nconst InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, resolve }) => {\n return render({ event, result, resolve });\n};\n\nexport function useLangGraphInterruptRender(): string | React.ReactElement | null {\n const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();\n\n const responseRef = React.useRef<string>();\n const resolveInterrupt = useCallback(\n (response: string) => {\n responseRef.current = response;\n // Use setTimeout to defer the state update to next tick\n setTimeout(() => {\n setLangGraphInterruptAction({ event: { response } });\n }, 0);\n },\n [setLangGraphInterruptAction],\n );\n\n if (\n !langGraphInterruptAction ||\n !langGraphInterruptAction.event ||\n !langGraphInterruptAction.render\n )\n return null;\n\n const { render, handler, event, conditions } = langGraphInterruptAction;\n\n const conditionsMet = executeConditions({ conditions, value: event.value });\n if (!conditionsMet) {\n return null;\n }\n\n let result = null;\n if (handler) {\n result = handler({\n event,\n resolve: resolveInterrupt,\n });\n }\n\n return React.createElement(InterruptRenderer, {\n event,\n result,\n render,\n resolve: resolveInterrupt,\n });\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\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\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\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => 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_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 langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\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 langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\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;;;ACMA,mBAAkB;AA4MlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC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AE,QAAQ,SAAS,OAAO,WAAW,IAAI;AAE/C,QAAM,oBAAgB,iCAAkB,EAAE,YAAY,OAAO,MAAM,MAAM,CAAC;AAC1E,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI,SAAS;AACX,aAAS,QAAQ;AAAA,MACf;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO,cAAAA,QAAM,cAAc,mBAAmB;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACH;","names":["React","import_react","React"]}
1
+ {"version":3,"sources":["../../src/hooks/use-langgraph-interrupt-render.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useCopilotContext } from \"../context\";\nimport React, { useCallback } from \"react\";\nimport { executeConditions } from \"@copilotkit/shared\";\n\ntype InterruptProps = {\n event: any;\n result: any;\n render: (props: {\n event: any;\n result: any;\n resolve: (response: string) => void;\n }) => string | React.ReactElement;\n resolve: (response: string) => void;\n};\n\nconst InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, resolve }) => {\n return render({ event, result, resolve });\n};\n\nexport function useLangGraphInterruptRender(): string | React.ReactElement | null {\n const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } =\n useCopilotContext();\n\n const responseRef = React.useRef<string>();\n const resolveInterrupt = useCallback(\n (response: string) => {\n responseRef.current = response;\n // Use setTimeout to defer the state update to next tick\n setTimeout(() => {\n setLangGraphInterruptAction({ event: { response } });\n }, 0);\n },\n [setLangGraphInterruptAction],\n );\n\n if (\n !langGraphInterruptAction ||\n !langGraphInterruptAction.event ||\n !langGraphInterruptAction.render\n )\n return null;\n\n const { render, handler, event, enabled } = langGraphInterruptAction;\n\n const conditionsMet =\n !agentSession || !enabled\n ? true\n : enabled({ eventValue: event.value, agentMetadata: agentSession });\n if (!conditionsMet) {\n return null;\n }\n\n let result = null;\n if (handler) {\n result = handler({\n event,\n resolve: resolveInterrupt,\n });\n }\n\n return React.createElement(InterruptRenderer, {\n event,\n result,\n render,\n resolve: resolveInterrupt,\n });\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\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\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\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => 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_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 langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\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 langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\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;;;ACMA,mBAAkB;AA4MlB,IAAM,sBAA4C;AAAA,EAChD,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M,EAAE,QAAQ,SAAS,OAAO,QAAQ,IAAI;AAE5C,QAAM,gBACJ,CAAC,gBAAgB,CAAC,UACd,OACA,QAAQ,EAAE,YAAY,MAAM,OAAO,eAAe,aAAa,CAAC;AACtE,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI,SAAS;AACX,aAAS,QAAQ;AAAA,MACf;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO,cAAAA,QAAM,cAAc,mBAAmB;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACH;","names":["React","import_react","React"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useLangGraphInterruptRender
3
- } from "../chunk-ZAU4EMBM.mjs";
3
+ } from "../chunk-F7O6L7C3.mjs";
4
4
  import "../chunk-YPSGKPDA.mjs";
5
5
  import "../chunk-ZM56S3LJ.mjs";
6
6
  import "../chunk-DCTJZ742.mjs";
@@ -1,6 +1,13 @@
1
- import { LangGraphInterruptRender } from '../types/interrupt-action.js';
2
- import '@copilotkit/runtime-client-gql';
1
+ import { e as LangGraphInterruptRender } from '../copilot-context-9ae8990b.js';
3
2
  import '@copilotkit/shared';
3
+ import '../types/frontend-action.js';
4
+ import '@copilotkit/runtime-client-gql';
5
+ import 'react';
6
+ import './use-tree.js';
7
+ import '../types/document-pointer.js';
8
+ import '../types/chat-suggestion-configuration.js';
9
+ import '../types/coagent-action.js';
10
+ import '../types/coagent-state.js';
4
11
 
5
12
  declare function useLangGraphInterrupt<TEventValue = any>(action: Omit<LangGraphInterruptRender<TEventValue>, "id">, dependencies?: any[]): void;
6
13
 
@@ -170,7 +170,7 @@ function returnAndThrowInDebug(_value) {
170
170
 
171
171
  // src/hooks/use-copilot-chat.ts
172
172
  var import_react8 = require("react");
173
- var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
173
+ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
174
174
 
175
175
  // src/hooks/use-chat.ts
176
176
  var import_react5 = require("react");
@@ -182,7 +182,7 @@ var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
182
182
  var import_shared = require("@copilotkit/shared");
183
183
  function processActionsForRuntimeRequest(actions) {
184
184
  const filteredActions = actions.filter(
185
- (action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
185
+ (action) => action.available !== import_runtime_client_gql.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
186
186
  ).map((action) => {
187
187
  let available = import_runtime_client_gql.ActionInputAvailability.Enabled;
188
188
  if (action.disabled) {
@@ -359,7 +359,6 @@ var useCopilotRuntimeClient = (options) => {
359
359
  };
360
360
 
361
361
  // src/hooks/use-chat.ts
362
- var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
363
362
  function useChat(options) {
364
363
  const {
365
364
  messages,
@@ -408,7 +407,7 @@ function useChat(options) {
408
407
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
409
408
  setIsLoading(true);
410
409
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
411
- if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql4.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
410
+ if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
412
411
  addErrorToast([
413
412
  new Error(
414
413
  "A message was sent while interrupt is active. This will cause failure on the agent side"
@@ -502,19 +501,16 @@ function useChat(options) {
502
501
  setExtensions(extensionsRef.current);
503
502
  let rawMessagesResponse = value.generateCopilotResponse.messages;
504
503
  ((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
505
- if (ev.name === import_runtime_client_gql4.MetaEventName.LangGraphInterruptEvent) {
504
+ if (ev.name === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent) {
506
505
  let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
507
- try {
508
- eventValue = JSON.parse(eventValue);
509
- } catch (e) {
510
- }
506
+ eventValue = (0, import_shared2.parseJson)(eventValue, eventValue);
511
507
  setLangGraphInterruptAction({
512
508
  event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
513
509
  value: eventValue
514
510
  })
515
511
  });
516
512
  }
517
- if (ev.name === import_runtime_client_gql4.MetaEventName.CopilotKitLangGraphInterruptEvent) {
513
+ if (ev.name === import_runtime_client_gql3.MetaEventName.CopilotKitLangGraphInterruptEvent) {
518
514
  const data = ev.data;
519
515
  rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
520
516
  interruptMessages = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
@@ -595,7 +591,7 @@ function useChat(options) {
595
591
  setMessages([...previousMessages, ...newMessages]);
596
592
  }
597
593
  }
598
- const finalMessages = constructFinalMessages(
594
+ let finalMessages = constructFinalMessages(
599
595
  [...syncedMessages, ...interruptMessages],
600
596
  previousMessages,
601
597
  newMessages
@@ -605,7 +601,7 @@ function useChat(options) {
605
601
  const lastMessages = [];
606
602
  for (let i = finalMessages.length - 1; i >= 0; i--) {
607
603
  const message = finalMessages[i];
608
- if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
604
+ if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql3.MessageStatusCode.Pending) {
609
605
  lastMessages.unshift(message);
610
606
  } else {
611
607
  break;
@@ -613,59 +609,51 @@ function useChat(options) {
613
609
  }
614
610
  for (const message of lastMessages) {
615
611
  setMessages(finalMessages);
616
- const action = actions.find((action2) => action2.name === message.name);
617
- if (action) {
618
- followUp = action.followUp;
619
- let result;
620
- let error = null;
621
- try {
622
- result = yield Promise.race([
623
- onFunctionCall({
624
- messages: previousMessages,
625
- name: message.name,
626
- args: message.arguments
627
- }),
628
- new Promise(
629
- (resolve) => {
630
- var _a2;
631
- return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener(
632
- "abort",
633
- () => resolve("Operation was aborted by the user")
634
- );
635
- }
636
- ),
637
- // if the user stopped generation, we also abort consecutive actions
638
- new Promise((resolve) => {
639
- var _a2;
640
- if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
641
- resolve("Operation was aborted by the user");
642
- }
643
- })
644
- ]);
645
- } catch (e) {
646
- error = e;
647
- addErrorToast([error]);
648
- result = `Failed to execute action ${message.name}. ${error.message}`;
649
- console.error(`Failed to execute action ${message.name}: ${error}`);
650
- }
612
+ const action = actions.find(
613
+ (action2) => action2.name === message.name
614
+ );
615
+ const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
616
+ const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
617
+ followUp = action2 == null ? void 0 : action2.followUp;
618
+ const resultMessage = yield executeAction({
619
+ onFunctionCall,
620
+ previousMessages,
621
+ message: message2,
622
+ chatAbortControllerRef,
623
+ onError: (error) => {
624
+ addErrorToast([error]);
625
+ console.error(`Failed to execute action ${message2.name}: ${error}`);
626
+ }
627
+ });
651
628
  didExecuteAction = true;
652
- const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);
653
- finalMessages.splice(
654
- messageIndex + 1,
655
- 0,
656
- new import_runtime_client_gql3.ResultMessage({
657
- id: "result-" + message.id,
658
- result: import_runtime_client_gql3.ResultMessage.encodeResult(
659
- error ? {
660
- content: result,
661
- error: JSON.parse(
662
- JSON.stringify(error, Object.getOwnPropertyNames(error))
663
- )
664
- } : result
665
- ),
666
- actionExecutionId: message.id,
667
- actionName: message.name
668
- })
629
+ const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
630
+ finalMessages.splice(messageIndex + 1, 0, resultMessage);
631
+ return resultMessage;
632
+ });
633
+ if (action && message.isActionExecutionMessage()) {
634
+ const resultMessage = yield executeActionFromMessage(action, message);
635
+ const pairedFeAction = getPairedFeAction(actions, resultMessage);
636
+ if (pairedFeAction) {
637
+ const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
638
+ name: pairedFeAction.name,
639
+ arguments: (0, import_shared2.parseJson)(resultMessage.result, resultMessage.result),
640
+ status: message.status,
641
+ createdAt: message.createdAt,
642
+ parentMessageId: message.parentMessageId
643
+ });
644
+ yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
645
+ }
646
+ } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
647
+ const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
648
+ name: currentResultMessagePairedFeAction.name,
649
+ arguments: (0, import_shared2.parseJson)(message.result, message.result),
650
+ status: message.status,
651
+ createdAt: message.createdAt
652
+ });
653
+ finalMessages.push(newExecutionMessage);
654
+ yield executeActionFromMessage(
655
+ currentResultMessagePairedFeAction,
656
+ newExecutionMessage
669
657
  );
670
658
  }
671
659
  }
@@ -736,7 +724,7 @@ function useChat(options) {
736
724
  if (!event)
737
725
  return acc;
738
726
  switch (event.name) {
739
- case import_runtime_client_gql4.MetaEventName.LangGraphInterruptEvent:
727
+ case import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent:
740
728
  if (event.response) {
741
729
  setLangGraphInterruptAction(null);
742
730
  const value = event.value;
@@ -812,6 +800,67 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
812
800
  }
813
801
  return finalMessages;
814
802
  }
803
+ function executeAction(_0) {
804
+ return __async(this, arguments, function* ({
805
+ onFunctionCall,
806
+ previousMessages,
807
+ message,
808
+ chatAbortControllerRef,
809
+ onError
810
+ }) {
811
+ let result;
812
+ let error = null;
813
+ try {
814
+ result = yield Promise.race([
815
+ onFunctionCall({
816
+ messages: previousMessages,
817
+ name: message.name,
818
+ args: message.arguments
819
+ }),
820
+ new Promise(
821
+ (resolve) => {
822
+ var _a;
823
+ return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
824
+ "abort",
825
+ () => resolve("Operation was aborted by the user")
826
+ );
827
+ }
828
+ ),
829
+ // if the user stopped generation, we also abort consecutive actions
830
+ new Promise((resolve) => {
831
+ var _a;
832
+ if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
833
+ resolve("Operation was aborted by the user");
834
+ }
835
+ })
836
+ ]);
837
+ } catch (e) {
838
+ onError(e);
839
+ }
840
+ return new import_runtime_client_gql3.ResultMessage({
841
+ id: "result-" + message.id,
842
+ result: import_runtime_client_gql3.ResultMessage.encodeResult(
843
+ error ? {
844
+ content: result,
845
+ error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
846
+ } : result
847
+ ),
848
+ actionExecutionId: message.id,
849
+ actionName: message.name
850
+ });
851
+ });
852
+ }
853
+ function getPairedFeAction(actions, message) {
854
+ let actionName = null;
855
+ if (message.isActionExecutionMessage()) {
856
+ actionName = message.name;
857
+ } else if (message.isResultMessage()) {
858
+ actionName = message.actionName;
859
+ }
860
+ return actions.find(
861
+ (action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
862
+ );
863
+ }
815
864
 
816
865
  // src/components/copilot-provider/copilotkit.tsx
817
866
  var import_react7 = require("react");
@@ -882,9 +931,9 @@ function useCopilotChat(_a = {}) {
882
931
  const makeSystemMessageCallback = (0, import_react8.useCallback)(() => {
883
932
  const systemMessageMaker = makeSystemMessage || defaultSystemMessage;
884
933
  const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
885
- return new import_runtime_client_gql5.TextMessage({
934
+ return new import_runtime_client_gql4.TextMessage({
886
935
  content: systemMessageMaker(contextString, chatInstructions),
887
- role: import_runtime_client_gql5.Role.System
936
+ role: import_runtime_client_gql4.Role.System
888
937
  });
889
938
  }, [getContextString, makeSystemMessage, chatInstructions]);
890
939
  const onCoAgentStateRender = useAsyncCallback(
@@ -1058,10 +1107,9 @@ function useLangGraphInterrupt(action, dependencies) {
1058
1107
  }
1059
1108
  }, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
1060
1109
  (0, import_react9.useEffect)(() => {
1061
- var _a2;
1062
1110
  if (!action)
1063
1111
  return;
1064
- if (hasAction && !isCurrentAction && !((_a2 = action.conditions) == null ? void 0 : _a2.length)) {
1112
+ if (hasAction && !isCurrentAction && !action.enabled) {
1065
1113
  addToast({
1066
1114
  type: "warning",
1067
1115
  message: "An action is already registered for the interrupt event"