@copilotkit/react-core 1.2.0 → 1.2.2-feat-runtime-remote-actions.0

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 (126) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/{chunk-QR4XKQOA.mjs → chunk-326LK7LX.mjs} +2 -2
  3. package/dist/{chunk-EVK5346D.mjs → chunk-3U22BXKC.mjs} +4 -3
  4. package/dist/chunk-3U22BXKC.mjs.map +1 -0
  5. package/dist/{chunk-GSL4ZHUB.mjs → chunk-A37GANOW.mjs} +4 -4
  6. package/dist/chunk-A37GANOW.mjs.map +1 -0
  7. package/dist/chunk-BWYAGPEF.mjs +1 -0
  8. package/dist/{chunk-LB53QWLY.mjs → chunk-CODXG6KU.mjs} +2 -2
  9. package/dist/{chunk-LB7ULLSU.mjs → chunk-J2YXDQHR.mjs} +14 -3
  10. package/dist/chunk-J2YXDQHR.mjs.map +1 -0
  11. package/dist/chunk-Q4TTTAXQ.mjs +87 -0
  12. package/dist/chunk-Q4TTTAXQ.mjs.map +1 -0
  13. package/dist/{chunk-CFCRJA63.mjs → chunk-RBNULK3U.mjs} +39 -5
  14. package/dist/chunk-RBNULK3U.mjs.map +1 -0
  15. package/dist/{chunk-PZOEBYWP.mjs → chunk-RWPGGPW5.mjs} +63 -11
  16. package/dist/chunk-RWPGGPW5.mjs.map +1 -0
  17. package/dist/chunk-STUXJ3BN.mjs +44 -0
  18. package/dist/chunk-STUXJ3BN.mjs.map +1 -0
  19. package/dist/{chunk-HUC6EZVP.mjs → chunk-TCZBK3HZ.mjs} +7 -4
  20. package/dist/chunk-TCZBK3HZ.mjs.map +1 -0
  21. package/dist/{chunk-AIW2RAN2.mjs → chunk-VCEOT4GG.mjs} +35 -6
  22. package/dist/chunk-VCEOT4GG.mjs.map +1 -0
  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 +50 -5
  26. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  27. package/dist/components/copilot-provider/copilotkit.mjs +2 -2
  28. package/dist/components/copilot-provider/index.js +50 -5
  29. package/dist/components/copilot-provider/index.js.map +1 -1
  30. package/dist/components/copilot-provider/index.mjs +2 -2
  31. package/dist/components/index.js +50 -5
  32. package/dist/components/index.js.map +1 -1
  33. package/dist/components/index.mjs +2 -2
  34. package/dist/context/copilot-context.d.ts +21 -2
  35. package/dist/context/copilot-context.js +13 -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.d.ts +2 -0
  39. package/dist/context/index.js +13 -2
  40. package/dist/context/index.js.map +1 -1
  41. package/dist/context/index.mjs +1 -1
  42. package/dist/hooks/index.d.ts +4 -0
  43. package/dist/hooks/index.js +224 -21
  44. package/dist/hooks/index.js.map +1 -1
  45. package/dist/hooks/index.mjs +17 -8
  46. package/dist/hooks/use-chat.d.ts +26 -4
  47. package/dist/hooks/use-chat.js +58 -9
  48. package/dist/hooks/use-chat.js.map +1 -1
  49. package/dist/hooks/use-chat.mjs +1 -1
  50. package/dist/hooks/use-coagent-action.d.ts +5 -0
  51. package/dist/hooks/use-coagent-action.js +156 -0
  52. package/dist/hooks/use-coagent-action.js.map +1 -0
  53. package/dist/hooks/use-coagent-action.mjs +9 -0
  54. package/dist/hooks/use-coagent-action.mjs.map +1 -0
  55. package/dist/hooks/use-coagent.d.ts +27 -0
  56. package/dist/hooks/use-coagent.js +219 -0
  57. package/dist/hooks/use-coagent.js.map +1 -0
  58. package/dist/hooks/use-coagent.mjs +10 -0
  59. package/dist/hooks/use-coagent.mjs.map +1 -0
  60. package/dist/hooks/use-copilot-action.js +15 -4
  61. package/dist/hooks/use-copilot-action.js.map +1 -1
  62. package/dist/hooks/use-copilot-action.mjs +2 -2
  63. package/dist/hooks/use-copilot-chat.js +101 -13
  64. package/dist/hooks/use-copilot-chat.js.map +1 -1
  65. package/dist/hooks/use-copilot-chat.mjs +4 -4
  66. package/dist/hooks/use-copilot-readable.js +13 -2
  67. package/dist/hooks/use-copilot-readable.js.map +1 -1
  68. package/dist/hooks/use-copilot-readable.mjs +2 -2
  69. package/dist/hooks/use-make-copilot-document-readable.js +13 -2
  70. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  71. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  72. package/dist/index.d.ts +4 -0
  73. package/dist/index.js +268 -31
  74. package/dist/index.js.map +1 -1
  75. package/dist/index.mjs +20 -12
  76. package/dist/lib/copilot-task.d.ts +2 -0
  77. package/dist/lib/copilot-task.js +1 -1
  78. package/dist/lib/copilot-task.js.map +1 -1
  79. package/dist/lib/copilot-task.mjs +3 -3
  80. package/dist/lib/index.d.ts +2 -0
  81. package/dist/lib/index.js +1 -1
  82. package/dist/lib/index.js.map +1 -1
  83. package/dist/lib/index.mjs +3 -3
  84. package/dist/types/coagent-action.d.ts +17 -0
  85. package/dist/types/coagent-action.js +19 -0
  86. package/dist/types/coagent-action.js.map +1 -0
  87. package/dist/types/coagent-action.mjs +1 -0
  88. package/dist/types/coagent-action.mjs.map +1 -0
  89. package/dist/types/coagent-state.d.ts +11 -0
  90. package/dist/types/coagent-state.js +19 -0
  91. package/dist/types/coagent-state.js.map +1 -0
  92. package/dist/types/coagent-state.mjs +1 -0
  93. package/dist/types/coagent-state.mjs.map +1 -0
  94. package/dist/utils/extract.d.ts +2 -0
  95. package/dist/utils/extract.js +1 -1
  96. package/dist/utils/extract.js.map +1 -1
  97. package/dist/utils/extract.mjs +3 -3
  98. package/dist/utils/index.d.ts +2 -0
  99. package/dist/utils/index.js +1 -1
  100. package/dist/utils/index.js.map +1 -1
  101. package/dist/utils/index.mjs +3 -3
  102. package/package.json +5 -5
  103. package/src/components/copilot-provider/copilotkit-props.tsx +5 -0
  104. package/src/components/copilot-provider/copilotkit.tsx +45 -3
  105. package/src/context/copilot-context.tsx +39 -2
  106. package/src/hooks/index.ts +2 -0
  107. package/src/hooks/use-chat.ts +111 -11
  108. package/src/hooks/use-coagent-action.ts +44 -0
  109. package/src/hooks/use-coagent.ts +133 -0
  110. package/src/hooks/use-copilot-action.ts +2 -2
  111. package/src/hooks/use-copilot-chat.ts +31 -0
  112. package/src/lib/copilot-task.ts +2 -1
  113. package/src/types/coagent-action.ts +17 -0
  114. package/src/types/coagent-state.ts +9 -0
  115. package/src/utils/extract.ts +7 -2
  116. package/dist/chunk-5JB4B2SV.mjs +0 -1
  117. package/dist/chunk-AIW2RAN2.mjs.map +0 -1
  118. package/dist/chunk-CFCRJA63.mjs.map +0 -1
  119. package/dist/chunk-EVK5346D.mjs.map +0 -1
  120. package/dist/chunk-GSL4ZHUB.mjs.map +0 -1
  121. package/dist/chunk-HUC6EZVP.mjs.map +0 -1
  122. package/dist/chunk-LB7ULLSU.mjs.map +0 -1
  123. package/dist/chunk-PZOEBYWP.mjs.map +0 -1
  124. /package/dist/{chunk-QR4XKQOA.mjs.map → chunk-326LK7LX.mjs.map} +0 -0
  125. /package/dist/{chunk-5JB4B2SV.mjs.map → chunk-BWYAGPEF.mjs.map} +0 -0
  126. /package/dist/{chunk-LB53QWLY.mjs.map → chunk-CODXG6KU.mjs.map} +0 -0
