@copilotkit/react-core 1.6.0-next.0 → 1.6.0-next.10
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 +78 -0
- package/dist/{chunk-VMYLY5KI.mjs → chunk-ADTDNMYG.mjs} +58 -48
- package/dist/chunk-ADTDNMYG.mjs.map +1 -0
- package/dist/{chunk-2DPTBHGN.mjs → chunk-ALW2T2LL.mjs} +3 -5
- package/dist/chunk-ALW2T2LL.mjs.map +1 -0
- package/dist/{chunk-ZAU4EMBM.mjs → chunk-F7O6L7C3.mjs} +4 -5
- package/dist/chunk-F7O6L7C3.mjs.map +1 -0
- package/dist/{chunk-7LZQFHNW.mjs → chunk-MPFP6ANM.mjs} +3 -4
- package/dist/chunk-MPFP6ANM.mjs.map +1 -0
- package/dist/{chunk-Z3U4UBG2.mjs → chunk-QJPWWVJQ.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
- package/dist/components/copilot-provider/index.d.ts +1 -2
- package/dist/components/index.d.ts +1 -2
- package/dist/context/copilot-context.d.ts +10 -148
- package/dist/context/index.d.ts +1 -2
- package/dist/copilot-context-9ae8990b.d.ts +183 -0
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +68 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +5 -5
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +2 -4
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +1 -1
- package/dist/hooks/use-coagent.d.ts +1 -2
- package/dist/hooks/use-coagent.js +58 -50
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +1 -2
- package/dist/hooks/use-copilot-chat.js +3 -5
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +3 -4
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt.d.ts +10 -3
- package/dist/hooks/use-langgraph-interrupt.js +6 -9
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +67 -61
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/lib/copilot-task.d.ts +1 -2
- package/dist/lib/index.d.ts +1 -2
- package/dist/types/interrupt-action.d.ts +10 -35
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/utils/extract.d.ts +1 -2
- package/dist/utils/index.d.ts +1 -2
- package/package.json +3 -3
- package/src/hooks/use-chat.ts +2 -4
- package/src/hooks/use-coagent.ts +70 -56
- package/src/hooks/use-langgraph-interrupt-render.ts +7 -3
- package/src/hooks/use-langgraph-interrupt.ts +3 -4
- package/src/types/interrupt-action.ts +17 -13
- package/dist/chunk-2DPTBHGN.mjs.map +0 -1
- package/dist/chunk-7LZQFHNW.mjs.map +0 -1
- package/dist/chunk-VMYLY5KI.mjs.map +0 -1
- package/dist/chunk-ZAU4EMBM.mjs.map +0 -1
- /package/dist/{chunk-Z3U4UBG2.mjs.map → chunk-QJPWWVJQ.mjs.map} +0 -0
|
@@ -1,148 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
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';
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { CoagentInChatRenderFunction, CopilotApiConfig, CopilotContext, CopilotContextParams, useCopilotContext } from '
|
|
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 };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -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 '../
|
|
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';
|
package/dist/hooks/index.js
CHANGED
|
@@ -373,6 +373,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
373
373
|
|
|
374
374
|
// src/hooks/use-chat.ts
|
|
375
375
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
376
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
376
377
|
function useChat(options) {
|
|
377
378
|
const {
|
|
378
379
|
messages,
|
|
@@ -517,10 +518,7 @@ function useChat(options) {
|
|
|
517
518
|
((_i = (_h = value.generateCopilotResponse) == null ? void 0 : _h.metaEvents) != null ? _i : []).forEach((ev) => {
|
|
518
519
|
if (ev.name === import_runtime_client_gql4.MetaEventName.LangGraphInterruptEvent) {
|
|
519
520
|
let eventValue = (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev).value;
|
|
520
|
-
|
|
521
|
-
eventValue = JSON.parse(eventValue);
|
|
522
|
-
} catch (e) {
|
|
523
|
-
}
|
|
521
|
+
eventValue = (0, import_shared3.parseJson)(eventValue, eventValue);
|
|
524
522
|
setLangGraphInterruptAction({
|
|
525
523
|
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql3.langGraphInterruptEvent)(ev)), {
|
|
526
524
|
value: eventValue
|
|
@@ -829,7 +827,7 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
829
827
|
// src/components/copilot-provider/copilotkit.tsx
|
|
830
828
|
var import_react7 = require("react");
|
|
831
829
|
var import_react_dom = require("react-dom");
|
|
832
|
-
var
|
|
830
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
833
831
|
|
|
834
832
|
// src/context/copilot-messages-context.tsx
|
|
835
833
|
var import_react6 = __toESM(require("react"));
|
|
@@ -1049,11 +1047,11 @@ ${additionalInstructions}` : "");
|
|
|
1049
1047
|
}
|
|
1050
1048
|
|
|
1051
1049
|
// src/hooks/use-copilot-action.ts
|
|
1052
|
-
var
|
|
1050
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1053
1051
|
var import_react9 = require("react");
|
|
1054
1052
|
function useCopilotAction(action, dependencies) {
|
|
1055
1053
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1056
|
-
const idRef = (0, import_react9.useRef)((0,
|
|
1054
|
+
const idRef = (0, import_react9.useRef)((0, import_shared5.randomId)());
|
|
1057
1055
|
const renderAndWaitRef = (0, import_react9.useRef)(null);
|
|
1058
1056
|
const { addToast } = useToast();
|
|
1059
1057
|
action = __spreadValues({}, action);
|
|
@@ -1155,7 +1153,7 @@ function isFrontendAction(action) {
|
|
|
1155
1153
|
|
|
1156
1154
|
// src/hooks/use-coagent-state-render.ts
|
|
1157
1155
|
var import_react10 = require("react");
|
|
1158
|
-
var
|
|
1156
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1159
1157
|
function useCoAgentStateRender(action, dependencies) {
|
|
1160
1158
|
const {
|
|
1161
1159
|
setCoAgentStateRender,
|
|
@@ -1164,7 +1162,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1164
1162
|
chatComponentsCache,
|
|
1165
1163
|
availableAgents
|
|
1166
1164
|
} = (0, import_react10.useContext)(CopilotContext);
|
|
1167
|
-
const idRef = (0, import_react10.useRef)((0,
|
|
1165
|
+
const idRef = (0, import_react10.useRef)((0, import_shared6.randomId)());
|
|
1168
1166
|
const { addToast } = useToast();
|
|
1169
1167
|
(0, import_react10.useEffect)(() => {
|
|
1170
1168
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
@@ -1263,15 +1261,13 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1263
1261
|
|
|
1264
1262
|
// src/hooks/use-coagent.ts
|
|
1265
1263
|
var import_react13 = require("react");
|
|
1264
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1266
1265
|
function useCoAgent(options) {
|
|
1267
1266
|
const generalContext = useCopilotContext();
|
|
1268
1267
|
const { availableAgents } = generalContext;
|
|
1269
1268
|
const { addToast } = useToast();
|
|
1270
1269
|
const lastLoadedThreadId = (0, import_react13.useRef)();
|
|
1271
1270
|
const lastLoadedState = (0, import_react13.useRef)();
|
|
1272
|
-
const isExternalStateManagement = (options2) => {
|
|
1273
|
-
return "state" in options2 && "setState" in options2;
|
|
1274
|
-
};
|
|
1275
1271
|
const { name } = options;
|
|
1276
1272
|
(0, import_react13.useEffect)(() => {
|
|
1277
1273
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
@@ -1280,44 +1276,27 @@ function useCoAgent(options) {
|
|
|
1280
1276
|
addToast({ type: "warning", message });
|
|
1281
1277
|
}
|
|
1282
1278
|
}, [availableAgents]);
|
|
1283
|
-
const isInternalStateManagementWithInitial = (options2) => {
|
|
1284
|
-
return "initialState" in options2;
|
|
1285
|
-
};
|
|
1286
1279
|
const messagesContext = useCopilotMessagesContext();
|
|
1287
1280
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1288
1281
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
1289
1282
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1290
|
-
const getCoagentState = (coagentStates2, name2) => {
|
|
1291
|
-
var _a;
|
|
1292
|
-
if (coagentStates2[name2]) {
|
|
1293
|
-
return coagentStates2[name2];
|
|
1294
|
-
} else {
|
|
1295
|
-
return {
|
|
1296
|
-
name: name2,
|
|
1297
|
-
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1298
|
-
configurable: (_a = options.configurable) != null ? _a : {},
|
|
1299
|
-
running: false,
|
|
1300
|
-
active: false,
|
|
1301
|
-
threadId: void 0,
|
|
1302
|
-
nodeName: void 0,
|
|
1303
|
-
runId: void 0
|
|
1304
|
-
};
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
1283
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1308
1284
|
url: copilotApiConfig.chatApiEndpoint,
|
|
1309
1285
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
1310
1286
|
credentials: copilotApiConfig.credentials
|
|
1311
1287
|
});
|
|
1312
|
-
const setState = (
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1288
|
+
const setState = (0, import_react13.useCallback)(
|
|
1289
|
+
(newState) => {
|
|
1290
|
+
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
1291
|
+
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
1292
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
1293
|
+
[name]: __spreadProps(__spreadValues({}, coagentState), {
|
|
1294
|
+
state: updatedState
|
|
1295
|
+
})
|
|
1296
|
+
}));
|
|
1297
|
+
},
|
|
1298
|
+
[coagentStates, name]
|
|
1299
|
+
);
|
|
1321
1300
|
(0, import_react13.useEffect)(() => {
|
|
1322
1301
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
1323
1302
|
var _a, _b, _c, _d;
|
|
@@ -1333,13 +1312,12 @@ function useCoAgent(options) {
|
|
|
1333
1312
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
1334
1313
|
lastLoadedState.current = newState;
|
|
1335
1314
|
lastLoadedThreadId.current = threadId;
|
|
1336
|
-
const fetchedState =
|
|
1315
|
+
const fetchedState = (0, import_shared7.parseJson)(newState, {});
|
|
1337
1316
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
1338
1317
|
}
|
|
1339
1318
|
});
|
|
1340
1319
|
void fetchAgentState();
|
|
1341
1320
|
}, [threadId]);
|
|
1342
|
-
const coagentState = getCoagentState(coagentStates, name);
|
|
1343
1321
|
(0, import_react13.useEffect)(() => {
|
|
1344
1322
|
if (isExternalStateManagement(options)) {
|
|
1345
1323
|
setState(options.state);
|
|
@@ -1357,17 +1335,20 @@ function useCoAgent(options) {
|
|
|
1357
1335
|
}),
|
|
1358
1336
|
[name, context, appendMessage, runChatCompletion]
|
|
1359
1337
|
);
|
|
1360
|
-
return {
|
|
1361
|
-
name,
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1338
|
+
return (0, import_react13.useMemo)(() => {
|
|
1339
|
+
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
1340
|
+
return {
|
|
1341
|
+
name,
|
|
1342
|
+
nodeName: coagentState.nodeName,
|
|
1343
|
+
threadId: coagentState.threadId,
|
|
1344
|
+
running: coagentState.running,
|
|
1345
|
+
state: coagentState.state,
|
|
1346
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
1347
|
+
start: () => startAgent(name, context),
|
|
1348
|
+
stop: () => stopAgent(name, context),
|
|
1349
|
+
run: runAgentCallback
|
|
1350
|
+
};
|
|
1351
|
+
}, [name, coagentStates, options, setState, runAgentCallback]);
|
|
1371
1352
|
}
|
|
1372
1353
|
function startAgent(name, context) {
|
|
1373
1354
|
const { setAgentSession } = context;
|
|
@@ -1423,6 +1404,33 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
1423
1404
|
}
|
|
1424
1405
|
});
|
|
1425
1406
|
}
|
|
1407
|
+
var isExternalStateManagement = (options) => {
|
|
1408
|
+
return "state" in options && "setState" in options;
|
|
1409
|
+
};
|
|
1410
|
+
var isInternalStateManagementWithInitial = (options) => {
|
|
1411
|
+
return "initialState" in options;
|
|
1412
|
+
};
|
|
1413
|
+
var getCoagentState = ({
|
|
1414
|
+
coagentStates,
|
|
1415
|
+
name,
|
|
1416
|
+
options
|
|
1417
|
+
}) => {
|
|
1418
|
+
var _a;
|
|
1419
|
+
if (coagentStates[name]) {
|
|
1420
|
+
return coagentStates[name];
|
|
1421
|
+
} else {
|
|
1422
|
+
return {
|
|
1423
|
+
name,
|
|
1424
|
+
state: isInternalStateManagementWithInitial(options) ? options.initialState : {},
|
|
1425
|
+
configurable: (_a = options.configurable) != null ? _a : {},
|
|
1426
|
+
running: false,
|
|
1427
|
+
active: false,
|
|
1428
|
+
threadId: void 0,
|
|
1429
|
+
nodeName: void 0,
|
|
1430
|
+
runId: void 0
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1426
1434
|
|
|
1427
1435
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
1428
1436
|
var import_react14 = require("react");
|
|
@@ -1470,13 +1478,13 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1470
1478
|
|
|
1471
1479
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1472
1480
|
var import_react16 = require("react");
|
|
1473
|
-
var
|
|
1481
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1474
1482
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1475
1483
|
var _a;
|
|
1476
1484
|
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react16.useContext)(CopilotContext);
|
|
1477
1485
|
const { runChatCompletion } = useCopilotChat();
|
|
1478
1486
|
const { addToast } = useToast();
|
|
1479
|
-
const actionId = (0,
|
|
1487
|
+
const actionId = (0, import_shared8.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
1480
1488
|
const hasAction = (0, import_react16.useMemo)(
|
|
1481
1489
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1482
1490
|
[langGraphInterruptAction]
|
|
@@ -1492,10 +1500,9 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
1492
1500
|
}
|
|
1493
1501
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
1494
1502
|
(0, import_react16.useEffect)(() => {
|
|
1495
|
-
var _a2;
|
|
1496
1503
|
if (!action)
|
|
1497
1504
|
return;
|
|
1498
|
-
if (hasAction && !isCurrentAction && !
|
|
1505
|
+
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
1499
1506
|
addToast({
|
|
1500
1507
|
type: "warning",
|
|
1501
1508
|
message: "An action is already registered for the interrupt event"
|
|
@@ -1518,12 +1525,11 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
1518
1525
|
|
|
1519
1526
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1520
1527
|
var import_react17 = __toESM(require("react"));
|
|
1521
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1522
1528
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1523
1529
|
return render({ event, result, resolve });
|
|
1524
1530
|
};
|
|
1525
1531
|
function useLangGraphInterruptRender() {
|
|
1526
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction } = useCopilotContext();
|
|
1532
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1527
1533
|
const responseRef = import_react17.default.useRef();
|
|
1528
1534
|
const resolveInterrupt = (0, import_react17.useCallback)(
|
|
1529
1535
|
(response) => {
|
|
@@ -1536,8 +1542,8 @@ function useLangGraphInterruptRender() {
|
|
|
1536
1542
|
);
|
|
1537
1543
|
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1538
1544
|
return null;
|
|
1539
|
-
const { render, handler, event,
|
|
1540
|
-
const conditionsMet =
|
|
1545
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1546
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1541
1547
|
if (!conditionsMet) {
|
|
1542
1548
|
return null;
|
|
1543
1549
|
}
|