@copilotkit/react-core 1.6.0-next.1 → 1.6.0-next.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{chunk-4ED56DQX.mjs → chunk-5SGYPX4V.mjs} +2 -3
  3. package/dist/chunk-5SGYPX4V.mjs.map +1 -0
  4. package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
  5. package/dist/chunk-F7O6L7C3.mjs.map +1 -0
  6. package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
  7. package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
  8. package/dist/components/copilot-provider/index.d.ts +1 -2
  9. package/dist/components/index.d.ts +1 -2
  10. package/dist/context/copilot-context.d.ts +10 -148
  11. package/dist/context/index.d.ts +1 -2
  12. package/dist/copilot-context-9ae8990b.d.ts +183 -0
  13. package/dist/hooks/index.d.ts +1 -2
  14. package/dist/hooks/index.js +4 -6
  15. package/dist/hooks/index.js.map +1 -1
  16. package/dist/hooks/index.mjs +2 -2
  17. package/dist/hooks/use-chat.d.ts +1 -2
  18. package/dist/hooks/use-coagent.d.ts +1 -2
  19. package/dist/hooks/use-copilot-chat.d.ts +1 -2
  20. package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
  21. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  22. package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
  23. package/dist/hooks/use-langgraph-interrupt.d.ts +9 -2
  24. package/dist/hooks/use-langgraph-interrupt.js +1 -2
  25. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  26. package/dist/hooks/use-langgraph-interrupt.mjs +1 -1
  27. package/dist/index.d.ts +1 -2
  28. package/dist/index.js +4 -6
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +2 -2
  31. package/dist/lib/copilot-task.d.ts +1 -2
  32. package/dist/lib/index.d.ts +1 -2
  33. package/dist/types/interrupt-action.d.ts +10 -35
  34. package/dist/types/interrupt-action.js.map +1 -1
  35. package/dist/utils/extract.d.ts +1 -2
  36. package/dist/utils/index.d.ts +1 -2
  37. package/package.json +3 -3
  38. package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
  39. package/src/hooks/use-langgraph-interrupt.ts +1 -2
  40. package/src/types/interrupt-action.ts +16 -12
  41. package/dist/chunk-4ED56DQX.mjs.map +0 -1
  42. package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ui
2
2
 
3
+ ## 1.6.0-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b454827: - fix: simplify condition options for langgraph interrupts
8
+ - chore: add new enabled to e2e tests
9
+ - fix: refine argument types
10
+ - chore: document hook API reference
11
+ - @copilotkit/runtime-client-gql@1.6.0-next.2
12
+ - @copilotkit/shared@1.6.0-next.2
13
+
3
14
  ## 1.6.0-next.1
4
15
 
5
16
  ### Patch Changes
