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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/dist/{chunk-XERJQUHA.mjs → chunk-4CEQJ2X6.mjs} +2 -2
  3. package/dist/{chunk-XERJQUHA.mjs.map → chunk-4CEQJ2X6.mjs.map} +1 -1
  4. package/dist/{chunk-VMYLY5KI.mjs → chunk-4EC4JK7H.mjs} +58 -48
  5. package/dist/chunk-4EC4JK7H.mjs.map +1 -0
  6. package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
  7. package/dist/chunk-F7O6L7C3.mjs.map +1 -0
  8. package/dist/{chunk-2DPTBHGN.mjs → chunk-FUO5LKSJ.mjs} +115 -63
  9. package/dist/chunk-FUO5LKSJ.mjs.map +1 -0
  10. package/dist/{chunk-4ED56DQX.mjs → chunk-HBCP2KNA.mjs} +3 -4
  11. package/dist/chunk-HBCP2KNA.mjs.map +1 -0
  12. package/dist/{chunk-Z3U4UBG2.mjs → chunk-T4CAQC6B.mjs} +2 -2
  13. package/dist/{chunk-JFCNSGNU.mjs → chunk-Y2T56VSE.mjs} +2 -2
  14. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
  15. package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
  16. package/dist/components/copilot-provider/index.d.ts +1 -2
  17. package/dist/components/index.d.ts +1 -2
  18. package/dist/context/copilot-context.d.ts +10 -148
  19. package/dist/context/index.d.ts +1 -2
  20. package/dist/copilot-context-9ae8990b.d.ts +183 -0
  21. package/dist/hooks/index.d.ts +1 -2
  22. package/dist/hooks/index.js +180 -123
  23. package/dist/hooks/index.js.map +1 -1
  24. package/dist/hooks/index.mjs +6 -6
  25. package/dist/hooks/use-chat.d.ts +1 -2
  26. package/dist/hooks/use-chat.js +113 -64
  27. package/dist/hooks/use-chat.js.map +1 -1
  28. package/dist/hooks/use-chat.mjs +2 -2
  29. package/dist/hooks/use-coagent.d.ts +1 -2
  30. package/dist/hooks/use-coagent.js +171 -112
  31. package/dist/hooks/use-coagent.js.map +1 -1
  32. package/dist/hooks/use-coagent.mjs +4 -4
  33. package/dist/hooks/use-copilot-chat.d.ts +1 -2
  34. package/dist/hooks/use-copilot-chat.js +116 -67
  35. package/dist/hooks/use-copilot-chat.js.map +1 -1
  36. package/dist/hooks/use-copilot-chat.mjs +3 -3
  37. package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
  38. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  39. package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
  40. package/dist/hooks/use-langgraph-interrupt.d.ts +9 -2
  41. package/dist/hooks/use-langgraph-interrupt.js +117 -69
  42. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  43. package/dist/hooks/use-langgraph-interrupt.mjs +4 -4
  44. package/dist/index.d.ts +1 -2
  45. package/dist/index.js +187 -130
  46. package/dist/index.js.map +1 -1
  47. package/dist/index.mjs +7 -7
  48. package/dist/lib/copilot-task.d.ts +1 -2
  49. package/dist/lib/copilot-task.js +1 -1
  50. package/dist/lib/copilot-task.js.map +1 -1
  51. package/dist/lib/copilot-task.mjs +2 -2
  52. package/dist/lib/index.d.ts +1 -2
  53. package/dist/lib/index.js +1 -1
  54. package/dist/lib/index.js.map +1 -1
  55. package/dist/lib/index.mjs +2 -2
  56. package/dist/types/frontend-action.d.ts +2 -1
  57. package/dist/types/frontend-action.js +1 -1
  58. package/dist/types/frontend-action.js.map +1 -1
  59. package/dist/types/frontend-action.mjs +1 -1
  60. package/dist/types/interrupt-action.d.ts +10 -35
  61. package/dist/types/interrupt-action.js.map +1 -1
  62. package/dist/utils/extract.d.ts +1 -2
  63. package/dist/utils/index.d.ts +1 -2
  64. package/package.json +3 -3
  65. package/src/hooks/use-chat.ts +134 -61
  66. package/src/hooks/use-coagent.ts +70 -56
  67. package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
  68. package/src/hooks/use-langgraph-interrupt.ts +1 -2
  69. package/src/types/frontend-action.ts +5 -2
  70. package/src/types/interrupt-action.ts +16 -12
  71. package/dist/chunk-2DPTBHGN.mjs.map +0 -1
  72. package/dist/chunk-4ED56DQX.mjs.map +0 -1
  73. package/dist/chunk-VMYLY5KI.mjs.map +0 -1
  74. package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
  75. /package/dist/{chunk-Z3U4UBG2.mjs.map → chunk-T4CAQC6B.mjs.map} +0 -0
  76. /package/dist/{chunk-JFCNSGNU.mjs.map → chunk-Y2T56VSE.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-chat.ts"],"sourcesContent":["import React, { useCallback, useRef } from \"react\";\nimport {\n FunctionCallHandler,\n COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,\n CoAgentStateRenderHandler,\n randomId,\n parseJson,\n} from \"@copilotkit/shared\";\nimport {\n Message,\n TextMessage,\n ResultMessage,\n convertMessagesToGqlInput,\n filterAdjacentAgentStateMessages,\n filterAgentStateMessages,\n convertGqlOutputToMessages,\n MessageStatusCode,\n MessageRole,\n Role,\n CopilotRequestType,\n ForwardedParametersInput,\n loadMessagesFromJsonRepresentation,\n ExtensionsInput,\n CopilotRuntimeClient,\n langGraphInterruptEvent,\n MetaEvent,\n MetaEventName,\n ActionExecutionMessage,\n CopilotKitLangGraphInterruptEvent,\n LangGraphInterruptEvent,\n MetaEventInput,\n} from \"@copilotkit/runtime-client-gql\";\n\nimport { CopilotApiConfig } from \"../context\";\nimport { FrontendAction, processActionsForRuntimeRequest } from \"../types/frontend-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { AgentSession } from \"../context/copilot-context\";\nimport { useCopilotRuntimeClient } from \"./use-copilot-runtime-client\";\nimport { useAsyncCallback, useErrorToast } from \"../components/error-boundary/error-utils\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\n\nexport type UseChatOptions = {\n /**\n * System messages of the chat. Defaults to an empty array.\n */\n initialMessages?: Message[];\n /**\n * Callback function to be called when a function call is received.\n * If the function returns a `ChatRequest` object, the request will be sent\n * automatically to the API and will be used to update the chat.\n */\n onFunctionCall?: FunctionCallHandler;\n\n /**\n * Callback function to be called when a coagent action is received.\n */\n onCoAgentStateRender?: CoAgentStateRenderHandler;\n\n /**\n * Function definitions to be sent to the API.\n */\n actions: FrontendAction<any>[];\n\n /**\n * The CopilotKit API configuration.\n */\n copilotConfig: CopilotApiConfig;\n\n /**\n * The current list of messages in the chat.\n */\n messages: Message[];\n /**\n * The setState-powered method to update the chat messages.\n */\n setMessages: React.Dispatch<React.SetStateAction<Message[]>>;\n\n /**\n * A callback to get the latest system message.\n */\n makeSystemMessageCallback: () => TextMessage;\n\n /**\n * Whether the API request is in progress\n */\n isLoading: boolean;\n\n /**\n * setState-powered method to update the isChatLoading value\n */\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n /**\n * The current list of coagent states.\n */\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n\n /**\n * setState-powered method to update the agent states\n */\n setCoagentStatesWithRef: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n\n /**\n * The current agent session.\n */\n agentSession: AgentSession | null;\n\n /**\n * setState-powered method to update the agent session\n */\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n /**\n * The forwarded parameters.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n\n /**\n * The current thread ID.\n */\n threadId: string;\n /**\n * set the current thread ID\n */\n setThreadId: (threadId: string) => void;\n /**\n * The current run ID.\n */\n runId: string | null;\n /**\n * set the current run ID\n */\n setRunId: (runId: string | null) => void;\n /**\n * The global chat abort controller.\n */\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n /**\n * The agent lock.\n */\n agentLock: string | null;\n /**\n * The extensions.\n */\n extensions: ExtensionsInput;\n /**\n * The setState-powered method to update the extensions.\n */\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n\n langGraphInterruptAction: LangGraphInterruptAction | null;\n\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n};\n\nexport type UseChatHelpers = {\n /**\n * Append a user message to the chat list. This triggers the API call to fetch\n * the assistant's response.\n * @param message The message to append\n */\n append: (message: Message, options?: AppendMessageOptions) => Promise<void>;\n /**\n * Reload the last AI chat response for the given chat history. If the last\n * message isn't from the assistant, it will request the API to generate a\n * new response.\n */\n reload: () => Promise<void>;\n /**\n * Abort the current request immediately, keep the generated tokens if any.\n */\n stop: () => void;\n\n /**\n * Run the chat completion.\n */\n runChatCompletion: () => Promise<Message[]>;\n};\n\nexport interface AppendMessageOptions {\n /**\n * Whether to run the chat completion after appending the message. Defaults to `true`.\n */\n followUp?: boolean;\n}\n\nexport function useChat(options: UseChatOptions): UseChatHelpers {\n const {\n messages,\n setMessages,\n makeSystemMessageCallback,\n copilotConfig,\n setIsLoading,\n initialMessages,\n isLoading,\n actions,\n onFunctionCall,\n onCoAgentStateRender,\n setCoagentStatesWithRef,\n coagentStatesRef,\n agentSession,\n setAgentSession,\n threadId,\n setThreadId,\n runId,\n setRunId,\n chatAbortControllerRef,\n agentLock,\n extensions,\n setExtensions,\n langGraphInterruptAction,\n setLangGraphInterruptAction,\n } = options;\n const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();\n const addErrorToast = useErrorToast();\n // We need to keep a ref of coagent states and session because of renderAndWait - making sure\n // the latest state is sent to the API\n // This is a workaround and needs to be addressed in the future\n const agentSessionRef = useRef<AgentSession | null>(agentSession);\n agentSessionRef.current = agentSession;\n\n const runIdRef = useRef<string | null>(runId);\n runIdRef.current = runId;\n const extensionsRef = useRef<ExtensionsInput>(extensions);\n extensionsRef.current = extensions;\n\n const publicApiKey = copilotConfig.publicApiKey;\n\n const headers = {\n ...(copilotConfig.headers || {}),\n ...(publicApiKey ? { [COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {}),\n };\n\n const runtimeClient = useCopilotRuntimeClient({\n url: copilotConfig.chatApiEndpoint,\n publicApiKey: copilotConfig.publicApiKey,\n headers,\n credentials: copilotConfig.credentials,\n });\n\n const runChatCompletion = useAsyncCallback(\n async (previousMessages: Message[]): Promise<Message[]> => {\n setIsLoading(true);\n const interruptEvent = langGraphInterruptAction?.event;\n // In case an interrupt event exist and valid but has no response yet, we cannot process further messages to an agent\n if (\n interruptEvent?.name === MetaEventName.LangGraphInterruptEvent &&\n interruptEvent?.value &&\n !interruptEvent?.response &&\n agentSessionRef.current\n ) {\n addErrorToast([\n new Error(\n \"A message was sent while interrupt is active. This will cause failure on the agent side\",\n ),\n ]);\n }\n\n // this message is just a placeholder. It will disappear once the first real message\n // is received\n let newMessages: Message[] = [\n new TextMessage({\n content: \"\",\n role: Role.Assistant,\n }),\n ];\n\n chatAbortControllerRef.current = new AbortController();\n\n setMessages([...previousMessages, ...newMessages]);\n\n const systemMessage = makeSystemMessageCallback();\n\n const messagesWithContext = [systemMessage, ...(initialMessages || []), ...previousMessages];\n\n const isAgentRun = agentSessionRef.current !== null;\n\n const stream = runtimeClient.asStream(\n runtimeClient.generateCopilotResponse({\n data: {\n frontend: {\n actions: processActionsForRuntimeRequest(actions),\n url: window.location.href,\n },\n threadId: threadId,\n runId: runIdRef.current,\n extensions: extensionsRef.current,\n metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction?.event]),\n messages: convertMessagesToGqlInput(filterAgentStateMessages(messagesWithContext)),\n ...(copilotConfig.cloud\n ? {\n cloud: {\n ...(copilotConfig.cloud.guardrails?.input?.restrictToTopic?.enabled\n ? {\n guardrails: {\n inputValidationRules: {\n allowList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,\n denyList:\n copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics,\n },\n },\n }\n : {}),\n },\n }\n : {}),\n metadata: {\n requestType: CopilotRequestType.Chat,\n },\n ...(agentSessionRef.current\n ? {\n agentSession: agentSessionRef.current,\n }\n : {}),\n agentStates: Object.values(coagentStatesRef.current!).map((state) => ({\n agentName: state.name,\n state: JSON.stringify(state.state),\n configurable: JSON.stringify(state.configurable ?? {}),\n })),\n forwardedParameters: options.forwardedParameters || {},\n },\n properties: copilotConfig.properties,\n signal: chatAbortControllerRef.current?.signal,\n }),\n );\n\n const guardrailsEnabled =\n copilotConfig.cloud?.guardrails?.input?.restrictToTopic.enabled || false;\n\n const reader = stream.getReader();\n\n let executedCoAgentStateRenders: string[] = [];\n let followUp: FrontendAction[\"followUp\"] = undefined;\n\n let messages: Message[] = [];\n let syncedMessages: Message[] = [];\n let interruptMessages: Message[] = [];\n\n try {\n while (true) {\n let done, value;\n\n try {\n const readResult = await reader.read();\n done = readResult.done;\n value = readResult.value;\n } catch (readError) {\n break;\n }\n\n if (done) {\n if (chatAbortControllerRef.current.signal.aborted) {\n return [];\n }\n break;\n }\n\n if (!value?.generateCopilotResponse) {\n continue;\n }\n\n runIdRef.current = value.generateCopilotResponse.runId || null;\n\n // in the output, graphql inserts __typename, which leads to an error when sending it along\n // as input to the next request.\n extensionsRef.current = CopilotRuntimeClient.removeGraphQLTypename(\n value.generateCopilotResponse.extensions || {},\n );\n\n // setThreadId(threadIdRef.current);\n setRunId(runIdRef.current);\n setExtensions(extensionsRef.current);\n let rawMessagesResponse = value.generateCopilotResponse.messages;\n (value.generateCopilotResponse?.metaEvents ?? []).forEach((ev) => {\n if (ev.name === MetaEventName.LangGraphInterruptEvent) {\n let eventValue = langGraphInterruptEvent(ev as LangGraphInterruptEvent).value;\n eventValue = parseJson(eventValue, eventValue);\n setLangGraphInterruptAction({\n event: {\n ...langGraphInterruptEvent(ev as LangGraphInterruptEvent),\n value: eventValue,\n },\n });\n }\n if (ev.name === MetaEventName.CopilotKitLangGraphInterruptEvent) {\n const data = (ev as CopilotKitLangGraphInterruptEvent).data;\n\n // @ts-expect-error -- same type of messages\n rawMessagesResponse = [...rawMessagesResponse, ...data.messages];\n interruptMessages = convertGqlOutputToMessages(\n // @ts-ignore\n filterAdjacentAgentStateMessages(data.messages),\n );\n }\n });\n\n messages = convertGqlOutputToMessages(\n filterAdjacentAgentStateMessages(rawMessagesResponse),\n );\n\n if (messages.length === 0) {\n continue;\n }\n\n newMessages = [];\n\n // request failed, display error message and quit\n if (\n value.generateCopilotResponse.status?.__typename === \"FailedResponseStatus\" &&\n value.generateCopilotResponse.status.reason === \"GUARDRAILS_VALIDATION_FAILED\"\n ) {\n newMessages = [\n new TextMessage({\n role: MessageRole.Assistant,\n content: value.generateCopilotResponse.status.details?.guardrailsReason || \"\",\n }),\n ];\n setMessages([...previousMessages, ...newMessages]);\n break;\n }\n\n // add messages to the chat\n else {\n newMessages = [...messages];\n\n for (const message of messages) {\n // execute onCoAgentStateRender handler\n if (\n message.isAgentStateMessage() &&\n !message.active &&\n !executedCoAgentStateRenders.includes(message.id) &&\n onCoAgentStateRender\n ) {\n // Do not execute a coagent action if guardrails are enabled but the status is not known\n if (guardrailsEnabled && value.generateCopilotResponse.status === undefined) {\n break;\n }\n // execute coagent action\n await onCoAgentStateRender({\n name: message.agentName,\n nodeName: message.nodeName,\n state: message.state,\n });\n executedCoAgentStateRenders.push(message.id);\n }\n }\n\n const lastAgentStateMessage = [...messages]\n .reverse()\n .find((message) => message.isAgentStateMessage());\n\n if (lastAgentStateMessage) {\n if (\n lastAgentStateMessage.state.messages &&\n lastAgentStateMessage.state.messages.length > 0\n ) {\n syncedMessages = loadMessagesFromJsonRepresentation(\n lastAgentStateMessage.state.messages,\n );\n }\n setCoagentStatesWithRef((prevAgentStates) => ({\n ...prevAgentStates,\n [lastAgentStateMessage.agentName]: {\n name: lastAgentStateMessage.agentName,\n state: lastAgentStateMessage.state,\n running: lastAgentStateMessage.running,\n active: lastAgentStateMessage.active,\n threadId: lastAgentStateMessage.threadId,\n nodeName: lastAgentStateMessage.nodeName,\n runId: lastAgentStateMessage.runId,\n },\n }));\n if (lastAgentStateMessage.running) {\n setAgentSession({\n threadId: lastAgentStateMessage.threadId,\n agentName: lastAgentStateMessage.agentName,\n nodeName: lastAgentStateMessage.nodeName,\n });\n } else {\n if (agentLock) {\n setAgentSession({\n threadId: randomId(),\n agentName: agentLock,\n nodeName: undefined,\n });\n } else {\n setAgentSession(null);\n }\n }\n }\n }\n\n if (newMessages.length > 0) {\n // Update message state\n setMessages([...previousMessages, ...newMessages]);\n }\n }\n let finalMessages = constructFinalMessages(\n [...syncedMessages, ...interruptMessages],\n previousMessages,\n newMessages,\n );\n\n let didExecuteAction = false;\n\n // execute regular action executions that are specific to the frontend (last actions)\n if (onFunctionCall) {\n // Find consecutive action execution messages at the end\n const lastMessages = [];\n for (let i = finalMessages.length - 1; i >= 0; i--) {\n const message = finalMessages[i];\n if (\n (message.isActionExecutionMessage() || message.isResultMessage()) &&\n message.status.code !== MessageStatusCode.Pending\n ) {\n lastMessages.unshift(message);\n } else {\n break;\n }\n }\n\n for (const message of lastMessages) {\n // We update the message state before calling the handler so that the render\n // function can be called with `executing` state\n setMessages(finalMessages);\n\n const action = actions.find(\n (action) => action.name === (message as ActionExecutionMessage).name,\n );\n const currentResultMessagePairedFeAction = message.isResultMessage()\n ? getPairedFeAction(actions, message)\n : null;\n\n const executeActionFromMessage = async (\n action: FrontendAction<any>,\n message: ActionExecutionMessage,\n ) => {\n followUp = action?.followUp;\n const resultMessage = await executeAction({\n onFunctionCall,\n previousMessages,\n message,\n chatAbortControllerRef,\n onError: (error: Error) => {\n addErrorToast([error]);\n console.error(`Failed to execute action ${message.name}: ${error}`);\n },\n });\n didExecuteAction = true;\n const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);\n finalMessages.splice(messageIndex + 1, 0, resultMessage);\n\n return resultMessage;\n };\n\n // execution message which has an action registered with the hook (remote availability):\n // execute that action first, and then the \"paired FE action\"\n if (action && message.isActionExecutionMessage()) {\n const resultMessage = await executeActionFromMessage(action, message);\n const pairedFeAction = getPairedFeAction(actions, resultMessage);\n\n if (pairedFeAction) {\n const newExecutionMessage = new ActionExecutionMessage({\n name: pairedFeAction.name,\n arguments: parseJson(resultMessage.result, resultMessage.result),\n status: message.status,\n createdAt: message.createdAt,\n parentMessageId: message.parentMessageId,\n });\n await executeActionFromMessage(pairedFeAction, newExecutionMessage);\n }\n } else if (message.isResultMessage() && currentResultMessagePairedFeAction) {\n // Actions which are set up in runtime actions array: Grab the result, executed paired FE action with it as args.\n const newExecutionMessage = new ActionExecutionMessage({\n name: currentResultMessagePairedFeAction.name,\n arguments: parseJson(message.result, message.result),\n status: message.status,\n createdAt: message.createdAt,\n });\n finalMessages.push(newExecutionMessage);\n await executeActionFromMessage(\n currentResultMessagePairedFeAction,\n newExecutionMessage,\n );\n }\n }\n\n setMessages(finalMessages);\n }\n\n if (\n // if followUp is not explicitly false\n followUp !== false &&\n // and we executed an action\n (didExecuteAction ||\n // the last message is a server side result\n (!isAgentRun &&\n finalMessages.length &&\n finalMessages[finalMessages.length - 1].isResultMessage())) &&\n // the user did not stop generation\n !chatAbortControllerRef.current?.signal.aborted\n ) {\n // run the completion again and return the result\n\n // wait for next tick to make sure all the react state updates\n // - tried using react-dom's flushSync, but it did not work\n await new Promise((resolve) => setTimeout(resolve, 10));\n\n return await runChatCompletionRef.current!(finalMessages);\n } else if (chatAbortControllerRef.current?.signal.aborted) {\n // filter out all the action execution messages that do not have a consecutive matching result message\n const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {\n if (message.isActionExecutionMessage()) {\n return finalMessages.find(\n (msg, resultIndex) =>\n msg.isResultMessage() &&\n msg.actionExecutionId === message.id &&\n resultIndex === actionExecutionIndex + 1,\n );\n }\n return true;\n });\n const repairedMessageIds = repairedMessages.map((message) => message.id);\n setMessages(repairedMessages);\n\n // LangGraph needs two pieces of information to continue execution:\n // 1. The threadId\n // 2. The nodeName it came from\n // When stopping the agent, we don't know the nodeName the agent would have ended with\n // Therefore, we set the nodeName to the most reasonable thing we can guess, which\n // is \"__end__\"\n if (agentSessionRef.current?.nodeName) {\n setAgentSession({\n threadId: agentSessionRef.current.threadId,\n agentName: agentSessionRef.current.agentName,\n nodeName: \"__end__\",\n });\n }\n // only return new messages that were not filtered out\n return newMessages.filter((message) => repairedMessageIds.includes(message.id));\n } else {\n return newMessages.slice();\n }\n } finally {\n setIsLoading(false);\n }\n },\n [\n messages,\n setMessages,\n makeSystemMessageCallback,\n copilotConfig,\n setIsLoading,\n initialMessages,\n isLoading,\n actions,\n onFunctionCall,\n onCoAgentStateRender,\n setCoagentStatesWithRef,\n coagentStatesRef,\n agentSession,\n setAgentSession,\n ],\n );\n\n runChatCompletionRef.current = runChatCompletion;\n\n const runChatCompletionAndHandleFunctionCall = useAsyncCallback(\n async (messages: Message[]): Promise<void> => {\n await runChatCompletionRef.current!(messages);\n },\n [messages],\n );\n\n // Go over all events and see that they include data that should be returned to the agent\n const composeAndFlushMetaEventsInput = useCallback(\n (metaEvents: (MetaEvent | undefined | null)[]) => {\n return metaEvents.reduce((acc: MetaEventInput[], event) => {\n if (!event) return acc;\n\n switch (event.name) {\n case MetaEventName.LangGraphInterruptEvent:\n if (event.response) {\n // Flush interrupt event from state\n setLangGraphInterruptAction(null);\n const value = (event as LangGraphInterruptEvent).value;\n return [\n ...acc,\n {\n name: event.name,\n value: typeof value === \"string\" ? value : JSON.stringify(value),\n response:\n typeof event.response === \"string\"\n ? event.response\n : JSON.stringify(event.response),\n },\n ];\n }\n return acc;\n default:\n return acc;\n }\n }, []);\n },\n [setLangGraphInterruptAction],\n );\n\n const append = useAsyncCallback(\n async (message: Message, options?: AppendMessageOptions): Promise<void> => {\n if (isLoading) {\n return;\n }\n\n const newMessages = [...messages, message];\n setMessages(newMessages);\n const followUp = options?.followUp ?? true;\n if (followUp) {\n return runChatCompletionAndHandleFunctionCall(newMessages);\n }\n },\n [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall],\n );\n\n const reload = useAsyncCallback(async (): Promise<void> => {\n if (isLoading || messages.length === 0) {\n return;\n }\n let newMessages = [...messages];\n const lastMessage = messages[messages.length - 1];\n\n if (lastMessage.isTextMessage() && lastMessage.role === \"assistant\") {\n newMessages = newMessages.slice(0, -1);\n }\n\n setMessages(newMessages);\n\n return runChatCompletionAndHandleFunctionCall(newMessages);\n }, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);\n\n const stop = (): void => {\n chatAbortControllerRef.current?.abort(\"Stop was called\");\n };\n\n return {\n append,\n reload,\n stop,\n runChatCompletion: () => runChatCompletionRef.current!(messages),\n };\n}\n\nfunction constructFinalMessages(\n syncedMessages: Message[],\n previousMessages: Message[],\n newMessages: Message[],\n): Message[] {\n const finalMessages =\n syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];\n\n if (syncedMessages.length > 0) {\n const messagesWithAgentState = [...previousMessages, ...newMessages];\n\n let previousMessageId: string | undefined = undefined;\n\n for (const message of messagesWithAgentState) {\n if (message.isAgentStateMessage()) {\n // insert this message into finalMessages after the position of previousMessageId\n const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);\n if (index !== -1) {\n finalMessages.splice(index + 1, 0, message);\n }\n }\n\n previousMessageId = message.id;\n }\n }\n\n return finalMessages;\n}\n\nasync function executeAction({\n onFunctionCall,\n previousMessages,\n message,\n chatAbortControllerRef,\n onError,\n}: {\n onFunctionCall: FunctionCallHandler;\n previousMessages: Message[];\n message: ActionExecutionMessage;\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n onError: (error: Error) => void;\n}) {\n let result: any;\n let error: Error | null = null;\n try {\n result = await Promise.race([\n onFunctionCall({\n messages: previousMessages,\n name: message.name,\n args: message.arguments,\n }),\n new Promise((resolve) =>\n chatAbortControllerRef.current?.signal.addEventListener(\"abort\", () =>\n resolve(\"Operation was aborted by the user\"),\n ),\n ),\n // if the user stopped generation, we also abort consecutive actions\n new Promise((resolve) => {\n if (chatAbortControllerRef.current?.signal.aborted) {\n resolve(\"Operation was aborted by the user\");\n }\n }),\n ]);\n } catch (e) {\n onError(e as Error);\n }\n return new ResultMessage({\n id: \"result-\" + message.id,\n result: ResultMessage.encodeResult(\n error\n ? {\n content: result,\n error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))),\n }\n : result,\n ),\n actionExecutionId: message.id,\n actionName: message.name,\n });\n}\n\nfunction getPairedFeAction(\n actions: FrontendAction<any>[],\n message: ActionExecutionMessage | ResultMessage,\n) {\n let actionName = null;\n if (message.isActionExecutionMessage()) {\n actionName = message.name;\n } else if (message.isResultMessage()) {\n actionName = message.actionName;\n }\n return actions.find(\n (action) =>\n (action.name === actionName && action.available === \"frontend\") ||\n action.pairedAction === actionName,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAgB,aAAa,cAAc;AAC3C;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OAIK;AA8JA,SAAS,QAAQ,SAAyC;AAC/D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,uBAAuB,OAA4D;AACzF,QAAM,gBAAgB,cAAc;AAIpC,QAAM,kBAAkB,OAA4B,YAAY;AAChE,kBAAgB,UAAU;AAE1B,QAAM,WAAW,OAAsB,KAAK;AAC5C,WAAS,UAAU;AACnB,QAAM,gBAAgB,OAAwB,UAAU;AACxD,gBAAc,UAAU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AO,SAAS;AAClD,oBAAQ,mCAAmC;AAAA,UAC7C;AAAA,QACF,CAAC;AAAA,MACH,CAAC;AAAA,IACH,SAAS,GAAP;AACA,cAAQ,CAAU;AAAA,IACpB;AACA,WAAO,IAAI,cAAc;AAAA,MACvB,IAAI,YAAY,QAAQ;AAAA,MACxB,QAAQ,cAAc;AAAA,QACpB,QACI;AAAA,UACE,SAAS;AAAA,UACT,OAAO,KAAK,MAAM,KAAK,UAAU,OAAO,OAAO,oBAAoB,KAAK,CAAC,CAAC;AAAA,QAC5E,IACA;AAAA,MACN;AAAA,MACA,mBAAmB,QAAQ;AAAA,MAC3B,YAAY,QAAQ;AAAA,IACtB,CAAC;AAAA,EACH;AAAA;AAEA,SAAS,kBACP,SACA,SACA;AACA,MAAI,aAAa;AACjB,MAAI,QAAQ,yBAAyB,GAAG;AACtC,iBAAa,QAAQ;AAAA,EACvB,WAAW,QAAQ,gBAAgB,GAAG;AACpC,iBAAa,QAAQ;AAAA,EACvB;AACA,SAAO,QAAQ;AAAA,IACb,CAAC,WACE,OAAO,SAAS,cAAc,OAAO,cAAc,cACpD,OAAO,iBAAiB;AAAA,EAC5B;AACF;","names":["_a","messages","action","message","options"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotChat
3
- } from "./chunk-Z3U4UBG2.mjs";
3
+ } from "./chunk-T4CAQC6B.mjs";
4
4
  import {
5
5
  CopilotContext
6
6
  } from "./chunk-ZM56S3LJ.mjs";
