@copilotkit/react-core 1.4.0-pre-1-4-0-alpha.10 → 1.4.0-pre-1-4-0.14

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 CHANGED
@@ -1,42 +1,192 @@
1
1
  # ui
2
2
 
3
- ## 1.4.0-pre-1-4-0-alpha.10
3
+ ## 1.4.0-pre-1-4-0.14
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - pre-release test
7
+ - lgc & lgjs alpha release
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - f6fab28: update tsup config
12
- - f6fab28: update entry
13
- - f6fab28: export langchain module
11
+ - a5efccd: Revert rxjs changes
12
+ - Updated dependencies [a5efccd]
13
+ - Updated dependencies
14
+ - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.14
15
+ - @copilotkit/shared@1.4.0-pre-1-4-0.14
16
+
17
+ ## 1.4.0-pre-1-4-0.13
18
+
19
+ ### Minor Changes
20
+
21
+ - lgc & lgjs alpha
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+ - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.13
27
+ - @copilotkit/shared@1.4.0-pre-1-4-0.13
28
+
29
+ ## 1.4.0-pre-1-4-0.12
30
+
31
+ ### Minor Changes
32
+
33
+ - c6b489d: LangGraph Platform and LangGraph JS support
34
+ - 7cc6cc8: LangGraph Cloud and LangGraphJS alpha release
35
+ - prerelease lgc and lgjs
36
+ - Add LangGraph Platform and LangGraph JS support
37
+ - b318b18: Add LangGraph Cloud support
38
+
39
+ ### Patch Changes
40
+
41
+ - 9ea9db1: update tsup config
42
+ - d52c1f9: update entry
43
+ - e71d469: export langchain module
14
44
  - 8a77944: Improve LangSmith support
15
- - f6fab28: Ensure intermediate state config is sent as snake case
16
- - f6fab28: update entry in tsup config
45
+ - 3caa5d5: Ensure intermediate state config is sent as snake case
46
+ - cf3a787: update entry in tsup config
17
47
  - 8a77944: Ensure the last message is sent to LangSmith
18
- - f6fab28: update entry
19
- - f6fab28: Update exports
20
- - f6fab28: Update exports
48
+ - 264a693: update entry
49
+ - dd99f00: Update exports
50
+ - a28fb90: Update exports
21
51
  - 332d744: Add support for Azure OpenAI
22
- - f6fab28: Export LangGraph functions
23
- - f6fab28: Update lockfile
24
- - Updated dependencies [f6fab28]
25
- - Updated dependencies
26
- - Updated dependencies [f6fab28]
27
- - Updated dependencies [f6fab28]
52
+ - 1f8032e: Export LangGraph functions
53
+ - c3576f6: Update lockfile
54
+ - Updated dependencies [9ea9db1]
55
+ - Updated dependencies [d52c1f9]
56
+ - Updated dependencies [c6b489d]
57
+ - Updated dependencies [7cc6cc8]
58
+ - Updated dependencies [e71d469]
28
59
  - Updated dependencies [8a77944]
29
- - Updated dependencies [f6fab28]
30
- - Updated dependencies [f6fab28]
60
+ - Updated dependencies [3caa5d5]
61
+ - Updated dependencies [cf3a787]
62
+ - Updated dependencies
63
+ - Updated dependencies
31
64
  - Updated dependencies [8a77944]
32
- - Updated dependencies [f6fab28]
33
- - Updated dependencies [f6fab28]
34
- - Updated dependencies [f6fab28]
65
+ - Updated dependencies [264a693]
66
+ - Updated dependencies [dd99f00]
67
+ - Updated dependencies [a28fb90]
35
68
  - Updated dependencies [332d744]