@@ -61,7 +61,12 @@ var emptyCopilotContext = {
61
61
  },
62
62
  removeAction: () => {
63
63
  },
64
- chatComponentsCache: { current: {} },
64
+ coagentActions: {},
65
+ setCoagentAction: () => {
66
+ },
67
+ removeCoagentAction: () => {
68
+ },
69
+ chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
65
70
  getContextString: (documents, categories) => returnAndThrowInDebug(""),
66
71
  addContext: () => "",
67
72
  removeContext: () => {
@@ -94,7 +99,13 @@ var emptyCopilotContext = {
94
99
  },
95
100
  removeChatSuggestionConfiguration: () => {
96
101
  },
97
- showDevConsole: "auto"
102
+ showDevConsole: "auto",
103
+ coagentStates: {},
104
+ setCoagentStates: () => {
105
+ },
106
+ agentSession: null,
107
+ setAgentSession: () => {
108
+ }
98
109
  };
99
110
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
100
111
  function useCopilotContext() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/copilot-context.tsx"],"sourcesContent":["import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { ActionRenderProps, FrontendAction } 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\";\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 = (props: ActionRenderProps<any>) => string | JSX.Element;\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 chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\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 // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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\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};\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 return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AA+GlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,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,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,EAE9B,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,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAClB;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
