@copilotkit/react-core 1.9.2-next.8 → 1.9.2
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 +193 -0
- package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-7G6RR4HE.mjs → chunk-3Q4F7RF2.mjs} +2 -2
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
- package/dist/{chunk-RN3ZRHI7.mjs → chunk-AD7DWJNW.mjs} +66 -25
- package/dist/chunk-AD7DWJNW.mjs.map +1 -0
- package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
- package/dist/{chunk-VJCHRQ7Q.mjs → chunk-DGON3GZX.mjs} +39 -6
- package/dist/chunk-DGON3GZX.mjs.map +1 -0
- package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
- package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
- package/dist/{chunk-S4BOATBG.mjs → chunk-FN3UA2ZE.mjs} +3 -3
- package/dist/{chunk-ISYBUDL4.mjs → chunk-JWAXDYOW.mjs} +11 -12
- package/dist/chunk-JWAXDYOW.mjs.map +1 -0
- package/dist/{chunk-T4ZKC4X4.mjs → chunk-KIXKBJUV.mjs} +3 -3
- package/dist/{chunk-I4JPQECN.mjs → chunk-LFAZTKBK.mjs} +5 -5
- package/dist/{chunk-JHIZ5HAI.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-ZHEEHGLS.mjs → chunk-QGT4JO7R.mjs} +35 -6
- package/dist/chunk-QGT4JO7R.mjs.map +1 -0
- package/dist/{chunk-JXF732XG.mjs → chunk-S5QUEHJC.mjs} +195 -77
- package/dist/chunk-S5QUEHJC.mjs.map +1 -0
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/{chunk-VF6UPRKM.mjs → chunk-ZGMZ5WJI.mjs} +4 -4
- package/dist/components/copilot-provider/copilot-messages.js +37 -4
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
- 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 +354 -258
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -10
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +354 -258
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -10
- package/dist/components/error-boundary/error-boundary.js +135 -146
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -4
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +354 -258
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/components/toast/toast-provider.js +118 -85
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.js +135 -146
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +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 +1 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +249 -88
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +287 -174
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +5 -5
- package/dist/hooks/use-coagent-state-render.js +1 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +224 -82
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +26 -7
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.js +1 -1
- 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 +26 -7
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +195 -82
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +1 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +8 -8
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
- 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 +195 -82
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +1 -1
- 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 +593 -336
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -11
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +26 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/setupTests.mjs +24 -0
- package/dist/setupTests.mjs.map +1 -0
- 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 +10 -10
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -10
- package/jest.config.js +4 -0
- package/package.json +6 -3
- package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
- package/src/components/copilot-provider/copilot-messages.tsx +43 -4
- package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
- package/src/components/copilot-provider/copilotkit.tsx +61 -19
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +4 -4
- package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
- package/src/hooks/use-chat.ts +249 -61
- package/src/hooks/use-coagent.ts +41 -0
- package/src/hooks/use-copilot-action.ts +51 -9
- package/src/hooks/use-copilot-runtime-client.ts +12 -50
- package/src/setupTests.ts +26 -0
- package/tsconfig.json +5 -2
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-ISYBUDL4.mjs.map +0 -1
- package/dist/chunk-JHIZ5HAI.mjs.map +0 -1
- package/dist/chunk-JXF732XG.mjs.map +0 -1
- package/dist/chunk-RN3ZRHI7.mjs.map +0 -1
- package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- package/dist/chunk-ZHEEHGLS.mjs.map +0 -1
- /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-3Q4F7RF2.mjs.map} +0 -0
- /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
- /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
- /package/dist/{chunk-S4BOATBG.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
- /package/dist/{chunk-I4JPQECN.mjs.map → chunk-LFAZTKBK.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
- /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-ZGMZ5WJI.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler, CopilotTraceHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } 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;\nexport type ContextTree = Tree;\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 getAllContext: () => Tree;\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;\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 /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onTrace?: CopilotTraceHandler;\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 getAllContext: () => [],\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: false,\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 onTrace: undefined,\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":"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","names":["React","import_react","emptyCopilotContext","React"]}
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts","../../src/context/copilot-context.tsx","../../src/context/copilot-messages-context.tsx"],"sourcesContent":["export { CopilotContext, useCopilotContext } from \"./copilot-context\";\nexport { CopilotMessagesContext, useCopilotMessagesContext } from \"./copilot-messages-context\";\nexport type {\n CopilotContextParams,\n CoagentInChatRenderFunction,\n CopilotApiConfig,\n} from \"./copilot-context\";\nexport type { CopilotMessagesContextParams } from \"./copilot-messages-context\";\n","import { CopilotCloudConfig, FunctionCallHandler, CopilotErrorHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } 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;\nexport type ContextTree = Tree;\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 getAllContext: () => Tree;\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;\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?: Partial<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 /**\n * Optional trace handler for comprehensive debugging and observability.\n */\n onError?: CopilotErrorHandler;\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 getAllContext: () => [],\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: false,\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 onError: undefined,\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","/**\n * An internal context to separate the messages state (which is constantly changing) from the rest of CopilotKit context\n */\n\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport React from \"react\";\n\nexport interface CopilotMessagesContextParams {\n messages: Message[];\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n}\n\nconst emptyCopilotContext: CopilotMessagesContextParams = {\n messages: [],\n setMessages: () => [],\n};\n\nexport const CopilotMessagesContext =\n React.createContext<CopilotMessagesContextParams>(emptyCopilotContext);\n\nexport function useCopilotMessagesContext(): CopilotMessagesContextParams {\n const context = React.useContext(CopilotMessagesContext);\n if (context === emptyCopilotContext) {\n throw new Error(\n \"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`\",\n );\n }\n return context;\n}\n"],"mappings":"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","names":["React","import_react","emptyCopilotContext","React"]}
|
package/dist/context/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CopilotCloudConfig, FunctionCallHandler,
|
|
1
|
+
import { CopilotCloudConfig, FunctionCallHandler, CopilotErrorHandler } from '@copilotkit/shared';
|
|
2
2
|
import { ActionRenderProps, CatchAllActionRenderProps, FrontendAction } from './types/frontend-action.js';
|
|
3
3
|
import React$1 from 'react';
|
|
4
4
|
import { Tree, TreeNodeId } from './hooks/use-tree.js';
|
|
@@ -169,7 +169,7 @@ interface CopilotContextParams {
|
|
|
169
169
|
/**
|
|
170
170
|
* The forwarded parameters to use for the task.
|
|
171
171
|
*/
|
|
172
|
-
forwardedParameters?: Pick<ForwardedParametersInput, "temperature"
|
|
172
|
+
forwardedParameters?: Partial<Pick<ForwardedParametersInput, "temperature">>;
|
|
173
173
|
availableAgents: Agent[];
|
|
174
174
|
/**
|
|
175
175
|
* The auth states for the CopilotKit.
|
|
@@ -192,7 +192,7 @@ interface CopilotContextParams {
|
|
|
192
192
|
/**
|
|
193
193
|
* Optional trace handler for comprehensive debugging and observability.
|
|
194
194
|
*/
|
|
195
|
-
|
|
195
|
+
onError?: CopilotErrorHandler;
|
|
196
196
|
}
|
|
197
197
|
declare const CopilotContext: React$1.Context<CopilotContextParams>;
|
|
198
198
|
declare function useCopilotContext(): CopilotContextParams;
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import '../types/frontend-action.js';
|
|
|
18
18
|
import 'react';
|
|
19
19
|
import '../types/coagent-action.js';
|
|
20
20
|
import '../types/document-pointer.js';
|
|
21
|
-
import '../copilot-context-
|
|
21
|
+
import '../copilot-context-3ab4fdf5.js';
|
|
22
22
|
import '../types/chat-suggestion-configuration.js';
|
|
23
23
|
import '../types/coagent-state.js';
|
|
24
24
|
import '../context/copilot-messages-context.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -173,7 +173,7 @@ var emptyCopilotContext = {
|
|
|
173
173
|
langGraphInterruptAction: null,
|
|
174
174
|
setLangGraphInterruptAction: () => null,
|
|
175
175
|
removeLangGraphInterruptAction: () => null,
|
|
176
|
-
|
|
176
|
+
onError: void 0
|
|
177
177
|
};
|
|
178
178
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
179
179
|
function useCopilotContext() {
|
|
@@ -192,6 +192,7 @@ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
|
192
192
|
|
|
193
193
|
// src/hooks/use-chat.ts
|
|
194
194
|
var import_react5 = require("react");
|
|
195
|
+
var import_react_dom = require("react-dom");
|
|
195
196
|
var import_shared4 = require("@copilotkit/shared");
|
|
196
197
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
197
198
|
|
|
@@ -248,13 +249,13 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
248
249
|
// src/hooks/use-copilot-runtime-client.ts
|
|
249
250
|
var useCopilotRuntimeClient = (options) => {
|
|
250
251
|
const { setBannerError } = useToast();
|
|
251
|
-
const _a = options, { showDevConsole,
|
|
252
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
252
253
|
const lastStructuredErrorRef = (0, import_react3.useRef)(null);
|
|
253
254
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
254
|
-
if (!
|
|
255
|
+
if (!onError || !runtimeOptions.publicApiKey)
|
|
255
256
|
return;
|
|
256
257
|
try {
|
|
257
|
-
const
|
|
258
|
+
const errorEvent = {
|
|
258
259
|
type: "error",
|
|
259
260
|
timestamp: Date.now(),
|
|
260
261
|
context: {
|
|
@@ -265,16 +266,16 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
265
266
|
startTime: Date.now()
|
|
266
267
|
},
|
|
267
268
|
technical: {
|
|
268
|
-
environment:
|
|
269
|
+
environment: "browser",
|
|
269
270
|
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
270
271
|
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
271
272
|
}
|
|
272
273
|
},
|
|
273
274
|
error
|
|
274
275
|
};
|
|
275
|
-
yield
|
|
276
|
-
} catch (
|
|
277
|
-
console.error("Error in
|
|
276
|
+
yield onError(errorEvent);
|
|
277
|
+
} catch (error2) {
|
|
278
|
+
console.error("Error in onError handler:", error2);
|
|
278
279
|
}
|
|
279
280
|
});
|
|
280
281
|
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
@@ -338,7 +339,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
338
339
|
setBannerError(warningError);
|
|
339
340
|
}
|
|
340
341
|
}));
|
|
341
|
-
}, [runtimeOptions, setBannerError, showDevConsole,
|
|
342
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onError]);
|
|
342
343
|
return runtimeClient;
|
|
343
344
|
};
|
|
344
345
|
function createStructuredError(gqlError) {
|
|
@@ -510,6 +511,35 @@ function useChat(options) {
|
|
|
510
511
|
} = options;
|
|
511
512
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
512
513
|
const addErrorToast = useErrorToast();
|
|
514
|
+
const { setBannerError } = useToast();
|
|
515
|
+
const { onError } = useCopilotContext();
|
|
516
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
517
|
+
if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
518
|
+
return;
|
|
519
|
+
try {
|
|
520
|
+
const traceEvent = {
|
|
521
|
+
type: "error",
|
|
522
|
+
timestamp: Date.now(),
|
|
523
|
+
context: {
|
|
524
|
+
source: "ui",
|
|
525
|
+
request: {
|
|
526
|
+
operation: "useChatCompletion",
|
|
527
|
+
url: copilotConfig.chatApiEndpoint,
|
|
528
|
+
startTime: Date.now()
|
|
529
|
+
},
|
|
530
|
+
technical: {
|
|
531
|
+
environment: "browser",
|
|
532
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
533
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
534
|
+
}
|
|
535
|
+
},
|
|
536
|
+
error
|
|
537
|
+
};
|
|
538
|
+
yield onError(traceEvent);
|
|
539
|
+
} catch (traceError) {
|
|
540
|
+
console.error("Error in use-chat onError handler:", traceError);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
513
543
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
514
544
|
agentSessionRef.current = agentSession;
|
|
515
545
|
const runIdRef = (0, import_react5.useRef)(runId);
|
|
@@ -529,7 +559,7 @@ function useChat(options) {
|
|
|
529
559
|
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
530
560
|
const runChatCompletion = useAsyncCallback(
|
|
531
561
|
(previousMessages) => __async(this, null, function* () {
|
|
532
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
562
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
533
563
|
setIsLoading(true);
|
|
534
564
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
535
565
|
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
@@ -661,20 +691,53 @@ function useChat(options) {
|
|
|
661
691
|
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
662
692
|
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
663
693
|
);
|
|
664
|
-
if (messages2.length === 0) {
|
|
665
|
-
continue;
|
|
666
|
-
}
|
|
667
694
|
newMessages = [];
|
|
668
695
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
696
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
669
697
|
newMessages = [
|
|
670
698
|
new import_runtime_client_gql3.TextMessage({
|
|
671
699
|
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
672
|
-
content:
|
|
700
|
+
content: guardrailsReason
|
|
673
701
|
})
|
|
674
702
|
];
|
|
703
|
+
const guardrailsError = new import_shared4.CopilotKitError({
|
|
704
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
705
|
+
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
706
|
+
});
|
|
707
|
+
yield traceUIError(guardrailsError, {
|
|
708
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
709
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
710
|
+
});
|
|
675
711
|
setMessages([...previousMessages, ...newMessages]);
|
|
676
712
|
break;
|
|
677
|
-
}
|
|
713
|
+
}
|
|
714
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
715
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
716
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
717
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
718
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
719
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
720
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
721
|
+
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
722
|
+
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
723
|
+
errorCode = originalCode;
|
|
724
|
+
}
|
|
725
|
+
const structuredError = new import_shared4.CopilotKitError({
|
|
726
|
+
message: errorMessage,
|
|
727
|
+
code: errorCode,
|
|
728
|
+
severity: originalSeverity,
|
|
729
|
+
visibility: originalVisibility
|
|
730
|
+
});
|
|
731
|
+
setBannerError(structuredError);
|
|
732
|
+
yield traceUIError(structuredError, {
|
|
733
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
734
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
735
|
+
originalErrorCode: originalCode,
|
|
736
|
+
preservedStructure: !!originalCode
|
|
737
|
+
});
|
|
738
|
+
setIsLoading(false);
|
|
739
|
+
break;
|
|
740
|
+
} else if (messages2.length > 0) {
|
|
678
741
|
newMessages = [...messages2];
|
|
679
742
|
for (const message of messages2) {
|
|
680
743
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -696,17 +759,22 @@ function useChat(options) {
|
|
|
696
759
|
lastAgentStateMessage.state.messages
|
|
697
760
|
);
|
|
698
761
|
}
|
|
699
|
-
setCoagentStatesWithRef((prevAgentStates) =>
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
762
|
+
setCoagentStatesWithRef((prevAgentStates) => {
|
|
763
|
+
var _a2;
|
|
764
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
765
|
+
[lastAgentStateMessage.agentName]: {
|
|
766
|
+
name: lastAgentStateMessage.agentName,
|
|
767
|
+
state: lastAgentStateMessage.state,
|
|
768
|
+
running: lastAgentStateMessage.running,
|
|
769
|
+
active: lastAgentStateMessage.active,
|
|
770
|
+
threadId: lastAgentStateMessage.threadId,
|
|
771
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
772
|
+
runId: lastAgentStateMessage.runId,
|
|
773
|
+
// Preserve existing config from previous state
|
|
774
|
+
config: (_a2 = prevAgentStates[lastAgentStateMessage.agentName]) == null ? void 0 : _a2.config
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
});
|
|
710
778
|
if (lastAgentStateMessage.running) {
|
|
711
779
|
setAgentSession({
|
|
712
780
|
threadId: lastAgentStateMessage.threadId,
|
|
@@ -736,6 +804,39 @@ function useChat(options) {
|
|
|
736
804
|
newMessages
|
|
737
805
|
);
|
|
738
806
|
let didExecuteAction = false;
|
|
807
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
808
|
+
var _a2;
|
|
809
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
810
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
811
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
812
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
813
|
+
}
|
|
814
|
+
const resultMessage = yield executeAction({
|
|
815
|
+
onFunctionCall,
|
|
816
|
+
message: actionMessage,
|
|
817
|
+
chatAbortControllerRef,
|
|
818
|
+
onError: (error) => {
|
|
819
|
+
addErrorToast([error]);
|
|
820
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
821
|
+
},
|
|
822
|
+
setMessages,
|
|
823
|
+
getFinalMessages: () => finalMessages,
|
|
824
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
825
|
+
});
|
|
826
|
+
didExecuteAction = true;
|
|
827
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
828
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
829
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
830
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
831
|
+
(0, import_react_dom.flushSync)(() => {
|
|
832
|
+
setMessages(messagesForImmediateUpdate);
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
836
|
+
currentAction._setActivatingMessageId(null);
|
|
837
|
+
}
|
|
838
|
+
return resultMessage;
|
|
839
|
+
});
|
|
739
840
|
if (onFunctionCall) {
|
|
740
841
|
const lastMessages = [];
|
|
741
842
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -752,37 +853,28 @@ function useChat(options) {
|
|
|
752
853
|
(action2) => action2.name === message.name
|
|
753
854
|
);
|
|
754
855
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
755
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
756
|
-
var _a2;
|
|
757
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
758
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
759
|
-
const resultMessage = yield executeAction({
|
|
760
|
-
onFunctionCall,
|
|
761
|
-
previousMessages,
|
|
762
|
-
message: message2,
|
|
763
|
-
chatAbortControllerRef,
|
|
764
|
-
onError: (error) => {
|
|
765
|
-
addErrorToast([error]);
|
|
766
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
767
|
-
}
|
|
768
|
-
});
|
|
769
|
-
didExecuteAction = true;
|
|
770
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
771
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
772
|
-
return resultMessage;
|
|
773
|
-
});
|
|
774
856
|
if (action && message.isActionExecutionMessage()) {
|
|
775
|
-
const
|
|
776
|
-
const
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
857
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
858
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
859
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
860
|
+
);
|
|
861
|
+
if (alreadyProcessed) {
|
|
862
|
+
} else {
|
|
863
|
+
const resultMessage = yield executeActionFromMessage(
|
|
864
|
+
action,
|
|
865
|
+
message
|
|
866
|
+
);
|
|
867
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
868
|
+
if (pairedFeAction) {
|
|
869
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
870
|
+
name: pairedFeAction.name,
|
|
871
|
+
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
872
|
+
status: message.status,
|
|
873
|
+
createdAt: message.createdAt,
|
|
874
|
+
parentMessageId: message.parentMessageId
|
|
875
|
+
});
|
|
876
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
877
|
+
}
|
|
786
878
|
}
|
|
787
879
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
788
880
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
@@ -800,16 +892,12 @@ function useChat(options) {
|
|
|
800
892
|
}
|
|
801
893
|
setMessages(finalMessages);
|
|
802
894
|
}
|
|
803
|
-
if (
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
(didExecuteAction || // the last message is a server side result
|
|
807
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
808
|
-
!((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
|
|
809
|
-
) {
|
|
895
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
896
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
897
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
810
898
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
811
899
|
return yield runChatCompletionRef.current(finalMessages);
|
|
812
|
-
} else if ((
|
|
900
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
813
901
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
814
902
|
if (message.isActionExecutionMessage()) {
|
|
815
903
|
return finalMessages.find(
|
|
@@ -820,7 +908,7 @@ function useChat(options) {
|
|
|
820
908
|
});
|
|
821
909
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
822
910
|
setMessages(repairedMessages);
|
|
823
|
-
if ((
|
|
911
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
824
912
|
setAgentSession({
|
|
825
913
|
threadId: agentSessionRef.current.threadId,
|
|
826
914
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -914,21 +1002,35 @@ function useChat(options) {
|
|
|
914
1002
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
915
1003
|
);
|
|
916
1004
|
const reload = useAsyncCallback(
|
|
917
|
-
(
|
|
1005
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
918
1006
|
if (isLoading || messages.length === 0) {
|
|
919
1007
|
return;
|
|
920
1008
|
}
|
|
921
|
-
const
|
|
922
|
-
if (
|
|
923
|
-
console.warn(`Message with id ${
|
|
1009
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
1010
|
+
if (reloadMessageIndex === -1) {
|
|
1011
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
924
1012
|
return;
|
|
925
1013
|
}
|
|
926
|
-
|
|
927
|
-
if (
|
|
928
|
-
|
|
1014
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
1015
|
+
if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
|
|
1016
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
1017
|
+
return;
|
|
929
1018
|
}
|
|
930
|
-
|
|
931
|
-
|
|
1019
|
+
let historyCutoff = [];
|
|
1020
|
+
if (messages.length > 2) {
|
|
1021
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
1022
|
+
(msg) => (
|
|
1023
|
+
// @ts-expect-error -- message has role
|
|
1024
|
+
msg.role === import_runtime_client_gql3.MessageRole.User
|
|
1025
|
+
)
|
|
1026
|
+
);
|
|
1027
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1028
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1029
|
+
);
|
|
1030
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
1031
|
+
}
|
|
1032
|
+
setMessages(historyCutoff);
|
|
1033
|
+
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
932
1034
|
}),
|
|
933
1035
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
934
1036
|
);
|
|
@@ -963,20 +1065,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
963
1065
|
function executeAction(_0) {
|
|
964
1066
|
return __async(this, arguments, function* ({
|
|
965
1067
|
onFunctionCall,
|
|
966
|
-
previousMessages,
|
|
967
1068
|
message,
|
|
968
1069
|
chatAbortControllerRef,
|
|
969
|
-
onError
|
|
1070
|
+
onError,
|
|
1071
|
+
setMessages,
|
|
1072
|
+
getFinalMessages,
|
|
1073
|
+
isRenderAndWait
|
|
970
1074
|
}) {
|
|
971
1075
|
let result;
|
|
972
1076
|
let error = null;
|
|
1077
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
1078
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
1079
|
+
messages: currentMessagesForHandler,
|
|
1080
|
+
name: message.name,
|
|
1081
|
+
args: message.arguments
|
|
1082
|
+
});
|
|
1083
|
+
if (isRenderAndWait) {
|
|
1084
|
+
const currentMessagesForRender = getFinalMessages();
|
|
1085
|
+
(0, import_react_dom.flushSync)(() => {
|
|
1086
|
+
setMessages([...currentMessagesForRender]);
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
973
1089
|
try {
|
|
974
1090
|
result = yield Promise.race([
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
name: message.name,
|
|
978
|
-
args: message.arguments
|
|
979
|
-
}),
|
|
1091
|
+
handlerReturnedPromise,
|
|
1092
|
+
// Await the promise returned by the handler
|
|
980
1093
|
new Promise(
|
|
981
1094
|
(resolve) => {
|
|
982
1095
|
var _a;
|
|
@@ -1024,7 +1137,7 @@ function getPairedFeAction(actions, message) {
|
|
|
1024
1137
|
|
|
1025
1138
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1026
1139
|
var import_react7 = require("react");
|
|
1027
|
-
var
|
|
1140
|
+
var import_react_dom2 = require("react-dom");
|
|
1028
1141
|
var import_shared5 = require("@copilotkit/shared");
|
|
1029
1142
|
|
|
1030
1143
|
// src/context/copilot-messages-context.tsx
|
|
@@ -1269,6 +1382,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1269
1382
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1270
1383
|
const idRef = (0, import_react9.useRef)((0, import_shared6.randomId)());
|
|
1271
1384
|
const renderAndWaitRef = (0, import_react9.useRef)(null);
|
|
1385
|
+
const activatingMessageIdRef = (0, import_react9.useRef)(null);
|
|
1272
1386
|
const { addToast } = useToast();
|
|
1273
1387
|
action = __spreadValues({}, action);
|
|
1274
1388
|
if (
|
|
@@ -1276,30 +1390,48 @@ function useCopilotAction(action, dependencies) {
|
|
|
1276
1390
|
isFrontendAction(action) && // check if renderAndWaitForResponse is set
|
|
1277
1391
|
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
1278
1392
|
) {
|
|
1393
|
+
action._isRenderAndWait = true;
|
|
1279
1394
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
1280
1395
|
action.renderAndWait = void 0;
|
|
1281
1396
|
action.renderAndWaitForResponse = void 0;
|
|
1397
|
+
action._setActivatingMessageId = (id) => {
|
|
1398
|
+
activatingMessageIdRef.current = id;
|
|
1399
|
+
};
|
|
1282
1400
|
action.handler = useAsyncCallback(() => __async(this, null, function* () {
|
|
1401
|
+
const currentActivatingId = activatingMessageIdRef.current;
|
|
1283
1402
|
let resolve;
|
|
1284
1403
|
let reject;
|
|
1285
1404
|
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
1286
1405
|
resolve = resolvePromise;
|
|
1287
1406
|
reject = rejectPromise;
|
|
1288
1407
|
});
|
|
1289
|
-
renderAndWaitRef.current = {
|
|
1290
|
-
|
|
1408
|
+
renderAndWaitRef.current = {
|
|
1409
|
+
promise,
|
|
1410
|
+
resolve,
|
|
1411
|
+
reject,
|
|
1412
|
+
messageId: currentActivatingId
|
|
1413
|
+
};
|
|
1414
|
+
const result = yield promise;
|
|
1415
|
+
return result;
|
|
1291
1416
|
}), []);
|
|
1292
1417
|
action.render = (props) => {
|
|
1418
|
+
const currentRenderMessageId = props.messageId;
|
|
1293
1419
|
let status = props.status;
|
|
1294
|
-
if (props.status === "executing"
|
|
1295
|
-
|
|
1420
|
+
if (props.status === "executing") {
|
|
1421
|
+
if (!renderAndWaitRef.current || !renderAndWaitRef.current.promise) {
|
|
1422
|
+
status = "inProgress";
|
|
1423
|
+
} else if (renderAndWaitRef.current.messageId !== currentRenderMessageId && activatingMessageIdRef.current !== currentRenderMessageId) {
|
|
1424
|
+
status = "inProgress";
|
|
1425
|
+
}
|
|
1296
1426
|
}
|
|
1297
1427
|
const waitProps = {
|
|
1298
1428
|
status,
|
|
1299
1429
|
args: props.args,
|
|
1300
1430
|
result: props.result,
|
|
1301
|
-
handler
|
|
1302
|
-
|
|
1431
|
+
// handler and respond should only be provided if this is the truly active instance
|
|
1432
|
+
// and its promise infrastructure is ready.
|
|
1433
|
+
handler: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0,
|
|
1434
|
+
respond: status === "executing" && renderAndWaitRef.current && renderAndWaitRef.current.messageId === currentRenderMessageId ? renderAndWaitRef.current.resolve : void 0
|
|
1303
1435
|
};
|
|
1304
1436
|
const isNoArgsRenderWait = (_fn) => {
|
|
1305
1437
|
var _a;
|
|
@@ -1542,6 +1674,9 @@ function useCoAgent(options) {
|
|
|
1542
1674
|
threadId,
|
|
1543
1675
|
agentName: name
|
|
1544
1676
|
});
|
|
1677
|
+
if (result.error) {
|
|
1678
|
+
return;
|
|
1679
|
+
}
|
|
1545
1680
|
const newState = (_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.state;
|
|
1546
1681
|
if (newState === lastLoadedState.current)
|
|
1547
1682
|
return;
|
|
@@ -1565,6 +1700,32 @@ function useCoAgent(options) {
|
|
|
1565
1700
|
// reset initialstate on reset
|
|
1566
1701
|
coagentStates[name] === void 0
|
|
1567
1702
|
]);
|
|
1703
|
+
(0, import_react13.useEffect)(() => {
|
|
1704
|
+
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
1705
|
+
if (newConfig === void 0)
|
|
1706
|
+
return;
|
|
1707
|
+
setCoagentStatesWithRef((prev) => {
|
|
1708
|
+
var _a;
|
|
1709
|
+
const existing = (_a = prev[name]) != null ? _a : {
|
|
1710
|
+
name,
|
|
1711
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1712
|
+
config: {},
|
|
1713
|
+
running: false,
|
|
1714
|
+
active: false,
|
|
1715
|
+
threadId: void 0,
|
|
1716
|
+
nodeName: void 0,
|
|
1717
|
+
runId: void 0
|
|
1718
|
+
};
|
|
1719
|
+
if (JSON.stringify(existing.config) === JSON.stringify(newConfig)) {
|
|
1720
|
+
return prev;
|
|
1721
|
+
}
|
|
1722
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
1723
|
+
[name]: __spreadProps(__spreadValues({}, existing), {
|
|
1724
|
+
config: newConfig
|
|
1725
|
+
})
|
|
1726
|
+
});
|
|
1727
|
+
});
|
|
1728
|
+
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
1568
1729
|
const runAgentCallback = useAsyncCallback(
|
|
1569
1730
|
(hint) => __async(this, null, function* () {
|
|
1570
1731
|
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|