@@ -36,10 +36,9 @@ function useLangGraphInterrupt(action, dependencies) {
36
36
  }
37
37
  }, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
38
38
  useEffect(() => {
39
- var _a2;
40
39
  if (!action)
41
40
  return;
42
- if (hasAction && !isCurrentAction && !((_a2 = action.conditions) == null ? void 0 : _a2.length)) {
41
+ if (hasAction && !isCurrentAction && !action.enabled) {
43
42
  addToast({
44
43
  type: "warning",
45
44
  message: "An action is already registered for the interrupt event"
@@ -63,4 +62,4 @@ function useLangGraphInterrupt(action, dependencies) {
63
62
  export {
64
63
  useLangGraphInterrupt
65
64
  };
66
- //# sourceMappingURL=chunk-4ED56DQX.mjs.map
65
+ //# sourceMappingURL=chunk-HBCP2KNA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-langgraph-interrupt.ts"],"sourcesContent":["import { useContext, useEffect, useMemo } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { LangGraphInterruptRender } from \"../types/interrupt-action\";\nimport { useCopilotChat } from \"./use-copilot-chat\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { dataToUUID } from \"@copilotkit/shared\";\n\nexport function useLangGraphInterrupt<TEventValue = any>(\n action: Omit<LangGraphInterruptRender<TEventValue>, \"id\">,\n dependencies?: any[],\n) {\n const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } =\n useContext(CopilotContext);\n const { runChatCompletion } = useCopilotChat();\n const { addToast } = useToast();\n\n const actionId = dataToUUID(JSON.stringify(action), \"lgAction\");\n // We only consider action to be defined once the ID is there\n const hasAction = useMemo(\n () => Boolean(langGraphInterruptAction?.id),\n [langGraphInterruptAction],\n );\n\n const isCurrentAction = useMemo(\n () => langGraphInterruptAction?.id && langGraphInterruptAction?.id === actionId,\n [langGraphInterruptAction],\n );\n\n // Run chat completion to submit a response event. Only if it's the current action\n useEffect(() => {\n if (hasAction && isCurrentAction && langGraphInterruptAction?.event?.response) {\n runChatCompletion();\n }\n }, [langGraphInterruptAction?.event?.response, runChatCompletion, hasAction, isCurrentAction]);\n\n useEffect(() => {\n if (!action) return;\n // An action was already set, with no conditions and it's not the action we're using right now.\n // Show a warning, as this action will not be executed\n if (hasAction && !isCurrentAction && !action.enabled) {\n addToast({\n type: \"warning\",\n message: \"An action is already registered for the interrupt event\",\n });\n return;\n }\n\n if (hasAction && isCurrentAction) {\n return;\n }\n\n setLangGraphInterruptAction({ ...action, id: actionId });\n }, [\n action,\n hasAction,\n isCurrentAction,\n setLangGraphInterruptAction,\n removeLangGraphInterruptAction,\n ...(dependencies || []),\n ]);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,YAAY,WAAW,eAAe;AAK/C,SAAS,kBAAkB;AAEpB,SAAS,sBACd,QACA,cACA;AAVF;AAWE,QAAM,EAAE,6BAA6B,gCAAgC,yBAAyB,IAC5F,WAAW,cAAc;AAC3B,QAAM,EAAE,kBAAkB,IAAI,eAAe;AAC7C,QAAM,EAAE,SAAS,IAAI,SAAS;AAE9B,QAAM,WAAW,WAAW,KAAK,UAAU,MAAM,GAAG,UAAU;AAE9D,QAAM,YAAY;AAAA,IAChB,MAAM,QAAQ,qEAA0B,EAAE;AAAA,IAC1C,CAAC,wBAAwB;AAAA,EAC3B;AAEA,QAAM,kBAAkB;AAAA,IACtB,OAAM,qEAA0B,QAAM,qEAA0B,QAAO;AAAA,IACvE,CAAC,wBAAwB;AAAA,EAC3B;AAGA,YAAU,MAAM;AA7BlB,QAAAA;AA8BI,QAAI,aAAa,qBAAmBA,MAAA,qEAA0B,UAA1B,gBAAAA,IAAiC,WAAU;AAC7E,wBAAkB;AAAA,IACpB;AAAA,EACF,GAAG,EAAC,0EAA0B,UAA1B,mBAAiC,UAAU,mBAAmB,WAAW,eAAe,CAAC;AAE7F,YAAU,MAAM;AACd,QAAI,CAAC;AAAQ;AAGb,QAAI,aAAa,CAAC,mBAAmB,CAAC,OAAO,SAAS;AACpD,eAAS;AAAA,QACP,MAAM;AAAA,QACN,SAAS;AAAA,MACX,CAAC;AACD;AAAA,IACF;AAEA,QAAI,aAAa,iBAAiB;AAChC;AAAA,IACF;AAEA,gCAA4B,iCAAK,SAAL,EAAa,IAAI,SAAS,EAAC;AAAA,EACzD,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":["_a"]}
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-DCTJZ742.mjs";
10
10
  import {
11
11
  useChat
12
- } from "./chunk-2DPTBHGN.mjs";
12
+ } from "./chunk-FUO5LKSJ.mjs";
13
13
  import {
14
14
  useAsyncCallback
15
15
  } from "./chunk-22ENANUU.mjs";
@@ -222,4 +222,4 @@ export {
222
222
  useCopilotChat,
223
223
  defaultSystemMessage
224
224
  };
225
- //# sourceMappingURL=chunk-Z3U4UBG2.mjs.map
225
+ //# sourceMappingURL=chunk-T4CAQC6B.mjs.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-7YXUCWXF.mjs";
4
4
  import {
5
5
  processActionsForRuntimeRequest
6
- } from "./chunk-XERJQUHA.mjs";
6
+ } from "./chunk-4CEQJ2X6.mjs";
7
7
  import {
8
8
  __async,
9
9
  __spreadProps,
@@ -117,4 +117,4 @@ ${instructions}
117
117
  export {
118
118
  CopilotTask
119
119
  };
120
- //# sourceMappingURL=chunk-JFCNSGNU.mjs.map
120
+ //# sourceMappingURL=chunk-Y2T56VSE.mjs.map
@@ -1,6 +1,6 @@
1
1
  import { ForwardedParametersInput } from '@copilotkit/runtime-client-gql';
2
2
  import { ReactNode } from 'react';
3
- import { AuthState } from '../../context/copilot-context.js';
3
+ import { f as AuthState } from '../../copilot-context-9ae8990b.js';
4
4
  import '@copilotkit/shared';
5
5
  import '../../types/frontend-action.js';
6
6
  import '../../hooks/use-tree.js';
@@ -8,7 +8,6 @@ import '../../types/document-pointer.js';
8
8
  import '../../types/chat-suggestion-configuration.js';
9
9
  import '../../types/coagent-action.js';
10
10
  import '../../types/coagent-state.js';
11
- import '../../types/interrupt-action.js';
12
11
 
13
12
  /**
14
13
  * Props for CopilotKit.
@@ -2,7 +2,7 @@ import { CopilotKitProps } from './copilotkit-props.js';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import '@copilotkit/runtime-client-gql';
4
4
  import 'react';
5
- import '../../context/copilot-context.js';
5
+ import '../../copilot-context-9ae8990b.js';
6
6
  import '@copilotkit/shared';
7
7
  import '../../types/frontend-action.js';
8
8
  import '../../hooks/use-tree.js';
@@ -10,7 +10,6 @@ import '../../types/document-pointer.js';
10
10
  import '../../types/chat-suggestion-configuration.js';
11
11
  import '../../types/coagent-action.js';
12
12
  import '../../types/coagent-state.js';
13
- import '../../types/interrupt-action.js';
14
13
 
15
14
  declare function CopilotKit({ children, ...props }: CopilotKitProps): react_jsx_runtime.JSX.Element;
16
15
  declare function CopilotKitInternal(cpkProps: CopilotKitProps): react_jsx_runtime.JSX.Element;
@@ -3,7 +3,7 @@ export { CopilotKitProps } from './copilotkit-props.js';
3
3
  import 'react/jsx-runtime';
4
4
  import '@copilotkit/runtime-client-gql';
5
5
  import 'react';
6
- import '../../context/copilot-context.js';
6
+ import '../../copilot-context-9ae8990b.js';
7
7
  import '@copilotkit/shared';
8
8
  import '../../types/frontend-action.js';
9
9
  import '../../hooks/use-tree.js';
@@ -11,4 +11,3 @@ import '../../types/document-pointer.js';
11
11
  import '../../types/chat-suggestion-configuration.js';
12
12
  import '../../types/coagent-action.js';
13
13
  import '../../types/coagent-state.js';
14
- import '../../types/interrupt-action.js';
@@ -3,7 +3,7 @@ export { CopilotKitProps } from './copilot-provider/copilotkit-props.js';
3
3
  import 'react/jsx-runtime';
4
4
  import '@copilotkit/runtime-client-gql';
5
5
  import 'react';
6
- import '../context/copilot-context.js';
6
+ import '../copilot-context-9ae8990b.js';
7
7
  import '@copilotkit/shared';
8
8
  import '../types/frontend-action.js';
9
9
  import '../hooks/use-tree.js';
@@ -11,4 +11,3 @@ import '../types/document-pointer.js';
11
11
  import '../types/chat-suggestion-configuration.js';
12
12
  import '../types/coagent-action.js';
13
13
  import '../types/coagent-state.js';
14
- import '../types/interrupt-action.js';
@@ -1,148 +1,10 @@
1
- import { CopilotCloudConfig, FunctionCallHandler } from '@copilotkit/shared';
2
- import { ActionRenderProps, CatchAllActionRenderProps, FrontendAction } from '../types/frontend-action.js';
3
- import React from 'react';
4
- import { TreeNodeId } from '../hooks/use-tree.js';
5
- import { DocumentPointer } from '../types/document-pointer.js';
6
- import { CopilotChatSuggestionConfiguration } from '../types/chat-suggestion-configuration.js';
7
- import { CoAgentStateRenderProps, CoAgentStateRender } from '../types/coagent-action.js';
8
- import { CoagentState } from '../types/coagent-state.js';
9
- import { CopilotRuntimeClient, ForwardedParametersInput, Agent, ExtensionsInput } from '@copilotkit/runtime-client-gql';
10
- import { LangGraphInterruptAction, LangGraphInterruptActionSetter } from '../types/interrupt-action.js';
11
-
12
- /**
13
- * Interface for the configuration of the Copilot API.
14
- */
15
- interface CopilotApiConfig {
16
- /**
17
- * The public API key for Copilot Cloud.
18
- */
19
- publicApiKey?: string;
20
- /**
21
- * The configuration for Copilot Cloud.
22
- */
23
- cloud?: CopilotCloudConfig;
24
- /**
25
- * The endpoint for the chat API.
26
- */
27
- chatApiEndpoint: string;
28
- /**
29
- * The endpoint for the Copilot transcribe audio service.
30
- */
31
- transcribeAudioUrl?: string;
32
- /**
33
- * The endpoint for the Copilot text to speech service.
34
- */
35
- textToSpeechUrl?: string;
36
- /**
37
- * additional headers to be sent with the request
38
- * @default {}
39
- * @example
40
- * ```
41
- * {
42
- * 'Authorization': 'Bearer your_token_here'
43
- * }
44
- * ```
45
- */
46
- headers: Record<string, string>;
47
- /**
48
- * Custom properties to be sent with the request
49
- * @default {}
50
- * @example
51
- * ```
52
- * {
53
- * 'user_id': 'user_id'
54
- * }
55
- * ```
56
- */
57
- properties?: Record<string, any>;
58
- /**
59
- * Indicates whether the user agent should send or receive cookies from the other domain
60
- * in the case of cross-origin requests.
61
- */
62
- credentials?: RequestCredentials;
63
- }
64
- type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> = (props: TProps) => string | JSX.Element;
65
- type CoagentInChatRenderFunction = (props: CoAgentStateRenderProps<any>) => string | JSX.Element | undefined | null;
66
- interface ChatComponentsCache {
67
- actions: Record<string, InChatRenderFunction | string>;
68
- coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;
69
- }
70
- interface AgentSession {
71
- agentName: string;
72
- threadId?: string;
73
- nodeName?: string;
74
- }
75
- interface AuthState {
76
- status: "authenticated" | "unauthenticated";
77
- authHeaders: Record<string, string>;
78
- userId?: string;
79
- metadata?: Record<string, any>;
80
- }
81
- type ActionName = string;
82
- interface CopilotContextParams {
83
- actions: Record<string, FrontendAction<any>>;
84
- setAction: (id: string, action: FrontendAction<any>) => void;
85
- removeAction: (id: string) => void;
86
- coAgentStateRenders: Record<string, CoAgentStateRender<any>>;
87
- setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;
88
- removeCoAgentStateRender: (id: string) => void;
89
- chatComponentsCache: React.RefObject<ChatComponentsCache>;
90
- getFunctionCallHandler: (customEntryPoints?: Record<string, FrontendAction<any>>) => FunctionCallHandler;
91
- addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;
92
- removeContext: (id: TreeNodeId) => void;
93
- getContextString: (documents: DocumentPointer[], categories: string[]) => string;
94
- addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;
95
- removeDocumentContext: (documentId: string) => void;
96
- getDocumentsContext: (categories: string[]) => DocumentPointer[];
97
- isLoading: boolean;
98
- setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
99
- chatSuggestionConfiguration: {
100
- [key: string]: CopilotChatSuggestionConfiguration;
101
- };
102
- addChatSuggestionConfiguration: (id: string, suggestion: CopilotChatSuggestionConfiguration) => void;
103
- removeChatSuggestionConfiguration: (id: string) => void;
104
- chatInstructions: string;
105
- setChatInstructions: React.Dispatch<React.SetStateAction<string>>;
106
- copilotApiConfig: CopilotApiConfig;
107
- showDevConsole: boolean | "auto";
108
- coagentStates: Record<string, CoagentState>;
109
- setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;
110
- coagentStatesRef: React.RefObject<Record<string, CoagentState>>;
111
- setCoagentStatesWithRef: (value: Record<string, CoagentState> | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>)) => void;
112
- agentSession: AgentSession | null;
113
- setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;
114
- agentLock: string | null;
115
- threadId: string;
116
- setThreadId: React.Dispatch<React.SetStateAction<string>>;
117
- runId: string | null;
118
- setRunId: React.Dispatch<React.SetStateAction<string | null>>;
119
- chatAbortControllerRef: React.MutableRefObject<AbortController | null>;
120
- runtimeClient: CopilotRuntimeClient;
121
- /**
122
- * The forwarded parameters to use for the task.
123
- */
124
- forwardedParameters?: Pick<ForwardedParametersInput, "temperature">;
125
- availableAgents: Agent[];
126
- /**
127
- * The auth states for the CopilotKit.
128
- */
129
- authStates_c?: Record<ActionName, AuthState>;
130
- setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;
131
- /**
132
- * The auth config for the CopilotKit.
133
- */
134
- authConfig_c?: {
135
- SignInComponent: React.ComponentType<{
136
- onSignInComplete: (authState: AuthState) => void;
137
- }>;
138
- };
139
- extensions: ExtensionsInput;
140
- setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;
141
- langGraphInterruptAction: LangGraphInterruptAction | null;
142
- setLangGraphInterruptAction: LangGraphInterruptActionSetter;
143
- removeLangGraphInterruptAction: () => void;
144
- }
145
- declare const CopilotContext: React.Context<CopilotContextParams>;
146
- declare function useCopilotContext(): CopilotContextParams;
147
-
148
- export { ActionName, AgentSession, AuthState, ChatComponentsCache, CoagentInChatRenderFunction, CopilotApiConfig, CopilotContext, CopilotContextParams, InChatRenderFunction, useCopilotContext };
1
+ import '@copilotkit/shared';
2
+ import '../types/frontend-action.js';
3
+ import 'react';
4
+ import '../hooks/use-tree.js';
5
+ import '../types/document-pointer.js';
6
+ import '../types/chat-suggestion-configuration.js';
7
+ import '../types/coagent-action.js';
8
+ import '../types/coagent-state.js';
9
+ import '@copilotkit/runtime-client-gql';
10
+ export { k as ActionName, A as AgentSession, f as AuthState, j as ChatComponentsCache, b as CoagentInChatRenderFunction, c as CopilotApiConfig, C as CopilotContext, a as CopilotContextParams, I as InChatRenderFunction, u as useCopilotContext } from '../copilot-context-9ae8990b.js';
@@ -1,4 +1,4 @@
1
- export { CoagentInChatRenderFunction, CopilotApiConfig, CopilotContext, CopilotContextParams, useCopilotContext } from './copilot-context.js';
1
+ export { b as CoagentInChatRenderFunction, c as CopilotApiConfig, C as CopilotContext, a as CopilotContextParams, u as useCopilotContext } from '../copilot-context-9ae8990b.js';
2
2
  export { CopilotMessagesContext, CopilotMessagesContextParams, useCopilotMessagesContext } from './copilot-messages-context.js';
3
3
  import '@copilotkit/shared';
4
4
  import '../types/frontend-action.js';
@@ -9,4 +9,3 @@ import '../types/document-pointer.js';
9
9
  import '../types/chat-suggestion-configuration.js';
10
10
  import '../types/coagent-action.js';
11
11
  import '../types/coagent-state.js';
12
- import '../types/interrupt-action.js';
@@ -0,0 +1,183 @@
1
+ import { CopilotCloudConfig, FunctionCallHandler } from '@copilotkit/shared';
2
+ import { ActionRenderProps, CatchAllActionRenderProps, FrontendAction } from './types/frontend-action.js';
3
+ import React$1 from 'react';
4
+ import { TreeNodeId } from './hooks/use-tree.js';
5
+ import { DocumentPointer } from './types/document-pointer.js';
6
+ import { CopilotChatSuggestionConfiguration } from './types/chat-suggestion-configuration.js';
7
+ import { CoAgentStateRenderProps, CoAgentStateRender } from './types/coagent-action.js';
8
+ import { CoagentState } from './types/coagent-state.js';
9
+ import { LangGraphInterruptEvent, CopilotRuntimeClient, ForwardedParametersInput, Agent, ExtensionsInput } from '@copilotkit/runtime-client-gql';
10
+
11
+ interface LangGraphInterruptRenderHandlerProps<TEventValue = any> {
12
+ event: LangGraphInterruptEvent<TEventValue>;
13
+ resolve: (resolution: string) => void;
14
+ }
15
+ interface LangGraphInterruptRenderProps<TEventValue = any> {
16
+ result: unknown;
17
+ event: LangGraphInterruptEvent<TEventValue>;
18
+ resolve: (resolution: string) => void;
19
+ }
20
+ interface LangGraphInterruptRender<TEventValue = any> {
21
+ id: string;
22
+ /**
23
+ * The handler function to handle the event.
24
+ */
25
+ handler?: (props: LangGraphInterruptRenderHandlerProps<TEventValue>) => any | Promise<any>;
26
+ /**
27
+ * The render function to handle the event.
28
+ */
29
+ render?: (props: LangGraphInterruptRenderProps<TEventValue>) => string | React.ReactElement;
30
+ /**
31
+ * Method that returns a boolean, indicating if the interrupt action should run
32
+ * Useful when using multiple interrupts
33
+ */
34
+ enabled?: (args: {
35
+ eventValue: TEventValue;
36
+ agentMetadata: AgentSession;
37
+ }) => boolean;
38
+ }
39
+ type LangGraphInterruptAction = LangGraphInterruptRender & {
40
+ event?: LangGraphInterruptEvent;
41
+ };
42
+ type LangGraphInterruptActionSetterArgs = (Partial<LangGraphInterruptRender> & {
43
+ event?: Partial<LangGraphInterruptEvent>;
44
+ }) | null;
45
+ type LangGraphInterruptActionSetter = (action: LangGraphInterruptActionSetterArgs) => void;
46
+
47
+ /**
48
+ * Interface for the configuration of the Copilot API.
49
+ */
50
+ interface CopilotApiConfig {
51
+ /**
52
+ * The public API key for Copilot Cloud.
53
+ */
54
+ publicApiKey?: string;
55
+ /**
56
+ * The configuration for Copilot Cloud.
57
+ */
58
+ cloud?: CopilotCloudConfig;
59
+ /**
60
+ * The endpoint for the chat API.
61
+ */
62
+ chatApiEndpoint: string;
63
+ /**
64
+ * The endpoint for the Copilot transcribe audio service.
65
+ */
66
+ transcribeAudioUrl?: string;
67
+ /**
68
+ * The endpoint for the Copilot text to speech service.
69
+ */
70
+ textToSpeechUrl?: string;
71
+ /**
72
+ * additional headers to be sent with the request
73
+ * @default {}
74
+ * @example
75
+ * ```
76
+ * {
77
+ * 'Authorization': 'Bearer your_token_here'
78
+ * }
79
+ * ```
80
+ */
81
+ headers: Record<string, string>;
82
+ /**
83
+ * Custom properties to be sent with the request
84
+ * @default {}
85
+ * @example
86
+ * ```
87
+ * {
88
+ * 'user_id': 'user_id'
89
+ * }
90
+ * ```
91
+ */
92
+ properties?: Record<string, any>;
93
+ /**
94
+ * Indicates whether the user agent should send or receive cookies from the other domain
95
+ * in the case of cross-origin requests.
96
+ */
97
+ credentials?: RequestCredentials;
98
+ }
99
+ type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> = (props: TProps) => string | JSX.Element;
100
+ type CoagentInChatRenderFunction = (props: CoAgentStateRenderProps<any>) => string | JSX.Element | undefined | null;
101
+ interface ChatComponentsCache {
102
+ actions: Record<string, InChatRenderFunction | string>;
103
+ coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;
104
+ }
105
+ interface AgentSession {
106
+ agentName: string;
107
+ threadId?: string;
108
+ nodeName?: string;
109
+ }
110
+ interface AuthState {
111
+ status: "authenticated" | "unauthenticated";
112
+ authHeaders: Record<string, string>;
113
+ userId?: string;
114
+ metadata?: Record<string, any>;
115
+ }
116
+ type ActionName = string;
117
+ interface CopilotContextParams {
118
+ actions: Record<string, FrontendAction<any>>;
119
+ setAction: (id: string, action: FrontendAction<any>) => void;
120
+ removeAction: (id: string) => void;
121
+ coAgentStateRenders: Record<string, CoAgentStateRender<any>>;
122
+ setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;
123
+ removeCoAgentStateRender: (id: string) => void;
124
+ chatComponentsCache: React$1.RefObject<ChatComponentsCache>;
125
+ getFunctionCallHandler: (customEntryPoints?: Record<string, FrontendAction<any>>) => FunctionCallHandler;
126
+ addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;
127
+ removeContext: (id: TreeNodeId) => void;
128
+ getContextString: (documents: DocumentPointer[], categories: string[]) => string;
129
+ addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;
130
+ removeDocumentContext: (documentId: string) => void;
131
+ getDocumentsContext: (categories: string[]) => DocumentPointer[];
132
+ isLoading: boolean;
133
+ setIsLoading: React$1.Dispatch<React$1.SetStateAction<boolean>>;
134
+ chatSuggestionConfiguration: {
135
+ [key: string]: CopilotChatSuggestionConfiguration;
136
+ };
137
+ addChatSuggestionConfiguration: (id: string, suggestion: CopilotChatSuggestionConfiguration) => void;
138
+ removeChatSuggestionConfiguration: (id: string) => void;
139
+ chatInstructions: string;
140
+ setChatInstructions: React$1.Dispatch<React$1.SetStateAction<string>>;
141
+ copilotApiConfig: CopilotApiConfig;
142
+ showDevConsole: boolean | "auto";
143
+ coagentStates: Record<string, CoagentState>;
144
+ setCoagentStates: React$1.Dispatch<React$1.SetStateAction<Record<string, CoagentState>>>;
145
+ coagentStatesRef: React$1.RefObject<Record<string, CoagentState>>;
146
+ setCoagentStatesWithRef: (value: Record<string, CoagentState> | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>)) => void;
147
+ agentSession: AgentSession | null;
148
+ setAgentSession: React$1.Dispatch<React$1.SetStateAction<AgentSession | null>>;
149
+ agentLock: string | null;
150
+ threadId: string;
151
+ setThreadId: React$1.Dispatch<React$1.SetStateAction<string>>;
152
+ runId: string | null;
153
+ setRunId: React$1.Dispatch<React$1.SetStateAction<string | null>>;
154
+ chatAbortControllerRef: React$1.MutableRefObject<AbortController | null>;
155
+ runtimeClient: CopilotRuntimeClient;
156
+ /**
157
+ * The forwarded parameters to use for the task.
158
+ */
159
+ forwardedParameters?: Pick<ForwardedParametersInput, "temperature">;
160
+ availableAgents: Agent[];
161
+ /**
162
+ * The auth states for the CopilotKit.
163
+ */
164
+ authStates_c?: Record<ActionName, AuthState>;
165
+ setAuthStates_c?: React$1.Dispatch<React$1.SetStateAction<Record<ActionName, AuthState>>>;
166
+ /**
167
+ * The auth config for the CopilotKit.
168
+ */
169
+ authConfig_c?: {
170
+ SignInComponent: React$1.ComponentType<{
171
+ onSignInComplete: (authState: AuthState) => void;
172
+ }>;
173
+ };
174
+ extensions: ExtensionsInput;
175
+ setExtensions: React$1.Dispatch<React$1.SetStateAction<ExtensionsInput>>;
176
+ langGraphInterruptAction: LangGraphInterruptAction | null;
177
+ setLangGraphInterruptAction: LangGraphInterruptActionSetter;
178
+ removeLangGraphInterruptAction: () => void;
179
+ }
180
+ declare const CopilotContext: React$1.Context<CopilotContextParams>;
181
+ declare function useCopilotContext(): CopilotContextParams;
182
+
183
+ export { AgentSession as A, CopilotContext as C, InChatRenderFunction as I, LangGraphInterruptAction as L, CopilotContextParams as a, CoagentInChatRenderFunction as b, CopilotApiConfig as c, LangGraphInterruptActionSetter as d, LangGraphInterruptRender as e, AuthState as f, LangGraphInterruptRenderHandlerProps as g, LangGraphInterruptRenderProps as h, LangGraphInterruptActionSetterArgs as i, ChatComponentsCache as j, ActionName as k, useCopilotContext as u };
@@ -16,9 +16,8 @@ import '../types/frontend-action.js';
16
16
  import 'react';
17
17
  import '../types/coagent-action.js';
18
18
  import '../types/document-pointer.js';
19
- import '../context/copilot-context.js';
19
+ import '../copilot-context-9ae8990b.js';
20
20
  import './use-tree.js';
21
21
  import '../types/chat-suggestion-configuration.js';
22
22
  import '../types/coagent-state.js';
23
- import '../types/interrupt-action.js';
24
23
  import '../context/copilot-messages-context.js';