1
+ {"version":3,"sources":["../../src/context/copilot-context.tsx"],"sourcesContent":["import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { ActionRenderProps, FrontendAction } 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 { CoagentAction, CoagentActionRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\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 = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoagentActionRenderProps<any>,\n) => string | JSX.Element;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coagentActions: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\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 coagentActions: Record<string, CoagentAction<any>>;\n setCoagentAction: (id: string, action: CoagentAction<any>) => void;\n removeCoagentAction: (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 // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coagentActions: {},\n setCoagentAction: () => {},\n removeCoagentAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coagentActions: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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\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\n agentSession: null,\n setAgentSession: () => {},\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 return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AA2IlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,gBAAgB,CAAC;AAAA,EACjB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,qBAAqB,MAAM;AAAA,EAAC;AAAA,EAE5B,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,EAAE,EAAE;AAAA,EACpE,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,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,EAE9B,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,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EAEzB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  CopilotContext,
3
3
  useCopilotContext
4
- } from "../chunk-LB7ULLSU.mjs";
4
+ } from "../chunk-J2YXDQHR.mjs";
5
5
  import "../chunk-SKC7AJIV.mjs";
6
6
  export {
7
7
  CopilotContext,
@@ -6,3 +6,5 @@ import 'react';
6
6
  import '../hooks/use-tree.js';
7
7
  import '../types/document-pointer.js';
8
8
  import '../types/chat-suggestion-configuration.js';
9
+ import '../types/coagent-action.js';
10
+ import '../types/coagent-state.js';
@@ -63,7 +63,12 @@ var emptyCopilotContext = {
63
63
  },
64
64
  removeAction: () => {
65
65
  },
66
- chatComponentsCache: { current: {} },
66
+ coagentActions: {},
67
+ setCoagentAction: () => {
68
+ },
69
+ removeCoagentAction: () => {
70
+ },
71
+ chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
67
72
  getContextString: (documents, categories) => returnAndThrowInDebug(""),
68
73
  addContext: () => "",
69
74
  removeContext: () => {
@@ -96,7 +101,13 @@ var emptyCopilotContext = {
96
101
  },
97
102
  removeChatSuggestionConfiguration: () => {
98
103
  },
99
- showDevConsole: "auto"
104
+ showDevConsole: "auto",
105
+ coagentStates: {},
106
+ setCoagentStates: () => {
107
+ },
108
+ agentSession: null,
109
+ setAgentSession: () => {
110
+ }
100
111
  };
101
112
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
102
113
  function useCopilotContext() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport type { CopilotContextParams } from \"./copilot-context\";\nexport type { CopilotApiConfig } from \"./copilot-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { ActionRenderProps, FrontendAction } 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\";\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 = (props: ActionRenderProps<any>) => string | JSX.Element;\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 chatComponentsCache: React.RefObject<Record<string, InChatRenderFunction | string>>;\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 // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n chatComponentsCache: { current: {} },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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\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};\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 return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAAkB;AA+GlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,EAAE,SAAS,CAAC,EAAE;AAAA,EACnC,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,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,EAE9B,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,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAClB;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
1
+ {"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport type { CopilotContextParams } from \"./copilot-context\";\nexport type { CopilotApiConfig } from \"./copilot-context\";\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { ActionRenderProps, FrontendAction } 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 { CoagentAction, CoagentActionRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\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 = (props: ActionRenderProps<any>) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoagentActionRenderProps<any>,\n) => string | JSX.Element;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coagentActions: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\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 coagentActions: Record<string, CoagentAction<any>>;\n setCoagentAction: (id: string, action: CoagentAction<any>) => void;\n removeCoagentAction: (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 // chat\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\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 agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coagentActions: {},\n setCoagentAction: () => {},\n removeCoagentAction: () => {},\n\n chatComponentsCache: { current: { actions: {}, coagentActions: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n messages: [],\n setMessages: () => returnAndThrowInDebug([]),\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\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\n agentSession: null,\n setAgentSession: () => {},\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 return value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,mBAAkB;AA2IlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,gBAAgB,CAAC;AAAA,EACjB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,qBAAqB,MAAM;AAAA,EAAC;AAAA,EAE5B,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,EAAE,EAAE;AAAA,EACpE,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,UAAU,CAAC;AAAA,EACX,aAAa,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAE3C,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,EAE9B,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,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EAEzB,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAC1B;AAEO,IAAM,iBAAiB,aAAAA,QAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,aAAAA,QAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,OAAa;AAC7C,QAAM,IAAI,MAAM,uEAAuE;AACvF,SAAO;AACT;","names":["React"]}
@@ -2,7 +2,7 @@ import "../chunk-VNRDQJXW.mjs";
2
2
  import {
3
3
  CopilotContext,
4
4
  useCopilotContext
5
- } from "../chunk-LB7ULLSU.mjs";
5
+ } from "../chunk-J2YXDQHR.mjs";
6
6
  import "../chunk-SKC7AJIV.mjs";