36
- - Updated dependencies [f6fab28]
37
- - Updated dependencies [f6fab28]
38
- - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0-alpha.10
39
- - @copilotkit/shared@1.4.0-pre-1-4-0-alpha.10
69
+ - Updated dependencies [b318b18]
70
+ - Updated dependencies [1f8032e]
71
+ - Updated dependencies [c3576f6]
72
+ - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.12
73
+ - @copilotkit/shared@1.4.0-pre-1-4-0.12
74
+
75
+ ## 1.4.0-pre-1-4-0.11
76
+
77
+ ### Minor Changes
78
+
79
+ - LangGraph Platform and LangGraph JS support
80
+
81
+ ### Patch Changes
82
+
83
+ - Updated dependencies
84
+ - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.11
85
+ - @copilotkit/shared@1.4.0-pre-1-4-0.11
86
+
87
+ ## 1.4.0-pre-1-4-0.10
88
+
89
+ ### Minor Changes
90
+
91
+ - LangGraph Cloud and LangGraphJS alpha release
92
+ - b318b18: Add LangGraph Cloud support
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies
97
+ - Updated dependencies [b318b18]
98
+ - @copilotkit/runtime-client-gql@1.4.0-pre-1-4-0.10
99
+ - @copilotkit/shared@1.4.0-pre-1-4-0.10
100
+
101
+ ## 1.3.16-mme-lgc-langgraph-package.9
102
+
103
+ ### Patch Changes
104
+
105
+ - update entry
106
+ - Updated dependencies
107
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.9
108
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.9
109
+
110
+ ## 1.3.16-mme-lgc-langgraph-package.8
111
+
112
+ ### Patch Changes
113
+
114
+ - update entry
115
+ - Updated dependencies
116
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.8
117
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.8
118
+
119
+ ## 1.3.16-mme-lgc-langgraph-package.7
120
+
121
+ ### Patch Changes
122
+
123
+ - update entry in tsup config
124
+ - Updated dependencies
125
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.7
126
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.7
127
+
128
+ ## 1.3.16-mme-lgc-langgraph-package.6
129
+
130
+ ### Patch Changes
131
+
132
+ - Update exports
133
+ - Updated dependencies
134
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.6
135
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.6
136
+
137
+ ## 1.3.16-mme-lgc-langgraph-package.5
138
+
139
+ ### Patch Changes
140
+
141
+ - update tsup config
142
+ - Updated dependencies
143
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.5
144
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.5
145
+
146
+ ## 1.3.16-mme-lgc-langgraph-package.4
147
+
148
+ ### Patch Changes
149
+
150
+ - Update exports
151
+ - Updated dependencies
152
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.4
153
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.4
154
+
155
+ ## 1.3.16-mme-lgc-langgraph-package.3
156
+
157
+ ### Patch Changes
158
+
159
+ - export langchain module
160
+ - Updated dependencies
161
+ - @copilotkit/runtime-client-gql@1.3.16-mme-lgc-langgraph-package.3
162
+ - @copilotkit/shared@1.3.16-mme-lgc-langgraph-package.3
163
+
164
+ ## 1.3.16-mme-sdk-js.2
165
+
166
+ ### Patch Changes
167
+
168
+ - Ensure intermediate state config is sent as snake case
169
+ - Updated dependencies
170
+ - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.2
171
+ - @copilotkit/shared@1.3.16-mme-sdk-js.2
172
+
173
+ ## 1.3.16-mme-sdk-js.1
174
+
175
+ ### Patch Changes
176
+
177
+ - Update lockfile
178
+ - Updated dependencies
179
+ - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.1
180
+ - @copilotkit/shared@1.3.16-mme-sdk-js.1
181
+
182
+ ## 1.3.16-mme-sdk-js.0
183
+
184
+ ### Patch Changes
185
+
186
+ - Export LangGraph functions
187
+ - Updated dependencies
188
+ - @copilotkit/runtime-client-gql@1.3.16-mme-sdk-js.0
189
+ - @copilotkit/shared@1.3.16-mme-sdk-js.0
40
190
 
41
191
  ## 1.3.15
42
192
 
