@copilotkit/react-core 1.8.7-next.0 → 1.8.8-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.
- package/CHANGELOG.md +17 -0
- package/dist/{chunk-GOK4PDQO.mjs → chunk-2ZKWBDBN.mjs} +2 -2
- package/dist/{chunk-LOOGELNK.mjs → chunk-364OMMXW.mjs} +3 -3
- package/dist/{chunk-7VCWAAWC.mjs → chunk-4EXRQ5D5.mjs} +2 -2
- package/dist/{chunk-UDUFMGWQ.mjs → chunk-7WG4MNRX.mjs} +1 -1
- package/dist/chunk-7WG4MNRX.mjs.map +1 -0
- package/dist/{chunk-5TVV6FJD.mjs → chunk-B3CERZDI.mjs} +2 -2
- package/dist/{chunk-KF5SB2VB.mjs → chunk-GBAZTXPQ.mjs} +2 -2
- package/dist/{chunk-MWRS4C6I.mjs → chunk-HI537DQG.mjs} +36 -21
- package/dist/chunk-HI537DQG.mjs.map +1 -0
- package/dist/{chunk-JWE4IXSG.mjs → chunk-INRN7B2F.mjs} +2 -2
- package/dist/{chunk-FDC3UOMT.mjs → chunk-O54FEOCV.mjs} +7 -9
- package/dist/chunk-O54FEOCV.mjs.map +1 -0
- package/dist/{chunk-DMQB35FC.mjs → chunk-OSVDTMKA.mjs} +2 -2
- package/dist/{chunk-3C2PD3HY.mjs → chunk-QWBJM23V.mjs} +3 -3
- package/dist/{chunk-HGZXDC4Y.mjs → chunk-VYSR3S2A.mjs} +2 -2
- package/dist/{chunk-FRRPZKXW.mjs → chunk-W3QHAZKD.mjs} +3 -3
- package/dist/{chunk-NRQLK2OM.mjs → chunk-XRCQULYN.mjs} +2 -2
- package/dist/{chunk-6OMSQLHC.mjs → chunk-ZXJHNU6Q.mjs} +20 -13
- package/dist/chunk-ZXJHNU6Q.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -18
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +1 -3
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +4 -4
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +1 -3
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +4 -4
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -4
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-0e923eb1.d.ts → copilot-context-8fb74a85.d.ts} +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +50 -28
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +15 -15
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +19 -12
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +50 -28
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +7 -7
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +8 -2
- package/dist/hooks/use-copilot-chat.js +50 -28
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +6 -6
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +50 -28
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +7 -7
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +51 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -16
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +5 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -5
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +4 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +4 -4
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit-props.tsx +0 -16
- package/src/components/copilot-provider/copilotkit.tsx +0 -2
- package/src/context/copilot-context.tsx +1 -1
- package/src/hooks/use-chat.ts +30 -4
- package/src/hooks/use-copilot-chat.ts +52 -27
- package/dist/chunk-6OMSQLHC.mjs.map +0 -1
- package/dist/chunk-FDC3UOMT.mjs.map +0 -1
- package/dist/chunk-MWRS4C6I.mjs.map +0 -1
- package/dist/chunk-UDUFMGWQ.mjs.map +0 -1
- /package/dist/{chunk-GOK4PDQO.mjs.map → chunk-2ZKWBDBN.mjs.map} +0 -0
- /package/dist/{chunk-LOOGELNK.mjs.map → chunk-364OMMXW.mjs.map} +0 -0
- /package/dist/{chunk-7VCWAAWC.mjs.map → chunk-4EXRQ5D5.mjs.map} +0 -0
- /package/dist/{chunk-5TVV6FJD.mjs.map → chunk-B3CERZDI.mjs.map} +0 -0
- /package/dist/{chunk-KF5SB2VB.mjs.map → chunk-GBAZTXPQ.mjs.map} +0 -0
- /package/dist/{chunk-JWE4IXSG.mjs.map → chunk-INRN7B2F.mjs.map} +0 -0
- /package/dist/{chunk-DMQB35FC.mjs.map → chunk-OSVDTMKA.mjs.map} +0 -0
- /package/dist/{chunk-3C2PD3HY.mjs.map → chunk-QWBJM23V.mjs.map} +0 -0
- /package/dist/{chunk-HGZXDC4Y.mjs.map → chunk-VYSR3S2A.mjs.map} +0 -0
- /package/dist/{chunk-FRRPZKXW.mjs.map → chunk-W3QHAZKD.mjs.map} +0 -0
- /package/dist/{chunk-NRQLK2OM.mjs.map → chunk-XRCQULYN.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 /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpEndpoints?: Array<{ endpoint: string; apiKey?: string }>;\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 {\n throw new Error(\"Remember to wrap your app in a `<Cop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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 /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | 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 {\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;AAsNlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;A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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;;;ADlSO,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"]}
|
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-
|
|
3
|
+
export { b as CoagentInChatRenderFunction, c as CopilotApiConfig, C as CopilotContext, a as CopilotContextParams, u as useCopilotContext } from './copilot-context-8fb74a85.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';
|
package/dist/index.js
CHANGED
|
@@ -1352,8 +1352,7 @@ ${nonDocumentStrings}`;
|
|
|
1352
1352
|
properties: props.properties || {},
|
|
1353
1353
|
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
1354
1354
|
textToSpeechUrl: props.textToSpeechUrl,
|
|
1355
|
-
credentials: props.credentials
|
|
1356
|
-
mcpEndpoints: props.mcpEndpoints
|
|
1355
|
+
credentials: props.credentials
|
|
1357
1356
|
});
|
|
1358
1357
|
}, [
|
|
1359
1358
|
props.publicApiKey,
|
|
@@ -1363,7 +1362,6 @@ ${nonDocumentStrings}`;
|
|
|
1363
1362
|
props.textToSpeechUrl,
|
|
1364
1363
|
props.credentials,
|
|
1365
1364
|
props.cloudRestrictToTopic,
|
|
1366
|
-
props.mcpEndpoints,
|
|
1367
1365
|
props.guardrails_c
|
|
1368
1366
|
]);
|
|
1369
1367
|
const headers = (0, import_react10.useMemo)(() => {
|
|
@@ -1652,7 +1650,7 @@ function useChat(options) {
|
|
|
1652
1650
|
});
|
|
1653
1651
|
const runChatCompletion = useAsyncCallback(
|
|
1654
1652
|
(previousMessages) => __async(this, null, function* () {
|
|
1655
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
|
|
1653
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
1656
1654
|
setIsLoading(true);
|
|
1657
1655
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
1658
1656
|
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) {
|
|
@@ -1673,8 +1671,15 @@ function useChat(options) {
|
|
|
1673
1671
|
const systemMessage = makeSystemMessageCallback();
|
|
1674
1672
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
1675
1673
|
const finalProperties = __spreadValues({}, copilotConfig.properties || {});
|
|
1676
|
-
|
|
1677
|
-
|
|
1674
|
+
let mcpServersToUse = null;
|
|
1675
|
+
if (copilotConfig.mcpServers && Array.isArray(copilotConfig.mcpServers) && copilotConfig.mcpServers.length > 0) {
|
|
1676
|
+
mcpServersToUse = copilotConfig.mcpServers;
|
|
1677
|
+
} else if (((_a = copilotConfig.properties) == null ? void 0 : _a.mcpServers) && Array.isArray(copilotConfig.properties.mcpServers) && copilotConfig.properties.mcpServers.length > 0) {
|
|
1678
|
+
mcpServersToUse = copilotConfig.properties.mcpServers;
|
|
1679
|
+
}
|
|
1680
|
+
if (mcpServersToUse) {
|
|
1681
|
+
finalProperties.mcpServers = mcpServersToUse;
|
|
1682
|
+
copilotConfig.mcpServers = mcpServersToUse;
|
|
1678
1683
|
}
|
|
1679
1684
|
const isAgentRun = agentSessionRef.current !== null;
|
|
1680
1685
|
const stream = runtimeClient.asStream(
|
|
@@ -1690,7 +1695,7 @@ function useChat(options) {
|
|
|
1690
1695
|
metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
|
|
1691
1696
|
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messagesWithContext))
|
|
1692
1697
|
}, copilotConfig.cloud ? {
|
|
1693
|
-
cloud: __spreadValues({}, ((
|
|
1698
|
+
cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
|
|
1694
1699
|
guardrails: {
|
|
1695
1700
|
inputValidationRules: {
|
|
1696
1701
|
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
@@ -1716,10 +1721,10 @@ function useChat(options) {
|
|
|
1716
1721
|
forwardedParameters: options.forwardedParameters || {}
|
|
1717
1722
|
}),
|
|
1718
1723
|
properties: finalProperties,
|
|
1719
|
-
signal: (
|
|
1724
|
+
signal: (_e = chatAbortControllerRef.current) == null ? void 0 : _e.signal
|
|
1720
1725
|
})
|
|
1721
1726
|
);
|
|
1722
|
-
const guardrailsEnabled = ((
|
|
1727
|
+
const guardrailsEnabled = ((_h = (_g = (_f = copilotConfig.cloud) == null ? void 0 : _f.guardrails) == null ? void 0 : _g.input) == null ? void 0 : _h.restrictToTopic.enabled) || false;
|
|
1723
1728
|
const reader = stream.getReader();
|
|
1724
1729
|
let executedCoAgentStateRenders = [];
|
|
1725
1730
|
let followUp = void 0;
|
|
@@ -1752,7 +1757,7 @@ function useChat(options) {
|
|
|
1752
1757
|
setRunId(runIdRef.current);
|
|
1753
1758
|
setExtensions(extensionsRef.current);
|
|
1754
1759
|
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
1755
|
-
const metaEvents = (
|
|
1760
|
+
const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
|
|
1756
1761
|
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
1757
1762
|
if (ev.name === import_runtime_client_gql6.MetaEventName.LangGraphInterruptEvent) {
|
|
1758
1763
|
let eventValue = (0, import_runtime_client_gql6.langGraphInterruptEvent)(ev).value;
|
|
@@ -1779,11 +1784,11 @@ function useChat(options) {
|
|
|
1779
1784
|
continue;
|
|
1780
1785
|
}
|
|
1781
1786
|
newMessages = [];
|
|
1782
|
-
if (((
|
|
1787
|
+
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
1783
1788
|
newMessages = [
|
|
1784
1789
|
new import_runtime_client_gql6.TextMessage({
|
|
1785
1790
|
role: import_runtime_client_gql6.MessageRole.Assistant,
|
|
1786
|
-
content: ((
|
|
1791
|
+
content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
|
|
1787
1792
|
})
|
|
1788
1793
|
];
|
|
1789
1794
|
setMessages([...previousMessages, ...newMessages]);
|
|
@@ -1918,11 +1923,11 @@ function useChat(options) {
|
|
|
1918
1923
|
followUp !== false && // and we executed an action
|
|
1919
1924
|
(didExecuteAction || // the last message is a server side result
|
|
1920
1925
|
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
1921
|
-
!((
|
|
1926
|
+
!((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
|
|
1922
1927
|
) {
|
|
1923
1928
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
1924
1929
|
return yield runChatCompletionRef.current(finalMessages);
|
|
1925
|
-
} else if ((
|
|
1930
|
+
} else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
|
|
1926
1931
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
1927
1932
|
if (message.isActionExecutionMessage()) {
|
|
1928
1933
|
return finalMessages.find(
|
|
@@ -1933,7 +1938,7 @@ function useChat(options) {
|
|
|
1933
1938
|
});
|
|
1934
1939
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
1935
1940
|
setMessages(repairedMessages);
|
|
1936
|
-
if ((
|
|
1941
|
+
if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
|
|
1937
1942
|
setAgentSession({
|
|
1938
1943
|
threadId: agentSessionRef.current.threadId,
|
|
1939
1944
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -2156,21 +2161,20 @@ function useCopilotChat(_a = {}) {
|
|
|
2156
2161
|
setLangGraphInterruptAction
|
|
2157
2162
|
} = useCopilotContext();
|
|
2158
2163
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2161
|
-
(
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
2164
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react12.useState)([]);
|
|
2165
|
+
(0, import_react12.useEffect)(() => {
|
|
2166
|
+
if (mcpServers.length > 0) {
|
|
2167
|
+
const serversCopy = [...mcpServers];
|
|
2168
|
+
copilotApiConfig.mcpServers = serversCopy;
|
|
2169
|
+
if (!copilotApiConfig.properties) {
|
|
2170
|
+
copilotApiConfig.properties = {};
|
|
2171
|
+
}
|
|
2172
|
+
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
2173
|
+
}
|
|
2174
|
+
}, [mcpServers, copilotApiConfig]);
|
|
2175
|
+
const setMcpServers = (0, import_react12.useCallback)((servers) => {
|
|
2176
|
+
setLocalMcpServers(servers);
|
|
2177
|
+
}, []);
|
|
2174
2178
|
const onCoAgentStateRender = useAsyncCallback(
|
|
2175
2179
|
(args) => __async(this, null, function* () {
|
|
2176
2180
|
var _a2;
|
|
@@ -2189,6 +2193,20 @@ function useCopilotChat(_a = {}) {
|
|
|
2189
2193
|
}),
|
|
2190
2194
|
[coAgentStateRenders]
|
|
2191
2195
|
);
|
|
2196
|
+
const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
|
|
2197
|
+
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
2198
|
+
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
2199
|
+
return new import_runtime_client_gql7.TextMessage({
|
|
2200
|
+
content: systemMessageMaker(contextString, chatInstructions),
|
|
2201
|
+
role: import_runtime_client_gql7.Role.System
|
|
2202
|
+
});
|
|
2203
|
+
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
2204
|
+
const deleteMessage = (0, import_react12.useCallback)(
|
|
2205
|
+
(messageId) => {
|
|
2206
|
+
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
2207
|
+
},
|
|
2208
|
+
[setMessages]
|
|
2209
|
+
);
|
|
2192
2210
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
2193
2211
|
actions: Object.values(actions),
|
|
2194
2212
|
copilotConfig: copilotApiConfig,
|
|
@@ -2285,7 +2303,9 @@ function useCopilotChat(_a = {}) {
|
|
|
2285
2303
|
reset: latestResetFunc,
|
|
2286
2304
|
deleteMessage: latestDeleteFunc,
|
|
2287
2305
|
runChatCompletion: latestRunChatCompletionFunc,
|
|
2288
|
-
isLoading
|
|
2306
|
+
isLoading,
|
|
2307
|
+
mcpServers,
|
|
2308
|
+
setMcpServers
|
|
2289
2309
|
};
|
|
2290
2310
|
}
|
|
2291
2311
|
function useUpdatedRef(value) {
|