7
7
  export {
8
8
  CopilotContext,
@@ -1,14 +1,18 @@
1
1
  export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './use-copilot-chat.js';
2
2
  export { useCopilotAction } from './use-copilot-action.js';
3
+ export { useCoAgentAction } from './use-coagent-action.js';
3
4
  export { useMakeCopilotDocumentReadable } from './use-make-copilot-document-readable.js';
4
5
  export { UseChatHelpers } from './use-chat.js';
5
6
  export { useCopilotReadable } from './use-copilot-readable.js';
7
+ export { useCoAgent } from './use-coagent.js';
6
8
  import '@copilotkit/runtime-client-gql';
7
9
  import '../types/system-message.js';
8
10
  import '../types/frontend-action.js';
9
11
  import '@copilotkit/shared';
10
12
  import 'react';
13
+ import '../types/coagent-action.js';
11
14
  import '../types/document-pointer.js';
12
15
  import '../context/copilot-context.js';
13
16
  import './use-tree.js';
14
17
  import '../types/chat-suggestion-configuration.js';
18
+ import '../types/coagent-state.js';
@@ -79,6 +79,8 @@ var __async = (__this, __arguments, generator) => {
79
79
  // src/hooks/index.ts
80
80
  var hooks_exports = {};
81
81
  __export(hooks_exports, {
82
+ useCoAgent: () => useCoAgent,
83
+ useCoAgentAction: () => useCoAgentAction,
82
84
  useCopilotAction: () => useCopilotAction,
83
85
  useCopilotChat: () => useCopilotChat,
84
86
  useCopilotReadable: () => useCopilotReadable,
@@ -97,7 +99,12 @@ var emptyCopilotContext = {
97
99
  },
98
100
  removeAction: () => {
99
101
  },
100
- chatComponentsCache: { current: {} },
102
+ coagentActions: {},
103
+ setCoagentAction: () => {
104
+ },
105
+ removeCoagentAction: () => {
106
+ },
107
+ chatComponentsCache: { current: { actions: {}, coagentActions: {} } },
101
108
  getContextString: (documents, categories) => returnAndThrowInDebug(""),
102
109
  addContext: () => "",
103
110
  removeContext: () => {
@@ -130,7 +137,13 @@ var emptyCopilotContext = {
130
137
  },
131
138
  removeChatSuggestionConfiguration: () => {
132
139
  },
133
- showDevConsole: "auto"
140
+ showDevConsole: "auto",
141
+ coagentStates: {},
142
+ setCoagentStates: () => {
143
+ },
144
+ agentSession: null,
145
+ setAgentSession: () => {
146
+ }
134
147
  };
135
148
  var CopilotContext = import_react.default.createContext(emptyCopilotContext);
136
149
  function useCopilotContext() {
@@ -162,7 +175,12 @@ function useChat(options) {
162
175
  initialMessages,
163
176
  isLoading,
164
177
  actions,
165
- onFunctionCall
178
+ onFunctionCall,
179
+ onCoagentAction,
180
+ setCoagentStates,
181
+ coagentStates,
182
+ agentSession,
183
+ setAgentSession
166
184
  } = options;
167
185
  const abortControllerRef = (0, import_react2.useRef)();
168
186
  const threadIdRef = (0, import_react2.useRef)(null);
@@ -191,7 +209,7 @@ function useChat(options) {
191
209
  const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
192
210
  const stream = import_runtime_client_gql.CopilotRuntimeClient.asStream(
193
211
  runtimeClient.generateCopilotResponse({
194
- data: __spreadProps(__spreadValues({
212
+ data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
195
213
  frontend: {
196
214
  actions: actions.map((action) => ({
197
215
  name: action.name,
@@ -202,7 +220,7 @@ function useChat(options) {
202
220
  },
203
221
  threadId: threadIdRef.current,
204
222
  runId: runIdRef.current,
205
- messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)(messagesWithContext)
223
+ messages: (0, import_runtime_client_gql.convertMessagesToGqlInput)((0, import_runtime_client_gql.filterAgentStateMessages)(messagesWithContext))
206
224
  }, copilotConfig.cloud ? {
207
225
  cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
208
226
  guardrails: {
@@ -216,6 +234,13 @@ function useChat(options) {
216
234
  metadata: {
217
235
  requestType: import_runtime_client_gql.CopilotRequestType.Chat
218
236
  }
237
+ }), agentSession ? {
238
+ agentSession
239
+ } : {}), {
240
+ agentStates: Object.values(coagentStates).map((state) => ({
241
+ agentName: state.name,
242
+ state: JSON.stringify(state.state)
243
+ }))
219
244
  }),
220
245
  properties: copilotConfig.properties,
221
246
  signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
@@ -223,7 +248,8 @@ function useChat(options) {
223
248
  );
224
249
  const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
225
250
  const reader = stream.getReader();
226
- let results = {};
251
+ let actionResults = {};
252
+ let executedCoagentActions = [];
227
253
  try {
228
254
  while (true) {
229
255
  const { done, value } = yield reader.read();
@@ -235,7 +261,9 @@ function useChat(options) {
235
261
  }
236
262
  threadIdRef.current = value.generateCopilotResponse.threadId || null;
237
263
  runIdRef.current = value.generateCopilotResponse.runId || null;
238
- const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(value.generateCopilotResponse.messages);
264
+ const messages2 = (0, import_runtime_client_gql.convertGqlOutputToMessages)(
265
+ (0, import_runtime_client_gql.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
266
+ );
239
267
  if (messages2.length === 0) {
240
268
  continue;
241
269
  }
@@ -251,7 +279,7 @@ function useChat(options) {
251
279
  for (const message of messages2) {
252
280
  newMessages.push(message);
253
281
  if (message instanceof import_runtime_client_gql.ActionExecutionMessage && message.status.code !== import_runtime_client_gql.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
254
- if (!(message.id in results)) {
282
+ if (!(message.id in actionResults)) {
255
283
  if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
256
284
  break;
257
285
  }
@@ -260,16 +288,50 @@ function useChat(options) {
260
288
  name: message.name,
261
289
  args: message.arguments
262
290
  });
263
- results[message.id] = result;
291
+ actionResults[message.id] = result;
264
292
  }
265
293
  newMessages.push(
266
294
  new import_runtime_client_gql.ResultMessage({
267
- result: import_runtime_client_gql.ResultMessage.encodeResult(results[message.id]),
295
+ result: import_runtime_client_gql.ResultMessage.encodeResult(actionResults[message.id]),
268
296
  actionExecutionId: message.id,
269
297
  actionName: message.name
270
298
  })
271
299
  );
272
300
  }
301
+ if (message instanceof import_runtime_client_gql.AgentStateMessage && !message.active && !executedCoagentActions.includes(message.id) && onCoagentAction) {
302
+ if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
303
+ break;
304
+ }
305
+ yield onCoagentAction({
306
+ name: message.agentName,
307
+ nodeName: message.nodeName,
308
+ state: message.state
309
+ });
310
+ executedCoagentActions.push(message.id);
311
+ }
312
+ }
313
+ const lastAgentStateMessage = [...messages2].reverse().find((message) => message instanceof import_runtime_client_gql.AgentStateMessage);
314
+ if (lastAgentStateMessage) {
315
+ if (lastAgentStateMessage.running) {
316
+ setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
317
+ [lastAgentStateMessage.agentName]: {
318
+ name: lastAgentStateMessage.agentName,
319
+ state: lastAgentStateMessage.state,
320
+ running: lastAgentStateMessage.running,
321
+ active: lastAgentStateMessage.active,
322
+ threadId: lastAgentStateMessage.threadId,
323
+ nodeName: lastAgentStateMessage.nodeName,
324
+ runId: lastAgentStateMessage.runId
325
+ }
326
+ }));
327
+ setAgentSession({
328
+ threadId: lastAgentStateMessage.threadId,
329
+ agentName: lastAgentStateMessage.agentName,
330
+ nodeName: lastAgentStateMessage.nodeName
331
+ });
332
+ } else {
333
+ setAgentSession(null);
334
+ }
273
335
  }
274
336
  }
275
337
  if (newMessages.length > 0) {
@@ -278,7 +340,7 @@ function useChat(options) {
278
340
  }
279
341
  if (
280
342
  // if we have client side results
281
- Object.values(results).length || // or the last message we received is a result
343
+ Object.values(actionResults).length || // or the last message we received is a result
282
344
  newMessages.length && newMessages[newMessages.length - 1] instanceof import_runtime_client_gql.ResultMessage
283
345
  ) {
284
346
  yield new Promise((resolve) => setTimeout(resolve, 10));
@@ -347,7 +409,12 @@ function useCopilotChat(_a = {}) {
347
409
  isLoading,
348
410
  setIsLoading,
349
411
  chatInstructions,
350
- actions
412
+ actions,
413
+ coagentStates,
414
+ setCoagentStates,
415
+ coagentActions,
416
+ agentSession,
417
+ setAgentSession
351
418
  } = useCopilotContext();
352
419
  const latestGetContextString = useUpdatedRef(getContextString);
353
420
  const deleteMessage = (0, import_react4.useCallback)(
@@ -364,16 +431,39 @@ function useCopilotChat(_a = {}) {
364
431
  role: import_runtime_client_gql2.Role.System
365
432
  });
366
433
  }, [getContextString, makeSystemMessage, chatInstructions]);
434
+ const onCoagentAction = (0, import_react4.useCallback)(
435
+ (args) => __async(this, null, function* () {
436
+ var _a2;
437
+ const { name, nodeName, state } = args;
438
+ let action = Object.values(coagentActions).find(
439
+ (action2) => action2.name === name && action2.nodeName === nodeName
440
+ );
441
+ if (!action) {
442
+ action = Object.values(coagentActions).find(
443
+ (action2) => action2.name === name && !action2.nodeName
444
+ );
445
+ }
446
+ if (action) {
447
+ yield (_a2 = action.handler) == null ? void 0 : _a2.call(action, { state, nodeName });
448
+ }
449
+ }),
450
+ [coagentActions]
451
+ );
367
452
  const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
368
453
  actions: Object.values(actions),
369
454
  copilotConfig: copilotApiConfig,
370
455
  initialMessages: options.initialMessages || [],
371
456
  onFunctionCall: getFunctionCallHandler(),
457
+ onCoagentAction,
372
458
  messages,
373
459
  setMessages,
374
460
  makeSystemMessageCallback,
375
461
  isLoading,
376
- setIsLoading
462
+ setIsLoading,
463
+ coagentStates,
464
+ setCoagentStates,
465
+ agentSession,
466
+ setAgentSession
377
467
  }));
378
468
  const latestAppend = useUpdatedRef(append);
379
469
  const latestAppendFunc = (0, import_react4.useCallback)(
@@ -456,7 +546,7 @@ function useCopilotAction(action, dependencies) {
456
546
  actions[idRef.current].handler = action.handler;
457
547
  if (typeof action.render === "function") {
458
548
  if (chatComponentsCache.current !== null) {
459
- chatComponentsCache.current[action.name] = action.render;
549
+ chatComponentsCache.current.actions[action.name] = action.render;
460
550
  }
461
551
  }
462
552
  }
@@ -467,7 +557,7 @@ function useCopilotAction(action, dependencies) {
467
557
  }
468
558
  setAction(idRef.current, action);
469
559
  if (chatComponentsCache.current !== null && action.render !== void 0) {
470
- chatComponentsCache.current[action.name] = action.render;
560
+ chatComponentsCache.current.actions[action.name] = action.render;
471
561
  }
472
562
  return () => {
473
563
  removeAction(idRef.current);
@@ -488,12 +578,48 @@ function useCopilotAction(action, dependencies) {
488
578
  ]);
489
579
  }
490
580
 
491
- // src/hooks/use-make-copilot-document-readable.ts
581
+ // src/hooks/use-coagent-action.ts
492
582
  var import_react6 = require("react");
583
+ var import_shared4 = require("@copilotkit/shared");
584
+ function useCoAgentAction(action, dependencies) {
585
+ const { setCoagentAction, removeCoagentAction, coagentActions, chatComponentsCache } = (0, import_react6.useContext)(CopilotContext);
586
+ const idRef = (0, import_react6.useRef)((0, import_shared4.randomId)());
587
+ const key = `${action.name}-${action.nodeName || "global"}`;
588
+ if (dependencies === void 0) {
589
+ if (coagentActions[idRef.current]) {
590
+ coagentActions[idRef.current].handler = action.handler;
591
+ if (typeof action.render === "function") {
592
+ if (chatComponentsCache.current !== null) {
593
+ chatComponentsCache.current.coagentActions[key] = action.render;
594
+ }
595
+ }
596
+ }
597
+ }
598
+ (0, import_react6.useEffect)(() => {
599
+ setCoagentAction(idRef.current, action);
600
+ if (chatComponentsCache.current !== null && action.render !== void 0) {
601
+ chatComponentsCache.current.coagentActions[key] = action.render;
602
+ }
603
+ return () => {
604
+ removeCoagentAction(idRef.current);
605
+ };
606
+ }, [
607
+ setCoagentAction,
608
+ removeCoagentAction,
609
+ action.name,
610
+ // include render only if it's a string
611
+ typeof action.render === "string" ? action.render : void 0,
612
+ // dependencies set by the developer
613
+ ...dependencies || []
614
+ ]);
615
+ }
616
+
617
+ // src/hooks/use-make-copilot-document-readable.ts
618
+ var import_react7 = require("react");
493
619
  function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
494
620
  const { addDocumentContext, removeDocumentContext } = useCopilotContext();
495
- const idRef = (0, import_react6.useRef)();
496
- (0, import_react6.useEffect)(() => {
621
+ const idRef = (0, import_react7.useRef)();
622
+ (0, import_react7.useEffect)(() => {
497
623
  const id = addDocumentContext(document, categories);
498
624
  idRef.current = id;
499
625
  return () => {
@@ -504,16 +630,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
504
630
  }
505
631
 
506
632
  // src/hooks/use-copilot-readable.ts
507
- var import_react7 = require("react");
633
+ var import_react8 = require("react");
508
634
  function convertToJSON(description, value) {
509
635
  return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
510
636
  }
511
637
  function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
512
638
  const { addContext, removeContext } = useCopilotContext();
513
- const idRef = (0, import_react7.useRef)();
639
+ const idRef = (0, import_react8.useRef)();
514
640
  convert = convert || convertToJSON;
515
641
  const information = convert(description, value);
516
- (0, import_react7.useEffect)(() => {
642
+ (0, import_react8.useEffect)(() => {
517
643
  const id = addContext(information, parentId, categories);
518
644
  idRef.current = id;
519
645
  return () => {
@@ -522,8 +648,85 @@ function useCopilotReadable({ description, value, parentId, categories, convert
522
648
  }, [information, parentId, addContext, removeContext, ...dependencies || []]);
523
649
  return idRef.current;
524
650
  }
651
+
652
+ // src/hooks/use-coagent.ts
653
+ var import_react9 = require("react");
654
+ function useCoAgent(options) {
655
+ const isExternalStateManagement = (options2) => {
656
+ return "state" in options2 && "setState" in options2;
657
+ };
658
+ const { name } = options;
659
+ const isInternalStateManagementWithInitial = (options2) => {
660
+ return "initialState" in options2;
661
+ };
662
+ const { coagentStates, setCoagentStates } = useCopilotContext();
663
+ const getCoagentState = (coagentStates2, name2) => {
664
+ if (coagentStates2[name2]) {
665
+ return coagentStates2[name2];
666
+ } else {
667
+ return {
668
+ name: name2,
669
+ state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
670
+ running: false,
671
+ active: false,
672
+ threadId: void 0,
673
+ nodeName: void 0,
674
+ runId: void 0
675
+ };
676
+ }
677
+ };
678
+ const setState = (newState) => {
679
+ setCoagentStates((prevAgentStates) => {
680
+ let coagentState2 = getCoagentState(prevAgentStates, name);
681
+ const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
682
+ return __spreadProps(__spreadValues({}, prevAgentStates), {
683
+ [name]: __spreadProps(__spreadValues({}, coagentState2), {
684
+ state: updatedState
685
+ })
686
+ });
687
+ });
688
+ };
689
+ const coagentState = getCoagentState(coagentStates, name);
690
+ const state = isExternalStateManagement(options) ? options.state : coagentState.state;
691
+ (0, import_react9.useEffect)(() => {
692
+ if (isExternalStateManagement(options)) {
693
+ setState(options.state);
694
+ } else if (coagentStates[name] === void 0) {
695
+ setState(options.initialState === void 0 ? {} : options.initialState);
696
+ }
697
+ }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
698
+ return {
699
+ name,
700
+ nodeName: coagentState.nodeName,
701
+ state,
702
+ setState,
703
+ running: coagentState.running,
704
+ start: () => {
705
+ startAgent(name);
706
+ },
707
+ stop: () => {
708
+ stopAgent(name);
709
+ }
710
+ };
711
+ }
712
+ function startAgent(name) {
713
+ const { setAgentSession } = useCopilotContext();
714
+ setAgentSession({
715
+ agentName: name
716
+ });
717
+ }
718
+ function stopAgent(name) {
719
+ const { agentSession, setAgentSession } = useCopilotContext();
720
+ if (agentSession && agentSession.agentName === name) {
721
+ setAgentSession(null);
722
+ } else {
723
+ console.warn(`No agent session found for ${name}`);
724
+ }
725
+ }
525
726
  // Annotate the CommonJS export names for ESM import in node:
526
727
  0 && (module.exports = {
728
+ useCoAgent,
729
+ useCoAgentAction,
527
730
  useCopilotAction,
528
731
  useCopilotChat,
529
732
  useCopilotReadable,