@copilotkit/react-core 1.6.0-next.9 → 1.7.0-next.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 (139) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/{chunk-5M47BILE.mjs → chunk-37LXOL6B.mjs} +2 -2
  3. package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
  4. package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
  5. package/dist/{chunk-JFCNSGNU.mjs → chunk-4X4XFBC6.mjs} +3 -3
  6. package/dist/{chunk-F7O6L7C3.mjs → chunk-7XNZHQWJ.mjs} +2 -2
  7. package/dist/{chunk-7HWSAEOY.mjs → chunk-AT4ALBK4.mjs} +13 -4
  8. package/dist/{chunk-7HWSAEOY.mjs.map → chunk-AT4ALBK4.mjs.map} +1 -1
  9. package/dist/{chunk-MPFP6ANM.mjs → chunk-CJTSYEYG.mjs} +3 -3
  10. package/dist/chunk-CQPYJIBH.mjs +1 -0
  11. package/dist/{chunk-ALW2T2LL.mjs → chunk-FUO5LKSJ.mjs} +114 -60
  12. package/dist/chunk-FUO5LKSJ.mjs.map +1 -0
  13. package/dist/{chunk-XOHLZIZK.mjs → chunk-JHPCDBBM.mjs} +2 -2
  14. package/dist/{chunk-PR5R5TTF.mjs → chunk-JMFYGW35.mjs} +2 -2
  15. package/dist/{chunk-T2EFA3D5.mjs → chunk-NY3BUYYZ.mjs} +2 -2
  16. package/dist/chunk-O3IIH54P.mjs +24 -0
  17. package/dist/chunk-O3IIH54P.mjs.map +1 -0
  18. package/dist/{chunk-7YXUCWXF.mjs → chunk-PRWPZCKZ.mjs} +10 -8
  19. package/dist/chunk-PRWPZCKZ.mjs.map +1 -0
  20. package/dist/{chunk-ZM56S3LJ.mjs → chunk-PTSWFERP.mjs} +3 -1
  21. package/dist/chunk-PTSWFERP.mjs.map +1 -0
  22. package/dist/{chunk-ADTDNMYG.mjs → chunk-RPSMTOER.mjs} +3 -3
  23. package/dist/{chunk-2F6RYBYS.mjs → chunk-YI7LPACV.mjs} +3 -3
  24. package/dist/{chunk-QJPWWVJQ.mjs → chunk-ZNWM2EVT.mjs} +4 -4
  25. package/dist/components/copilot-provider/copilot-messages.js +2 -0
  26. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  27. package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
  28. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -1
  29. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  30. package/dist/components/copilot-provider/copilotkit.js +5 -1
  31. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  32. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  33. package/dist/components/copilot-provider/index.d.ts +1 -1
  34. package/dist/components/copilot-provider/index.js +5 -1
  35. package/dist/components/copilot-provider/index.js.map +1 -1
  36. package/dist/components/copilot-provider/index.mjs +4 -4
  37. package/dist/components/index.d.ts +1 -1
  38. package/dist/components/index.js +5 -1
  39. package/dist/components/index.js.map +1 -1
  40. package/dist/components/index.mjs +4 -4
  41. package/dist/context/copilot-context.d.ts +1 -1
  42. package/dist/context/copilot-context.js +2 -0
  43. package/dist/context/copilot-context.js.map +1 -1
  44. package/dist/context/copilot-context.mjs +1 -1
  45. package/dist/context/index.d.ts +1 -1
  46. package/dist/context/index.js +2 -0
  47. package/dist/context/index.js.map +1 -1
  48. package/dist/context/index.mjs +1 -1
  49. package/dist/{copilot-context-9ae8990b.d.ts → copilot-context-c402f48d.d.ts} +2 -0
  50. package/dist/hooks/index.d.ts +2 -1
  51. package/dist/hooks/index.js +159 -79
  52. package/dist/hooks/index.js.map +1 -1
  53. package/dist/hooks/index.mjs +20 -16
  54. package/dist/hooks/use-chat.d.ts +1 -1
  55. package/dist/hooks/use-chat.js +113 -62
  56. package/dist/hooks/use-chat.js.map +1 -1
  57. package/dist/hooks/use-chat.mjs +2 -2
  58. package/dist/hooks/use-coagent-state-render.js +2 -0
  59. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  60. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  61. package/dist/hooks/use-coagent.d.ts +1 -1
  62. package/dist/hooks/use-coagent.js +121 -68
  63. package/dist/hooks/use-coagent.js.map +1 -1
  64. package/dist/hooks/use-coagent.mjs +8 -8
  65. package/dist/hooks/use-copilot-action.js +2 -0
  66. package/dist/hooks/use-copilot-action.js.map +1 -1
  67. package/dist/hooks/use-copilot-action.mjs +2 -2
  68. package/dist/hooks/use-copilot-additional-instructions.d.ts +26 -0
  69. package/dist/hooks/use-copilot-additional-instructions.js +162 -0
  70. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -0
  71. package/dist/hooks/use-copilot-additional-instructions.mjs +9 -0
  72. package/dist/hooks/use-copilot-additional-instructions.mjs.map +1 -0
  73. package/dist/hooks/use-copilot-authenticated-action.js +2 -0
  74. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  75. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  76. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  77. package/dist/hooks/use-copilot-chat.js +119 -66
  78. package/dist/hooks/use-copilot-chat.js.map +1 -1
  79. package/dist/hooks/use-copilot-chat.mjs +7 -7
  80. package/dist/hooks/use-copilot-readable.d.ts +5 -1
  81. package/dist/hooks/use-copilot-readable.js +13 -2
  82. package/dist/hooks/use-copilot-readable.js.map +1 -1
  83. package/dist/hooks/use-copilot-readable.mjs +2 -2
  84. package/dist/hooks/use-langgraph-interrupt-render.js +2 -0
  85. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  86. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  87. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  88. package/dist/hooks/use-langgraph-interrupt.js +121 -68
  89. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  90. package/dist/hooks/use-langgraph-interrupt.mjs +8 -8
  91. package/dist/hooks/use-make-copilot-document-readable.js +2 -0
  92. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  93. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  94. package/dist/index.d.ts +2 -1
  95. package/dist/index.js +168 -86
  96. package/dist/index.js.map +1 -1
  97. package/dist/index.mjs +21 -17
  98. package/dist/lib/copilot-task.d.ts +1 -1
  99. package/dist/lib/copilot-task.js +1 -1
  100. package/dist/lib/copilot-task.js.map +1 -1
  101. package/dist/lib/copilot-task.mjs +6 -6
  102. package/dist/lib/index.d.ts +1 -1
  103. package/dist/lib/index.js +1 -1
  104. package/dist/lib/index.js.map +1 -1
  105. package/dist/lib/index.mjs +6 -6
  106. package/dist/types/frontend-action.d.ts +2 -1
  107. package/dist/types/frontend-action.js +1 -1
  108. package/dist/types/frontend-action.js.map +1 -1
  109. package/dist/types/frontend-action.mjs +1 -1
  110. package/dist/types/interrupt-action.d.ts +1 -1
  111. package/dist/utils/extract.d.ts +1 -1
  112. package/dist/utils/extract.js.map +1 -1
  113. package/dist/utils/extract.mjs +4 -4
  114. package/dist/utils/index.d.ts +1 -1
  115. package/dist/utils/index.js.map +1 -1
  116. package/dist/utils/index.mjs +4 -4
  117. package/package.json +5 -5
  118. package/src/components/copilot-provider/copilotkit.tsx +3 -1
  119. package/src/context/copilot-context.tsx +6 -0
  120. package/src/hooks/index.ts +1 -0
  121. package/src/hooks/use-chat.ts +133 -58
  122. package/src/hooks/use-copilot-additional-instructions.ts +85 -0
  123. package/src/hooks/use-copilot-readable.ts +16 -2
  124. package/src/types/frontend-action.ts +5 -2
  125. package/dist/chunk-7YXUCWXF.mjs.map +0 -1
  126. package/dist/chunk-ALW2T2LL.mjs.map +0 -1
  127. package/dist/chunk-IGLITGLC.mjs +0 -1
  128. package/dist/chunk-ZM56S3LJ.mjs.map +0 -1
  129. /package/dist/{chunk-5M47BILE.mjs.map → chunk-37LXOL6B.mjs.map} +0 -0
  130. /package/dist/{chunk-JFCNSGNU.mjs.map → chunk-4X4XFBC6.mjs.map} +0 -0
  131. /package/dist/{chunk-F7O6L7C3.mjs.map → chunk-7XNZHQWJ.mjs.map} +0 -0
  132. /package/dist/{chunk-MPFP6ANM.mjs.map → chunk-CJTSYEYG.mjs.map} +0 -0
  133. /package/dist/{chunk-IGLITGLC.mjs.map → chunk-CQPYJIBH.mjs.map} +0 -0
  134. /package/dist/{chunk-XOHLZIZK.mjs.map → chunk-JHPCDBBM.mjs.map} +0 -0
  135. /package/dist/{chunk-PR5R5TTF.mjs.map → chunk-JMFYGW35.mjs.map} +0 -0
  136. /package/dist/{chunk-T2EFA3D5.mjs.map → chunk-NY3BUYYZ.mjs.map} +0 -0
  137. /package/dist/{chunk-ADTDNMYG.mjs.map → chunk-RPSMTOER.mjs.map} +0 -0
  138. /package/dist/{chunk-2F6RYBYS.mjs.map → chunk-YI7LPACV.mjs.map} +0 -0
  139. /package/dist/{chunk-QJPWWVJQ.mjs.map → chunk-ZNWM2EVT.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\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;AAAA,IAAAA,gBAAkC;;;ACMlC,mBAAkB;AA4MlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AA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AAAA,EAAC;AAAA,EACpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EACjB,wBAAwB,EAAE,SAAS,KAAK;AAAA,EACxC,iBAAiB,CAAC;AAAA,EAClB,YAAY,CAAC;AAAA,EACb,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,0BAA0B;AAAA,EAC1B,6BAA6B,MAAM;AAAA,EACnC,gCAAgC,MAAM;AACxC;AAEO,IAAM,iBAAiB,aAAAC,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,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;;;ADrRO,SAAS,+BACd,UACA,YACA,eAAsB,CAAC,GACH;AACpB,QAAM,EAAE,oBAAoB,sBAAsB,IAAI,kBAAkB;AACxE,QAAM,YAAQ,sBAAe;AAE7B,+BAAU,MAAM;AACd,UAAM,KAAK,mBAAmB,UAAU,UAAU;AAClD,UAAM,UAAU;AAEhB,WAAO,MAAM;AACX,4BAAsB,EAAE;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":["import_react","React"]}
1
+ {"version":3,"sources":["../../src/hooks/use-make-copilot-document-readable.ts","../../src/context/copilot-context.tsx"],"sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { useCopilotContext } from \"../context/copilot-context\";\nimport { DocumentPointer } from \"../types\";\n\n/**\n * Makes a document readable by Copilot.\n * @param document The document to make readable.\n * @param categories The categories to associate with the document.\n * @param dependencies The dependencies to use for the effect.\n * @returns The id of the document.\n */\nexport function useMakeCopilotDocumentReadable(\n document: DocumentPointer,\n categories?: string[],\n dependencies: any[] = [],\n): string | undefined {\n const { addDocumentContext, removeDocumentContext } = useCopilotContext();\n const idRef = useRef<string>();\n\n useEffect(() => {\n const id = addDocumentContext(document, categories);\n idRef.current = id;\n\n return () => {\n removeDocumentContext(id);\n };\n }, [addDocumentContext, removeDocumentContext, ...dependencies]);\n\n return idRef.current;\n}\n","import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\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 additionalInstructions?: string[];\n setAdditionalInstructions: 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 additionalInstructions: [],\n setAdditionalInstructions: () => 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 {\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AC1B;AAAA,EACF,GAAG,CAAC,oBAAoB,uBAAuB,GAAG,YAAY,CAAC;AAE/D,SAAO,MAAM;AACf;","names":["import_react","React"]}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useMakeCopilotDocumentReadable
3
- } from "../chunk-XOHLZIZK.mjs";
4
- import "../chunk-ZM56S3LJ.mjs";
3
+ } from "../chunk-JHPCDBBM.mjs";
4
+ import "../chunk-PTSWFERP.mjs";
5
5
  import "../chunk-SKC7AJIV.mjs";