@@ -123,4 +123,4 @@ function runAgent(name, context, appendMessage, hint) {
123
123
  export {
124
124
  useCoAgent
125
125
  };
126
- //# sourceMappingURL=chunk-PNLF3DOF.mjs.map
126
+ //# sourceMappingURL=chunk-XACBOJF5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent.ts"],"sourcesContent":["/**\n * <Callout type=\"info\">\n * Usage of this hook assumes some additional setup in your application, for more information\n * on that see the Agentic Copilots <span className=\"text-blue-500\">[getting started guide](/coagents/quickstart)</span>.\n * </Callout>\n * <Frame className=\"my-12\">\n * <img\n * src=\"/images/coagents/SharedStateCoAgents.gif\"\n * alt=\"CoAgents demonstration\"\n * className=\"w-auto\"\n * />\n * </Frame>\n *\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of an agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences \"Agentic Copilots\".\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgent } from \"@copilotkit/react-core\";\n *\n * type AgentState = {\n * count: number;\n * }\n *\n * const agent = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * ```\n *\n * `useCoAgent` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * name, // The name of the agent currently being used.\n * nodeName, // The name of the current LangGraph node.\n * state, // The current state of the agent.\n * setState, // A function to update the state of the agent.\n * running, // A boolean indicating if the agent is currently running.\n * start, // A function to start the agent.\n * stop, // A function to stop the agent.\n * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run.\n * } = agent;\n * ```\n *\n * Finally we can leverage these properties to create reactive experiences with the agent!\n *\n * ```tsx\n * const { state, setState } = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * return (\n * <div>\n * <p>Count: {state.count}</p>\n * <button onClick={() => setState({ count: state.count + 1 })}>Increment</button>\n * </div>\n * );\n * ```\n *\n * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa.\n *\n * ## Parameters\n * <PropertyReference name=\"options\" type=\"UseCoagentOptions<T>\" required>\n * The options to use when creating the coagent.\n * <PropertyReference name=\"name\" type=\"string\" required>\n * The name of the agent to use.\n * </PropertyReference>\n * <PropertyReference name=\"initialState\" type=\"T | any\">\n * The initial state of the agent.\n * </PropertyReference>\n * <PropertyReference name=\"state\" type=\"T | any\">\n * State to manage externally if you are using this hook with external state management.\n * </PropertyReference>\n * <PropertyReference name=\"setState\" type=\"(newState: T | ((prevState: T | undefined) => T)) => void\">\n * A function to update the state of the agent if you are using this hook with external state management.\n * </PropertyReference>\n * </PropertyReference>\n */\n\nimport { useEffect } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"../context\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { useCopilotChat } from \"./use-copilot-chat\";\nimport { AgentStateMessage, Message, Role, TextMessage } from \"@copilotkit/runtime-client-gql\";\n\ninterface WithInternalStateManagementAndInitial<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The initial state of the agent.\n */\n initialState: T;\n}\n\ninterface WithInternalStateManagement {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * Optional initialState with default type any\n */\n initialState?: any;\n}\n\ninterface WithExternalStateManagement<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n}\n\ntype UseCoagentOptions<T> =\n | WithInternalStateManagementAndInitial<T>\n | WithInternalStateManagement\n | WithExternalStateManagement<T>;\n\nexport interface UseCoagentReturnType<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The name of the current LangGraph node.\n */\n nodeName?: string;\n /**\n * The ID of the thread the agent is running in.\n */\n threadId?: string;\n /**\n * A boolean indicating if the agent is currently running.\n */\n running: boolean;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n /**\n * A function to start the agent.\n */\n start: () => void;\n /**\n * A function to stop the agent.\n */\n stop: () => void;\n /**\n * A function to re-run the agent. The hint function can be used to provide a hint to the agent\n * about why it is being re-run again.\n */\n run: (hint?: HintFunction) => Promise<void>;\n}\n\nexport interface HintFunctionParams {\n /**\n * The previous state of the agent.\n */\n previousState: any;\n /**\n * The current state of the agent.\n */\n currentState: any;\n}\n\nexport type HintFunction = (params: HintFunctionParams) => Message | undefined;\n\n/**\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of the agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences \"Agentic Copilots\". To get started using Agentic Copilots through this\n * hook, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart.\n */\nexport function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {\n const isExternalStateManagement = (\n options: UseCoagentOptions<T>,\n ): options is WithExternalStateManagement<T> => {\n return \"state\" in options && \"setState\" in options;\n };\n\n const { name } = options;\n\n const isInternalStateManagementWithInitial = (\n options: UseCoagentOptions<T>,\n ): options is WithInternalStateManagementAndInitial<T> => {\n return \"initialState\" in options;\n };\n\n const generalContext = useCopilotContext();\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const { coagentStates, setCoagentStates } = context;\n const { appendMessage } = useCopilotChat();\n\n const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {\n if (coagentStates[name]) {\n return coagentStates[name];\n } else {\n return {\n name,\n state: isInternalStateManagementWithInitial(options) ? options.initialState : {},\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n };\n }\n };\n\n // if we manage state internally, we need to provide a function to set the state\n const setState = (newState: T | ((prevState: T | undefined) => T)) => {\n setCoagentStates((prevAgentStates) => {\n let coagentState: CoagentState = getCoagentState(prevAgentStates, name);\n\n const updatedState =\n typeof newState === \"function\" ? (newState as Function)(coagentState.state) : newState;\n\n return {\n ...prevAgentStates,\n [name]: {\n ...coagentState,\n state: updatedState,\n },\n };\n });\n };\n\n const coagentState = getCoagentState(coagentStates, name);\n\n const state = isExternalStateManagement(options) ? options.state : coagentState.state;\n\n // Sync internal state with external state if state management is external\n useEffect(() => {\n if (isExternalStateManagement(options)) {\n setState(options.state);\n } else if (coagentStates[name] === undefined) {\n setState(options.initialState === undefined ? {} : options.initialState);\n }\n }, [isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined]);\n\n // Return the state and setState function\n return {\n name,\n nodeName: coagentState.nodeName,\n state,\n setState,\n running: coagentState.running,\n start: () => {\n startAgent(name, context);\n },\n stop: () => {\n stopAgent(name, context);\n },\n run: (hint?: HintFunction) => {\n return runAgent(name, context, appendMessage, hint);\n },\n };\n}\n\nfunction startAgent(name: string, context: CopilotContextParams) {\n const { setAgentSession } = context;\n setAgentSession({\n agentName: name,\n });\n}\n\nfunction stopAgent(name: string, context: CopilotContextParams) {\n const { agentSession, setAgentSession } = context;\n if (agentSession && agentSession.agentName === name) {\n setAgentSession(null);\n } else {\n console.warn(`No agent session found for ${name}`);\n }\n}\n\nasync function runAgent(\n name: string,\n context: CopilotContextParams & CopilotMessagesContextParams,\n appendMessage: (message: Message) => Promise<void>,\n hint?: HintFunction,\n) {\n const { agentSession, setAgentSession } = context;\n if (!agentSession || agentSession.agentName !== name) {\n setAgentSession({\n agentName: name,\n });\n }\n\n let previousState: any = null;\n for (let i = context.messages.length - 1; i >= 0; i--) {\n const message = context.messages[i];\n if (message.isAgentStateMessage() && message.agentName === name) {\n previousState = message.state;\n }\n }\n\n let state = context.coagentStates?.[name]?.state || {};\n\n if (hint) {\n const hintMessage = hint({ previousState, currentState: state });\n if (hintMessage) {\n await appendMessage(hintMessage);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0FA,SAAS,iBAAiB;AAgHnB,SAAS,WAAoB,SAAwD;AAC1F,QAAM,4BAA4B,CAChCA,aAC8C;AAC9C,WAAO,WAAWA,YAAW,cAAcA;AAAA,EAC7C;AAEA,QAAM,EAAE,KAAK,IAAI;AAEjB,QAAM,uCAAuC,CAC3CA,aACwD;AACxD,WAAO,kBAAkBA;AAAA,EAC3B;AAEA,QAAM,iBAAiB,kBAAkB;AACzC,QAAM,kBAAkB,0BA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