@@ -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-5SGYPX4V.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"]}
@@ -4,12 +4,11 @@ import {
4
4
 
5
5
  // src/hooks/use-langgraph-interrupt-render.ts
6
6
  import React, { useCallback } from "react";
7
- import { executeConditions } from "@copilotkit/shared";
8
7
  var InterruptRenderer = ({ event, result, render, resolve }) => {
9
8
  return render({ event, result, resolve });
10
9
  };
11
10
  function useLangGraphInterruptRender() {
12
- const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
11
+ const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
13
12
  const responseRef = React.useRef();
14
13
  const resolveInterrupt = useCallback(
15
14
  (response) => {
@@ -22,8 +21,8 @@ function useLangGraphInterruptRender() {
22
21
  );
23
22
  if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
24
23
  return null;
25
- const { render, handler, event, conditions } = langGraphInterruptAction;
26
- const conditionsMet = executeConditions({ conditions, value: event.value });
24
+ const { render, handler, event, enabled } = langGraphInterruptAction;
25
+ const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
27
26
  if (!conditionsMet) {
28
27
  return null;
29
28
  }
@@ -45,4 +44,4 @@ function useLangGraphInterruptRender() {
45
44
  export {
46
45
  useLangGraphInterruptRender
47
46
  };
48
- //# sourceMappingURL=chunk-ZAU4EMBM.mjs.map
47
+ //# sourceMappingURL=chunk-F7O6L7C3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-langgraph-interrupt-render.ts"],"sourcesContent":["import { useCopilotContext } from \"../context\";\nimport React, { useCallback } from \"react\";\nimport { executeConditions } from \"@copilotkit/shared\";\n\ntype InterruptProps = {\n event: any;\n result: any;\n render: (props: {\n event: any;\n result: any;\n resolve: (response: string) => void;\n }) => string | React.ReactElement;\n resolve: (response: string) => void;\n};\n\nconst InterruptRenderer: React.FC<InterruptProps> = ({ event, result, render, resolve }) => {\n return render({ event, result, resolve });\n};\n\nexport function useLangGraphInterruptRender(): string | React.ReactElement | null {\n const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } =\n useCopilotContext();\n\n const responseRef = React.useRef<string>();\n const resolveInterrupt = useCallback(\n (response: string) => {\n responseRef.current = response;\n // Use setTimeout to defer the state update to next tick\n setTimeout(() => {\n setLangGraphInterruptAction({ event: { response } });\n }, 0);\n },\n [setLangGraphInterruptAction],\n );\n\n if (\n !langGraphInterruptAction ||\n !langGraphInterruptAction.event ||\n !langGraphInterruptAction.render\n )\n return null;\n\n const { render, handler, event, enabled } = langGraphInterruptAction;\n\n const conditionsMet =\n !agentSession || !enabled\n ? true\n : enabled({ eventValue: event.value, agentMetadata: agentSession });\n if (!conditionsMet) {\n return null;\n }\n\n let result = null;\n if (handler) {\n result = handler({\n event,\n resolve: resolveInterrupt,\n });\n }\n\n return React.createElement(InterruptRenderer, {\n event,\n result,\n render,\n resolve: resolveInterrupt,\n });\n}\n"],"mappings":";;;;;AACA,OAAO,SAAS,mBAAmB;AAcnC,IAAM,oBAA8C,CAAC,EAAE,OAAO,QAAQ,QAAQ,QAAQ,MAAM;AAC1F,SAAO,OAAO,EAAE,OAAO,QAAQ,QAAQ,CAAC;AAC1C;AAEO,SAAS,8BAAkE;AAChF,QAAM,EAAE,0BAA0B,6BAA6B,aAAa,IAC1E,kBAAkB;AAEpB,QAAM,cAAc,MAAM,OAAe;AACzC,QAAM,mBAAmB;AAAA,IACvB,CAAC,aAAqB;AACpB,kBAAY,UAAU;AAEtB,iBAAW,MAAM;AACf,oCAA4B,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAAA,MACrD,GAAG,CAAC;AAAA,IACN;AAAA,IACA,CAAC,2BAA2B;AAAA,EAC9B;AAEA,MACE,CAAC,4BACD,CAAC,yBAAyB,SAC1B,CAAC,yBAAyB;AAE1B,WAAO;AAET,QAAM,EAAE,QAAQ,SAAS,OAAO,QAAQ,IAAI;AAE5C,QAAM,gBACJ,CAAC,gBAAgB,CAAC,UACd,OACA,QAAQ,EAAE,YAAY,MAAM,OAAO,eAAe,aAAa,CAAC;AACtE,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,EACT;AAEA,MAAI,SAAS;AACb,MAAI,SAAS;AACX,aAAS,QAAQ;AAAA,MACf;AAAA,MACA,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO,MAAM,cAAc,mBAAmB;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACX,CAAC;AACH;","names":[]}
@@ -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';
@@ -1492,10 +1492,9 @@ function useLangGraphInterrupt(action, dependencies) {
1492
1492
  }
1493
1493
  }, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
1494
1494
  (0, import_react16.useEffect)(() => {
1495
- var _a2;
1496
1495
  if (!action)
1497
1496
  return;
1498
- if (hasAction && !isCurrentAction && !((_a2 = action.conditions) == null ? void 0 : _a2.length)) {
1497
+ if (hasAction && !isCurrentAction && !action.enabled) {
1499
1498
  addToast({
1500
1499
  type: "warning",
1501
1500
  message: "An action is already registered for the interrupt event"
@@ -1518,12 +1517,11 @@ function useLangGraphInterrupt(action, dependencies) {
1518
1517
 
1519
1518
  // src/hooks/use-langgraph-interrupt-render.ts
1520
1519
  var import_react17 = __toESM(require("react"));
1521
- var import_shared7 = require("@copilotkit/shared");
1522
1520
  var InterruptRenderer = ({ event, result, render, resolve }) => {
1523
1521
  return render({ event, result, resolve });
1524
1522
  };
1525
1523
  function useLangGraphInterruptRender() {
1526
- const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
1524
+ const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
1527
1525
  const responseRef = import_react17.default.useRef();
1528
1526
  const resolveInterrupt = (0, import_react17.useCallback)(
1529
1527
  (response) => {
@@ -1536,8 +1534,8 @@ function useLangGraphInterruptRender() {
1536
1534
  );
1537
1535
  if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
1538
1536
  return null;
1539
- const { render, handler, event, conditions } = langGraphInterruptAction;
1540
- const conditionsMet = (0, import_shared7.executeConditions)({ conditions, value: event.value });
1537
+ const { render, handler, event, enabled } = langGraphInterruptAction;
1538
+ const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
1541
1539
  if (!conditionsMet) {
1542
1540
  return null;
1543
1541
  }