6
6
  export {
7
7
  useMakeCopilotDocumentReadable
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { CopilotKit, defaultCopilotContextCategories } from './components/copilot-provider/copilotkit.js';
2
2
  export { CopilotKitProps } from './components/copilot-provider/copilotkit-props.js';
3
- export { b as CoagentInChatRenderFunction, c as CopilotApiConfig, C as CopilotContext, a as CopilotContextParams, u as useCopilotContext } from './copilot-context-9ae8990b.js';
3
+ export { b as CoagentInChatRenderFunction, c as CopilotApiConfig, C as CopilotContext, a as CopilotContextParams, u as useCopilotContext } from './copilot-context-c402f48d.js';
4
4
  export { CopilotMessagesContext, CopilotMessagesContextParams, useCopilotMessagesContext } from './context/copilot-messages-context.js';
5
5
  export { UseCopilotChatOptions, UseCopilotChatReturn, useCopilotChat } from './hooks/use-copilot-chat.js';
6
6
  export { useCopilotAction } from './hooks/use-copilot-action.js';
@@ -13,6 +13,7 @@ export { useCopilotRuntimeClient } from './hooks/use-copilot-runtime-client.js';
13
13
  export { useCopilotAuthenticatedAction_c } from './hooks/use-copilot-authenticated-action.js';
14
14
  export { useLangGraphInterrupt } from './hooks/use-langgraph-interrupt.js';
15
15
  export { useLangGraphInterruptRender } from './hooks/use-langgraph-interrupt-render.js';
16
+ export { useCopilotAdditionalInstructions } from './hooks/use-copilot-additional-instructions.js';
16
17
  export { DocumentPointer } from './types/document-pointer.js';
17
18
  export { SystemMessageFunction } from './types/system-message.js';
18
19
  export { ActionRenderProps, CatchAllActionRenderProps, RenderFunctionStatus } from './types/frontend-action.js';
package/dist/index.js CHANGED
@@ -94,6 +94,7 @@ __export(src_exports, {
94
94
  useCoAgent: () => useCoAgent,
95
95
  useCoAgentStateRender: () => useCoAgentStateRender,
96
96
  useCopilotAction: () => useCopilotAction,
97
+ useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
97
98
  useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
98
99
  useCopilotChat: () => useCopilotChat,
99
100
  useCopilotContext: () => useCopilotContext,
@@ -133,6 +134,8 @@ var emptyCopilotContext = {
133
134
  setIsLoading: () => returnAndThrowInDebug(false),
134
135
  chatInstructions: "",
135
136
  setChatInstructions: () => returnAndThrowInDebug(""),
137
+ additionalInstructions: [],
138
+ setAdditionalInstructions: () => returnAndThrowInDebug([]),
136
139
  getDocumentsContext: (categories) => returnAndThrowInDebug([]),
137
140
  addDocumentContext: () => returnAndThrowInDebug(""),
138
141
  removeDocumentContext: () => {
@@ -1242,7 +1245,7 @@ function CopilotKitInternal(cpkProps) {
1242
1245
  const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
1243
1246
  const [authStates, setAuthStates] = (0, import_react10.useState)({});
1244
1247
  const [extensions, setExtensions] = (0, import_react10.useState)({});
1245
- const lastLoadedAvailableAgents = (0, import_react10.useRef)();
1248
+ const [additionalInstructions, setAdditionalInstructions] = (0, import_react10.useState)([]);
1246
1249
  const {
1247
1250
  addElement: addDocument,
1248
1251
  removeElement: removeDocument,
@@ -1485,6 +1488,8 @@ ${nonDocumentStrings}`;
1485
1488
  removeChatSuggestionConfiguration,
1486
1489
  chatInstructions,
1487
1490
  setChatInstructions,
1491
+ additionalInstructions,
1492
+ setAdditionalInstructions,
1488
1493
  showDevConsole,
1489
1494
  coagentStates,
1490
1495
  setCoagentStates,
@@ -1557,7 +1562,7 @@ function validateProps(props) {
1557
1562
 
1558
1563
  // src/hooks/use-copilot-chat.ts
1559
1564
  var import_react12 = require("react");
1560
- var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
1565
+ var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1561
1566
 
1562
1567
  // src/hooks/use-chat.ts
1563
1568
  var import_react11 = require("react");
@@ -1569,7 +1574,7 @@ var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
1569
1574
  var import_shared9 = require("@copilotkit/shared");
1570
1575
  function processActionsForRuntimeRequest(actions) {
1571
1576
  const filteredActions = actions.filter(
1572
- (action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
1577
+ (action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
1573
1578
  ).map((action) => {
1574
1579
  let available = import_runtime_client_gql5.ActionInputAvailability.Enabled;
1575
1580
  if (action.disabled) {
@@ -1590,8 +1595,6 @@ function processActionsForRuntimeRequest(actions) {
1590
1595
  }
1591
1596
 
1592
1597
  // src/hooks/use-chat.ts
1593
- var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
1594
- var import_shared11 = require("@copilotkit/shared");
1595
1598
  function useChat(options) {
1596
1599
  const {
1597
1600
  messages,
@@ -1640,7 +1643,7 @@ function useChat(options) {
1640
1643
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1641
1644
  setIsLoading(true);
1642
1645
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
1643
- if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
1646
+ if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
1644
1647
  addErrorToast([
1645
1648
  new Error(
1646
1649
  "A message was sent while interrupt is active. This will cause failure on the agent side"
@@ -1734,16 +1737,16 @@ function useChat(options) {
1734
1737
  setExtensions(extensionsRef.current);
1735
1738
  let rawMessagesResponse = value.generateCopilotResponse.messages;
1736
1739
  ((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
1737
- if (ev.name === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent) {
1740
+ if (ev.name === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent) {
1738
1741
  let eventValue = (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev).value;
1739
- eventValue = (0, import_shared11.parseJson)(eventValue, eventValue);
1742
+ eventValue = (0, import_shared10.parseJson)(eventValue, eventValue);
1740
1743
  setLangGraphInterruptAction({
1741
1744
  event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev)), {
1742
1745
  value: eventValue
1743
1746
  })
1744
1747
  });
1745
1748
  }
1746
- if (ev.name === import_runtime_client_gql7.MetaEventName.CopilotKitLangGraphInterruptEvent) {
1749
+ if (ev.name === import_runtime_client_gql6.MetaEventName.CopilotKitLangGraphInterruptEvent) {
1747
1750
  const data = ev.data;
1748
1751
  rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
1749
1752
  interruptMessages = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
@@ -1824,7 +1827,7 @@ function useChat(options) {
1824
1827
  setMessages([...previousMessages, ...newMessages]);
1825
1828
  }
1826
1829
  }
1827
- const finalMessages = constructFinalMessages(
1830
+ let finalMessages = constructFinalMessages(
1828
1831
  [...syncedMessages, ...interruptMessages],
1829
1832
  previousMessages,
1830
1833
  newMessages
@@ -1834,7 +1837,7 @@ function useChat(options) {
1834
1837
  const lastMessages = [];
1835
1838
  for (let i = finalMessages.length - 1; i >= 0; i--) {
1836
1839
  const message = finalMessages[i];
1837
- if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
1840
+ if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
1838
1841
  lastMessages.unshift(message);
1839
1842
  } else {
1840
1843
  break;
@@ -1842,59 +1845,51 @@ function useChat(options) {
1842
1845
  }
1843
1846
  for (const message of lastMessages) {
1844
1847
  setMessages(finalMessages);
1845
- const action = actions.find((action2) => action2.name === message.name);
1846
- if (action) {
1847
- followUp = action.followUp;
1848
- let result;
1849
- let error = null;
1850
- try {
1851
- result = yield Promise.race([
1852
- onFunctionCall({
1853
- messages: previousMessages,
1854
- name: message.name,
1855
- args: message.arguments
1856
- }),
1857
- new Promise(
1858
- (resolve) => {
1859
- var _a2;
1860
- return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener(
1861
- "abort",
1862
- () => resolve("Operation was aborted by the user")
1863
- );
1864
- }
1865
- ),
1866
- // if the user stopped generation, we also abort consecutive actions
1867
- new Promise((resolve) => {
1868
- var _a2;
1869
- if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
1870
- resolve("Operation was aborted by the user");
1871
- }
1872
- })
1873
- ]);
1874
- } catch (e) {
1875
- error = e;
1876
- addErrorToast([error]);
1877
- result = `Failed to execute action ${message.name}. ${error.message}`;
1878
- console.error(`Failed to execute action ${message.name}: ${error}`);
1879
- }
1848
+ const action = actions.find(
1849
+ (action2) => action2.name === message.name
1850
+ );
1851
+ const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
1852
+ const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
1853
+ followUp = action2 == null ? void 0 : action2.followUp;
1854
+ const resultMessage = yield executeAction({
1855
+ onFunctionCall,
1856
+ previousMessages,
1857
+ message: message2,
1858
+ chatAbortControllerRef,
1859
+ onError: (error) => {
1860
+ addErrorToast([error]);
1861
+ console.error(`Failed to execute action ${message2.name}: ${error}`);
1862
+ }
1863
+ });
1880
1864
  didExecuteAction = true;
1881
- const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);
1882
- finalMessages.splice(
1883
- messageIndex + 1,
1884
- 0,
1885
- new import_runtime_client_gql6.ResultMessage({
1886
- id: "result-" + message.id,
1887
- result: import_runtime_client_gql6.ResultMessage.encodeResult(
1888
- error ? {
1889
- content: result,
1890
- error: JSON.parse(
1891
- JSON.stringify(error, Object.getOwnPropertyNames(error))
1892
- )
1893
- } : result
1894
- ),
1895
- actionExecutionId: message.id,
1896
- actionName: message.name
1897
- })
1865
+ const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
1866
+ finalMessages.splice(messageIndex + 1, 0, resultMessage);
1867
+ return resultMessage;
1868
+ });
1869
+ if (action && message.isActionExecutionMessage()) {
1870
+ const resultMessage = yield executeActionFromMessage(action, message);
1871
+ const pairedFeAction = getPairedFeAction(actions, resultMessage);
1872
+ if (pairedFeAction) {
1873
+ const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
1874
+ name: pairedFeAction.name,
1875
+ arguments: (0, import_shared10.parseJson)(resultMessage.result, resultMessage.result),
1876
+ status: message.status,
1877
+ createdAt: message.createdAt,
1878
+ parentMessageId: message.parentMessageId
1879
+ });
1880
+ yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
1881
+ }
1882
+ } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
1883
+ const newExecutionMessage = new import_runtime_client_gql6.ActionExecutionMessage({
1884
+ name: currentResultMessagePairedFeAction.name,
1885
+ arguments: (0, import_shared10.parseJson)(message.result, message.result),
1886
+ status: message.status,
1887
+ createdAt: message.createdAt
1888
+ });
1889
+ finalMessages.push(newExecutionMessage);
1890
+ yield executeActionFromMessage(
1891
+ currentResultMessagePairedFeAction,
1892
+ newExecutionMessage
1898
1893
  );
1899
1894
  }
1900
1895
  }
@@ -1965,7 +1960,7 @@ function useChat(options) {
1965
1960
  if (!event)
1966
1961
  return acc;
1967
1962
  switch (event.name) {
1968
- case import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent:
1963
+ case import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent:
1969
1964
  if (event.response) {
1970
1965
  setLangGraphInterruptAction(null);
1971
1966
  const value = event.value;
@@ -2041,6 +2036,67 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
2041
2036
  }
2042
2037
  return finalMessages;
2043
2038
  }
2039
+ function executeAction(_0) {
2040
+ return __async(this, arguments, function* ({
2041
+ onFunctionCall,
2042
+ previousMessages,
2043
+ message,
2044
+ chatAbortControllerRef,
2045
+ onError
2046
+ }) {
2047
+ let result;
2048
+ let error = null;
2049
+ try {
2050
+ result = yield Promise.race([
2051
+ onFunctionCall({
2052
+ messages: previousMessages,
2053
+ name: message.name,
2054
+ args: message.arguments
2055
+ }),
2056
+ new Promise(
2057
+ (resolve) => {
2058
+ var _a;
2059
+ return (_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.addEventListener(
2060
+ "abort",
2061
+ () => resolve("Operation was aborted by the user")
2062
+ );
2063
+ }
2064
+ ),
2065
+ // if the user stopped generation, we also abort consecutive actions
2066
+ new Promise((resolve) => {
2067
+ var _a;
2068
+ if ((_a = chatAbortControllerRef.current) == null ? void 0 : _a.signal.aborted) {
2069
+ resolve("Operation was aborted by the user");
2070
+ }
2071
+ })
2072
+ ]);
2073
+ } catch (e) {
2074
+ onError(e);
2075
+ }
2076
+ return new import_runtime_client_gql6.ResultMessage({
2077
+ id: "result-" + message.id,
2078
+ result: import_runtime_client_gql6.ResultMessage.encodeResult(
2079
+ error ? {
2080
+ content: result,
2081
+ error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
2082
+ } : result
2083
+ ),
2084
+ actionExecutionId: message.id,
2085
+ actionName: message.name
2086
+ });
2087
+ });
2088
+ }
2089
+ function getPairedFeAction(actions, message) {
2090
+ let actionName = null;
2091
+ if (message.isActionExecutionMessage()) {
2092
+ actionName = message.name;
2093
+ } else if (message.isResultMessage()) {
2094
+ actionName = message.actionName;
2095
+ }
2096
+ return actions.find(
2097
+ (action) => action.name === actionName && action.available === "frontend" || action.pairedAction === actionName
2098
+ );
2099
+ }
2044
2100
 
2045
2101
  // src/hooks/use-copilot-chat.ts
2046
2102
  function useCopilotChat(_a = {}) {
@@ -2085,9 +2141,9 @@ function useCopilotChat(_a = {}) {
2085
2141
  const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
2086
2142
  const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
2087
2143
  const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
2088
- return new import_runtime_client_gql8.TextMessage({
2144
+ return new import_runtime_client_gql7.TextMessage({
2089
2145
  content: systemMessageMaker(contextString, chatInstructions),
2090
- role: import_runtime_client_gql8.Role.System
2146
+ role: import_runtime_client_gql7.Role.System
2091
2147
  });
2092
2148
  }, [getContextString, makeSystemMessage2, chatInstructions]);
2093
2149
  const onCoAgentStateRender = useAsyncCallback(
@@ -2239,11 +2295,11 @@ ${additionalInstructions}` : "");
2239
2295
  }
2240
2296
 
2241
2297
  // src/hooks/use-copilot-action.ts
2242
- var import_shared12 = require("@copilotkit/shared");
2298
+ var import_shared11 = require("@copilotkit/shared");
2243
2299
  var import_react13 = require("react");
2244
2300
  function useCopilotAction(action, dependencies) {
2245
2301
  const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
2246
- const idRef = (0, import_react13.useRef)((0, import_shared12.randomId)());
2302
+ const idRef = (0, import_react13.useRef)((0, import_shared11.randomId)());
2247
2303
  const renderAndWaitRef = (0, import_react13.useRef)(null);
2248
2304
  const { addToast } = useToast();
2249
2305
  action = __spreadValues({}, action);
@@ -2345,7 +2401,7 @@ function isFrontendAction(action) {
2345
2401
 
2346
2402
  // src/hooks/use-coagent-state-render.ts
2347
2403
  var import_react14 = require("react");
2348
- var import_shared13 = require("@copilotkit/shared");
2404
+ var import_shared12 = require("@copilotkit/shared");
2349
2405
  function useCoAgentStateRender(action, dependencies) {
2350
2406
  const {
2351
2407
  setCoAgentStateRender,
@@ -2354,7 +2410,7 @@ function useCoAgentStateRender(action, dependencies) {
2354
2410
  chatComponentsCache,
2355
2411
  availableAgents
2356
2412
  } = (0, import_react14.useContext)(CopilotContext);
2357
- const idRef = (0, import_react14.useRef)((0, import_shared13.randomId)());
2413
+ const idRef = (0, import_react14.useRef)((0, import_shared12.randomId)());
2358
2414
  const { addToast } = useToast();
2359
2415
  (0, import_react14.useEffect)(() => {
2360
2416
  if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
@@ -2436,24 +2492,33 @@ var import_react16 = require("react");
2436
2492
  function convertToJSON(description, value) {
2437
2493
  return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
2438
2494
  }
2439
- function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
2495
+ function useCopilotReadable({
2496
+ description,
2497
+ value,
2498
+ parentId,
2499
+ categories,
2500
+ convert,
2501
+ available = "enabled"
2502
+ }, dependencies) {
2440
2503
  const { addContext, removeContext } = useCopilotContext();
2441
2504
  const idRef = (0, import_react16.useRef)();
2442
2505
  convert = convert || convertToJSON;
2443
2506
  const information = convert(description, value);
2444
2507
  (0, import_react16.useEffect)(() => {
2508
+ if (available === "disabled")
2509
+ return;
2445
2510
  const id = addContext(information, parentId, categories);
2446
2511
  idRef.current = id;
2447
2512
  return () => {
2448
2513
  removeContext(id);
2449
2514
  };
2450
- }, [information, parentId, addContext, removeContext, ...dependencies || []]);
2515
+ }, [available, information, parentId, addContext, removeContext, ...dependencies || []]);
2451
2516
  return idRef.current;
2452
2517
  }
2453
2518
 
2454
2519
  // src/hooks/use-coagent.ts
2455
2520
  var import_react17 = require("react");
2456
- var import_shared14 = require("@copilotkit/shared");
2521
+ var import_shared13 = require("@copilotkit/shared");
2457
2522
  function useCoAgent(options) {
2458
2523
  const generalContext = useCopilotContext();
2459
2524
  const { availableAgents } = generalContext;
@@ -2504,7 +2569,7 @@ function useCoAgent(options) {
2504
2569
  if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
2505
2570
  lastLoadedState.current = newState;
2506
2571
  lastLoadedThreadId.current = threadId;
2507
- const fetchedState = (0, import_shared14.parseJson)(newState, {});
2572
+ const fetchedState = (0, import_shared13.parseJson)(newState, {});
2508
2573
  isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
2509
2574
  }
2510
2575
  });
@@ -2630,7 +2695,7 @@ var import_react19 = __toESM(require("react"));
2630
2695
  function useCopilotAuthenticatedAction_c(action, dependencies) {
2631
2696
  const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
2632
2697
  const pendingActionRef = (0, import_react18.useRef)(null);
2633
- const executeAction = (0, import_react18.useCallback)(
2698
+ const executeAction2 = (0, import_react18.useCallback)(
2634
2699
  (props) => {
2635
2700
  if (typeof action.render === "function") {
2636
2701
  return action.render(props);
@@ -2650,13 +2715,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2650
2715
  onSignInComplete: (authState) => {
2651
2716
  setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
2652
2717
  if (pendingActionRef.current) {
2653
- executeAction(pendingActionRef.current);
2718
+ executeAction2(pendingActionRef.current);
2654
2719
  pendingActionRef.current = null;
2655
2720
  }
2656
2721
  }
2657
2722
  }) : import_react19.default.createElement(import_react18.Fragment);
2658
2723
  }
2659
- return executeAction(props);
2724
+ return executeAction2(props);
2660
2725
  },
2661
2726
  [action, authStates_c, setAuthStates_c]
2662
2727
  );
@@ -2670,13 +2735,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
2670
2735
 
2671
2736
  // src/hooks/use-langgraph-interrupt.ts
2672
2737
  var import_react20 = require("react");
2673
- var import_shared15 = require("@copilotkit/shared");
2738
+ var import_shared14 = require("@copilotkit/shared");
2674
2739
  function useLangGraphInterrupt(action, dependencies) {
2675
2740
  var _a;
2676
2741
  const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react20.useContext)(CopilotContext);
2677
2742
  const { runChatCompletion } = useCopilotChat();
2678
2743
  const { addToast } = useToast();
2679
- const actionId = (0, import_shared15.dataToUUID)(JSON.stringify(action), "lgAction");
2744
+ const actionId = (0, import_shared14.dataToUUID)(JSON.stringify(action), "lgAction");
2680
2745
  const hasAction = (0, import_react20.useMemo)(
2681
2746
  () => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
2682
2747
  [langGraphInterruptAction]
@@ -2754,8 +2819,24 @@ function useLangGraphInterruptRender() {
2754
2819
  });
2755
2820
  }
2756
2821
 
2822
+ // src/hooks/use-copilot-additional-instructions.ts
2823
+ var import_react22 = require("react");
2824
+ function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
2825
+ const { setAdditionalInstructions } = useCopilotContext();
2826
+ (0, import_react22.useEffect)(() => {
2827
+ if (available === "disabled")
2828
+ return;
2829
+ setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
2830
+ return () => {
2831
+ setAdditionalInstructions(
2832
+ (prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter((instruction) => instruction !== instructions)) || []
2833
+ );
2834
+ };
2835
+ }, [available, instructions, setAdditionalInstructions, ...dependencies || []]);
2836
+ }
2837
+
2757
2838
  // src/lib/copilot-task.ts
2758
- var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
2839
+ var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
2759
2840
  var CopilotTask = class {
2760
2841
  constructor(config) {
2761
2842
  this.instructions = config.instructions;
@@ -2783,12 +2864,12 @@ var CopilotTask = class {
2783
2864
  if (this.includeCopilotReadable) {
2784
2865
  contextString += context.getContextString([], defaultCopilotContextCategories);
2785
2866
  }
2786
- const systemMessage = new import_runtime_client_gql9.TextMessage({
2867
+ const systemMessage = new import_runtime_client_gql8.TextMessage({
2787
2868
  content: taskSystemMessage(contextString, this.instructions),
2788
- role: import_runtime_client_gql9.Role.System
2869
+ role: import_runtime_client_gql8.Role.System
2789
2870
  });
2790
2871
  const messages = [systemMessage];
2791
- const runtimeClient = new import_runtime_client_gql9.CopilotRuntimeClient({
2872
+ const runtimeClient = new import_runtime_client_gql8.CopilotRuntimeClient({
2792
2873
  url: context.copilotApiConfig.chatApiEndpoint,
2793
2874
  publicApiKey: context.copilotApiConfig.publicApiKey,
2794
2875
  headers: context.copilotApiConfig.headers,
@@ -2800,9 +2881,9 @@ var CopilotTask = class {
2800
2881
  actions: processActionsForRuntimeRequest(Object.values(actions)),
2801
2882
  url: window.location.href
2802
2883
  },
2803
- messages: (0, import_runtime_client_gql9.convertMessagesToGqlInput)((0, import_runtime_client_gql9.filterAgentStateMessages)(messages)),
2884
+ messages: (0, import_runtime_client_gql8.convertMessagesToGqlInput)((0, import_runtime_client_gql8.filterAgentStateMessages)(messages)),
2804
2885
  metadata: {
2805
- requestType: import_runtime_client_gql9.CopilotRequestType.Task
2886
+ requestType: import_runtime_client_gql8.CopilotRequestType.Task
2806
2887
  },
2807
2888
  forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
2808
2889
  toolChoice: "required"
@@ -2811,7 +2892,7 @@ var CopilotTask = class {
2811
2892
  properties: context.copilotApiConfig.properties
2812
2893
  }).toPromise();
2813
2894
  const functionCallHandler = context.getFunctionCallHandler(actions);
2814
- const functionCalls = (0, import_runtime_client_gql9.convertGqlOutputToMessages)(
2895
+ const functionCalls = (0, import_runtime_client_gql8.convertGqlOutputToMessages)(
2815
2896
  ((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
2816
2897
  ).filter((m) => m.isActionExecutionMessage());
2817
2898
  for (const functionCall of functionCalls) {
@@ -2864,6 +2945,7 @@ ${instructions}
2864
2945
  useCoAgent,
2865
2946
  useCoAgentStateRender,
2866
2947
  useCopilotAction,
2948
+ useCopilotAdditionalInstructions,
2867
2949
  useCopilotAuthenticatedAction_c,
2868
2950
  useCopilotChat,
2869
2951
  useCopilotContext,