@copilotkit/sdk-js 1.51.5-next.0 → 1.51.5-next.1

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 (59) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/index.cjs +0 -0
  4. package/dist/index.d.cts +1 -0
  5. package/dist/index.d.mts +1 -0
  6. package/dist/index.mjs +1 -1
  7. package/dist/langchain.cjs +18 -0
  8. package/dist/langchain.cjs.map +1 -0
  9. package/dist/langchain.d.cts +3 -0
  10. package/dist/langchain.d.mts +4 -0
  11. package/dist/langchain.mjs +6 -23
  12. package/dist/langchain.mjs.map +1 -1
  13. package/dist/langgraph/middleware.cjs +139 -0
  14. package/dist/langgraph/middleware.cjs.map +1 -0
  15. package/dist/langgraph/middleware.d.cts +8 -0
  16. package/dist/langgraph/middleware.d.cts.map +1 -0
  17. package/dist/langgraph/middleware.d.mts +8 -0
  18. package/dist/langgraph/middleware.d.mts.map +1 -0
  19. package/dist/langgraph/middleware.mjs +137 -0
  20. package/dist/langgraph/middleware.mjs.map +1 -0
  21. package/dist/langgraph/types.cjs +19 -0
  22. package/dist/langgraph/types.cjs.map +1 -0
  23. package/dist/langgraph/types.d.cts +246 -0
  24. package/dist/langgraph/types.d.cts.map +1 -0
  25. package/dist/langgraph/types.d.mts +246 -0
  26. package/dist/langgraph/types.d.mts.map +1 -0
  27. package/dist/langgraph/types.mjs +17 -0
  28. package/dist/langgraph/types.mjs.map +1 -0
  29. package/dist/langgraph/utils.cjs +281 -0
  30. package/dist/langgraph/utils.cjs.map +1 -0
  31. package/dist/langgraph/utils.d.cts +192 -0
  32. package/dist/langgraph/utils.d.cts.map +1 -0
  33. package/dist/langgraph/utils.d.mts +192 -0
  34. package/dist/langgraph/utils.d.mts.map +1 -0
  35. package/dist/langgraph/utils.mjs +273 -0
  36. package/dist/langgraph/utils.mjs.map +1 -0
  37. package/dist/langgraph.cjs +16 -0
  38. package/dist/langgraph.d.cts +4 -0
  39. package/dist/langgraph.d.mts +4 -0
  40. package/dist/langgraph.mjs +5 -27
  41. package/package.json +22 -22
  42. package/tsdown.config.ts +17 -0
  43. package/vitest.config.mjs +11 -0
  44. package/dist/chunk-A7ZQHBQI.mjs +0 -505
  45. package/dist/chunk-A7ZQHBQI.mjs.map +0 -1
  46. package/dist/index.d.ts +0 -2
  47. package/dist/index.js +0 -1
  48. package/dist/index.js.map +0 -1
  49. package/dist/index.mjs.map +0 -1
  50. package/dist/langchain-db7cb6cb.d.ts +0 -427
  51. package/dist/langchain.d.ts +0 -6
  52. package/dist/langchain.js +0 -284
  53. package/dist/langchain.js.map +0 -1
  54. package/dist/langgraph/index.d.ts +0 -10
  55. package/dist/langgraph.js +0 -548
  56. package/dist/langgraph.js.map +0 -1
  57. package/dist/langgraph.mjs.map +0 -1
  58. package/jest.config.js +0 -5
  59. package/tsup.config.ts +0 -23
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @copilotkit/sdk-js
2
2
 
3
+ ## 1.51.5-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - @copilotkit/shared@1.51.5-next.1
8
+
3
9
  ## 1.51.5-next.0
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/index.cjs ADDED
File without changes
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- //# sourceMappingURL=index.mjs.map
1
+ export { };
@@ -0,0 +1,18 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_types = require('./langgraph/types.cjs');
3
+ const require_utils = require('./langgraph/utils.cjs');
4
+
5
+ //#region src/langchain.ts
6
+ console.warn("Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.");
7
+
8
+ //#endregion
9
+ exports.CopilotKitPropertiesAnnotation = require_types.CopilotKitPropertiesAnnotation;
10
+ exports.CopilotKitStateAnnotation = require_types.CopilotKitStateAnnotation;
11
+ exports.convertActionToDynamicStructuredTool = require_utils.convertActionToDynamicStructuredTool;
12
+ exports.convertActionsToDynamicStructuredTools = require_utils.convertActionsToDynamicStructuredTools;
13
+ exports.copilotKitCustomizeConfig = require_utils.copilotkitCustomizeConfig;
14
+ exports.copilotKitEmitMessage = require_utils.copilotkitEmitMessage;
15
+ exports.copilotKitEmitState = require_utils.copilotkitEmitState;
16
+ exports.copilotKitEmitToolCall = require_utils.copilotkitEmitToolCall;
17
+ exports.copilotKitExit = require_utils.copilotkitExit;
18
+ //# sourceMappingURL=langchain.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"langchain.cjs","names":[],"sources":["../src/langchain.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n"],"mappings":";;;;;AAAA,QAAQ,KACN,oJACD"}
@@ -0,0 +1,3 @@
1
+ import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation } from "./langgraph/types.cjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.cjs";
3
+ export { type CopilotKitProperties, CopilotKitPropertiesAnnotation, type CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig as copilotKitCustomizeConfig, copilotkitEmitMessage as copilotKitEmitMessage, copilotkitEmitState as copilotKitEmitState, copilotkitEmitToolCall as copilotKitEmitToolCall, copilotkitExit as copilotKitExit };
@@ -0,0 +1,4 @@
1
+ import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation } from "./langgraph/types.mjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
3
+ import "./langgraph.mjs";
4
+ export { type CopilotKitProperties, CopilotKitPropertiesAnnotation, type CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig as copilotKitCustomizeConfig, copilotkitEmitMessage as copilotKitEmitMessage, copilotkitEmitState as copilotKitEmitState, copilotkitEmitToolCall as copilotKitEmitToolCall, copilotkitExit as copilotKitExit };
@@ -1,26 +1,9 @@
1
- import {
2
- CopilotKitPropertiesAnnotation,
3
- CopilotKitStateAnnotation,
4
- convertActionToDynamicStructuredTool,
5
- convertActionsToDynamicStructuredTools,
6
- copilotkitCustomizeConfig,
7
- copilotkitEmitMessage,
8
- copilotkitEmitState,
9
- copilotkitEmitToolCall,
10
- copilotkitExit
11
- } from "./chunk-A7ZQHBQI.mjs";
1
+ import { CopilotKitPropertiesAnnotation, CopilotKitStateAnnotation } from "./langgraph/types.mjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
12
3
 
13
- // src/langchain.ts
4
+ //#region src/langchain.ts
14
5
  console.warn("Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.");
15
- export {
16
- CopilotKitPropertiesAnnotation,
17
- CopilotKitStateAnnotation,
18
- convertActionToDynamicStructuredTool,
19
- convertActionsToDynamicStructuredTools,
20
- copilotkitCustomizeConfig as copilotKitCustomizeConfig,
21
- copilotkitEmitMessage as copilotKitEmitMessage,
22
- copilotkitEmitState as copilotKitEmitState,
23
- copilotkitEmitToolCall as copilotKitEmitToolCall,
24
- copilotkitExit as copilotKitExit
25
- };
6
+
7
+ //#endregion
8
+ export { CopilotKitPropertiesAnnotation, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig as copilotKitCustomizeConfig, copilotkitEmitMessage as copilotKitEmitMessage, copilotkitEmitState as copilotKitEmitState, copilotkitEmitToolCall as copilotKitEmitToolCall, copilotkitExit as copilotKitExit };
26
9
  //# sourceMappingURL=langchain.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/langchain.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n"],"mappings":";;;;;;;;;;;;;AAAAA,QAAQC,KACN,mJAAA;","names":["console","warn"]}
1
+ {"version":3,"file":"langchain.mjs","names":[],"sources":["../src/langchain.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n"],"mappings":";;;;AAAA,QAAQ,KACN,oJACD"}
@@ -0,0 +1,139 @@
1
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
2
+ let langchain = require("langchain");
3
+ let zod = require("zod");
4
+ zod = require_runtime.__toESM(zod);
5
+
6
+ //#region src/langgraph/middleware.ts
7
+ const createAppContextBeforeAgent = (state, runtime) => {
8
+ const messages = state.messages;
9
+ if (!messages || messages.length === 0) return;
10
+ const appContext = state["copilotkit"]?.context ?? runtime?.context;
11
+ if (!appContext || typeof appContext === "string" && appContext.trim() === "" || typeof appContext === "object" && Object.keys(appContext).length === 0) return;
12
+ const contextMessageContent = `App Context:\n${typeof appContext === "string" ? appContext : JSON.stringify(appContext, null, 2)}`;
13
+ const contextMessagePrefix = "App Context:\n";
14
+ const getContentString = (msg) => {
15
+ if (typeof msg.content === "string") return msg.content;
16
+ if (Array.isArray(msg.content) && msg.content[0]?.text) return msg.content[0].text;
17
+ return null;
18
+ };
19
+ let firstSystemIndex = -1;
20
+ for (let i = 0; i < messages.length; i++) {
21
+ const msg = messages[i];
22
+ const type = msg._getType?.();
23
+ if (type === "system" || type === "developer") {
24
+ if (getContentString(msg)?.startsWith(contextMessagePrefix)) continue;
25
+ firstSystemIndex = i;
26
+ break;
27
+ }
28
+ }
29
+ let existingContextIndex = -1;
30
+ for (let i = 0; i < messages.length; i++) {
31
+ const msg = messages[i];
32
+ const type = msg._getType?.();
33
+ if (type === "system" || type === "developer") {
34
+ if (getContentString(msg)?.startsWith(contextMessagePrefix)) {
35
+ existingContextIndex = i;
36
+ break;
37
+ }
38
+ }
39
+ }
40
+ const contextMessage = new langchain.SystemMessage({ content: contextMessageContent });
41
+ let updatedMessages;
42
+ if (existingContextIndex !== -1) {
43
+ updatedMessages = [...messages];
44
+ updatedMessages[existingContextIndex] = contextMessage;
45
+ } else {
46
+ const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;
47
+ updatedMessages = [
48
+ ...messages.slice(0, insertIndex),
49
+ contextMessage,
50
+ ...messages.slice(insertIndex)
51
+ ];
52
+ }
53
+ return {
54
+ ...state,
55
+ messages: updatedMessages
56
+ };
57
+ };
58
+ const middlewareInput = {
59
+ name: "CopilotKitMiddleware",
60
+ stateSchema: zod.object({ copilotkit: zod.object({
61
+ actions: zod.array(zod.any()),
62
+ context: zod.any().optional(),
63
+ interceptedToolCalls: zod.array(zod.any()).optional(),
64
+ originalAIMessageId: zod.string().optional()
65
+ }).optional() }),
66
+ wrapModelCall: async (request, handler) => {
67
+ const frontendTools = request.state["copilotkit"]?.actions ?? [];
68
+ if (frontendTools.length === 0) return handler(request);
69
+ const mergedTools = [...request.tools || [], ...frontendTools];
70
+ return handler({
71
+ ...request,
72
+ tools: mergedTools
73
+ });
74
+ },
75
+ beforeAgent: createAppContextBeforeAgent,
76
+ afterAgent: (state) => {
77
+ const interceptedToolCalls = state["copilotkit"]?.interceptedToolCalls;
78
+ const originalMessageId = state["copilotkit"]?.originalAIMessageId;
79
+ if (!interceptedToolCalls?.length || !originalMessageId) return;
80
+ let messageFound = false;
81
+ const updatedMessages = state.messages.map((msg) => {
82
+ if (langchain.AIMessage.isInstance(msg) && msg.id === originalMessageId) {
83
+ messageFound = true;
84
+ const existingToolCalls = msg.tool_calls || [];
85
+ return new langchain.AIMessage({
86
+ content: msg.content,
87
+ tool_calls: [...existingToolCalls, ...interceptedToolCalls],
88
+ id: msg.id
89
+ });
90
+ }
91
+ return msg;
92
+ });
93
+ if (!messageFound) {
94
+ console.warn(`CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`);
95
+ return;
96
+ }
97
+ return {
98
+ messages: updatedMessages,
99
+ copilotkit: {
100
+ ...state["copilotkit"] ?? {},
101
+ interceptedToolCalls: void 0,
102
+ originalAIMessageId: void 0
103
+ }
104
+ };
105
+ },
106
+ afterModel: (state) => {
107
+ const frontendTools = state["copilotkit"]?.actions ?? [];
108
+ if (frontendTools.length === 0) return;
109
+ const frontendToolNames = new Set(frontendTools.map((t) => t.function?.name || t.name));
110
+ const lastMessage = state.messages[state.messages.length - 1];
111
+ if (!langchain.AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls?.length) return;
112
+ const backendToolCalls = [];
113
+ const frontendToolCalls = [];
114
+ for (const call of lastMessage.tool_calls) if (frontendToolNames.has(call.name)) frontendToolCalls.push(call);
115
+ else backendToolCalls.push(call);
116
+ if (frontendToolCalls.length === 0) return;
117
+ const updatedAIMessage = new langchain.AIMessage({
118
+ content: lastMessage.content,
119
+ tool_calls: backendToolCalls,
120
+ id: lastMessage.id
121
+ });
122
+ return {
123
+ messages: [...state.messages.slice(0, -1), updatedAIMessage],
124
+ copilotkit: {
125
+ ...state["copilotkit"] ?? {},
126
+ interceptedToolCalls: frontendToolCalls,
127
+ originalAIMessageId: lastMessage.id
128
+ }
129
+ };
130
+ }
131
+ };
132
+ const createCopilotKitMiddleware = () => {
133
+ return (0, langchain.createMiddleware)(middlewareInput);
134
+ };
135
+ const copilotkitMiddleware = createCopilotKitMiddleware();
136
+
137
+ //#endregion
138
+ exports.copilotkitMiddleware = copilotkitMiddleware;
139
+ //# sourceMappingURL=middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.cjs","names":["SystemMessage","z","AIMessage"],"sources":["../../src/langgraph/middleware.ts"],"sourcesContent":["import { createMiddleware, AIMessage, SystemMessage } from \"langchain\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport * as z from \"zod\";\n\nconst createAppContextBeforeAgent = (state, runtime) => {\n const messages = state.messages;\n\n if (!messages || messages.length === 0) {\n return;\n }\n\n // Get app context from runtime\n const appContext = state[\"copilotkit\"]?.context ?? runtime?.context;\n\n // Check if appContext is missing or empty\n const isEmptyContext =\n !appContext ||\n (typeof appContext === \"string\" && appContext.trim() === \"\") ||\n (typeof appContext === \"object\" && Object.keys(appContext).length === 0);\n\n if (isEmptyContext) {\n return;\n }\n\n // Create the context content\n const contextContent =\n typeof appContext === \"string\"\n ? appContext\n : JSON.stringify(appContext, null, 2);\n const contextMessageContent = `App Context:\\n${contextContent}`;\n const contextMessagePrefix = \"App Context:\\n\";\n\n // Helper to get message content as string\n const getContentString = (msg: any): string | null => {\n if (typeof msg.content === \"string\") return msg.content;\n if (Array.isArray(msg.content) && msg.content[0]?.text)\n return msg.content[0].text;\n return null;\n };\n\n // Find the first system/developer message (not our context message) to determine\n // where to insert our context message (right after it)\n let firstSystemIndex = -1;\n\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n // Skip if this is our own context message\n if (content?.startsWith(contextMessagePrefix)) {\n continue;\n }\n firstSystemIndex = i;\n break;\n }\n }\n\n // Check if our context message already exists\n let existingContextIndex = -1;\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n if (content?.startsWith(contextMessagePrefix)) {\n existingContextIndex = i;\n break;\n }\n }\n }\n\n // Create the context message\n const contextMessage = new SystemMessage({ content: contextMessageContent });\n\n let updatedMessages;\n\n if (existingContextIndex !== -1) {\n // Replace existing context message\n updatedMessages = [...messages];\n updatedMessages[existingContextIndex] = contextMessage;\n } else {\n // Insert after the first system message, or at position 0 if no system message\n const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;\n updatedMessages = [\n ...messages.slice(0, insertIndex),\n contextMessage,\n ...messages.slice(insertIndex),\n ];\n }\n\n return {\n ...state,\n messages: updatedMessages,\n };\n};\n\n/**\n * CopilotKit Middleware for LangGraph agents.\n *\n * Enables:\n * - Dynamic frontend tools from state.tools\n * - Context provided from CopilotKit useCopilotReadable\n *\n * Works with any agent (prebuilt or custom).\n *\n * @example\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { copilotkitMiddleware } from \"@copilotkit/sdk-js/langgraph\";\n *\n * const agent = createAgent({\n * model: \"gpt-4o\",\n * tools: [backendTool],\n * middleware: [copilotkitMiddleware],\n * });\n * ```\n */\nconst copilotKitStateSchema = z.object({\n copilotkit: z\n .object({\n actions: z.array(z.any()),\n context: z.any().optional(),\n interceptedToolCalls: z.array(z.any()).optional(),\n originalAIMessageId: z.string().optional(),\n })\n .optional(),\n});\n\nconst middlewareInput = {\n name: \"CopilotKitMiddleware\",\n\n stateSchema: copilotKitStateSchema as unknown as InteropZodObject,\n\n // Inject frontend tools before model call\n wrapModelCall: async (request, handler) => {\n const frontendTools = request.state[\"copilotkit\"]?.actions ?? [];\n\n if (frontendTools.length === 0) {\n return handler(request);\n }\n\n const existingTools = request.tools || [];\n const mergedTools = [...existingTools, ...frontendTools];\n\n return handler({\n ...request,\n tools: mergedTools,\n });\n },\n\n beforeAgent: createAppContextBeforeAgent,\n\n // Restore frontend tool calls to AIMessage before agent exits\n afterAgent: (state) => {\n const interceptedToolCalls = state[\"copilotkit\"]?.interceptedToolCalls;\n const originalMessageId = state[\"copilotkit\"]?.originalAIMessageId;\n\n if (!interceptedToolCalls?.length || !originalMessageId) {\n return;\n }\n\n let messageFound = false;\n const updatedMessages = state.messages.map((msg: any) => {\n if (AIMessage.isInstance(msg) && msg.id === originalMessageId) {\n messageFound = true;\n const existingToolCalls = msg.tool_calls || [];\n return new AIMessage({\n content: msg.content,\n tool_calls: [...existingToolCalls, ...interceptedToolCalls],\n id: msg.id,\n });\n }\n return msg;\n });\n\n // Only clear intercepted state if we successfully restored the tool calls\n if (!messageFound) {\n console.warn(\n `CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`,\n );\n return;\n }\n\n return {\n messages: updatedMessages,\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: undefined,\n originalAIMessageId: undefined,\n },\n };\n },\n\n // Intercept frontend tool calls after model returns, before ToolNode executes\n afterModel: (state) => {\n const frontendTools = state[\"copilotkit\"]?.actions ?? [];\n if (frontendTools.length === 0) return;\n\n const frontendToolNames = new Set(\n frontendTools.map((t: any) => t.function?.name || t.name),\n );\n\n const lastMessage = state.messages[state.messages.length - 1];\n if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls?.length) {\n return;\n }\n\n const backendToolCalls: any[] = [];\n const frontendToolCalls: any[] = [];\n\n for (const call of lastMessage.tool_calls) {\n if (frontendToolNames.has(call.name)) {\n frontendToolCalls.push(call);\n } else {\n backendToolCalls.push(call);\n }\n }\n\n if (frontendToolCalls.length === 0) return;\n\n const updatedAIMessage = new AIMessage({\n content: lastMessage.content,\n tool_calls: backendToolCalls,\n id: lastMessage.id,\n });\n\n return {\n messages: [...state.messages.slice(0, -1), updatedAIMessage],\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: frontendToolCalls,\n originalAIMessageId: lastMessage.id,\n },\n };\n },\n} as any;\nconst createCopilotKitMiddleware = () => {\n return createMiddleware(middlewareInput);\n};\n\nexport const copilotkitMiddleware = createCopilotKitMiddleware();\n"],"mappings":";;;;;;AAIA,MAAM,+BAA+B,OAAO,YAAY;CACtD,MAAM,WAAW,MAAM;AAEvB,KAAI,CAAC,YAAY,SAAS,WAAW,EACnC;CAIF,MAAM,aAAa,MAAM,eAAe,WAAW,SAAS;AAQ5D,KAJE,CAAC,cACA,OAAO,eAAe,YAAY,WAAW,MAAM,KAAK,MACxD,OAAO,eAAe,YAAY,OAAO,KAAK,WAAW,CAAC,WAAW,EAGtE;CAQF,MAAM,wBAAwB,iBAH5B,OAAO,eAAe,WAClB,aACA,KAAK,UAAU,YAAY,MAAM,EAAE;CAEzC,MAAM,uBAAuB;CAG7B,MAAM,oBAAoB,QAA4B;AACpD,MAAI,OAAO,IAAI,YAAY,SAAU,QAAO,IAAI;AAChD,MAAI,MAAM,QAAQ,IAAI,QAAQ,IAAI,IAAI,QAAQ,IAAI,KAChD,QAAO,IAAI,QAAQ,GAAG;AACxB,SAAO;;CAKT,IAAI,mBAAmB;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,MAAM,SAAS;EACrB,MAAM,OAAO,IAAI,YAAY;AAC7B,MAAI,SAAS,YAAY,SAAS,aAAa;AAG7C,OAFgB,iBAAiB,IAAI,EAExB,WAAW,qBAAqB,CAC3C;AAEF,sBAAmB;AACnB;;;CAKJ,IAAI,uBAAuB;AAC3B,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;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AAY;IAClC;GACF;;CAEJ;AACD,MAAM,mCAAmC;AACvC,wCAAwB,gBAAgB;;AAG1C,MAAa,uBAAuB,4BAA4B"}
@@ -0,0 +1,8 @@
1
+ import * as langchain from "langchain";
2
+ import * as _langchain_core_tools0 from "@langchain/core/tools";
3
+
4
+ //#region src/langgraph/middleware.d.ts
5
+ declare const copilotkitMiddleware: langchain.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
6
+ //#endregion
7
+ export { copilotkitMiddleware };
8
+ //# sourceMappingURL=middleware.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.cts","names":[],"sources":["../../src/langgraph/middleware.ts"],"mappings":";;;;cAiPa,oBAAA,EAAoB,SAAA,CAAA,eAAA,0CAA+B,sBAAA,CAA/B,UAAA,GAAA,sBAAA,CAAA,UAAA"}
@@ -0,0 +1,8 @@
1
+ import * as _langchain_core_tools0 from "@langchain/core/tools";
2
+ import * as langchain from "langchain";
3
+
4
+ //#region src/langgraph/middleware.d.ts
5
+ declare const copilotkitMiddleware: langchain.AgentMiddleware<undefined, undefined, unknown, readonly (_langchain_core_tools0.ClientTool | _langchain_core_tools0.ServerTool)[]>;
6
+ //#endregion
7
+ export { copilotkitMiddleware };
8
+ //# sourceMappingURL=middleware.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.mts","names":[],"sources":["../../src/langgraph/middleware.ts"],"mappings":";;;;cAiPa,oBAAA,EAAoB,SAAA,CAAA,eAAA,0CAA+B,sBAAA,CAA/B,UAAA,GAAA,sBAAA,CAAA,UAAA"}
@@ -0,0 +1,137 @@
1
+ import { AIMessage, SystemMessage, createMiddleware } from "langchain";
2
+ import * as z from "zod";
3
+
4
+ //#region src/langgraph/middleware.ts
5
+ const createAppContextBeforeAgent = (state, runtime) => {
6
+ const messages = state.messages;
7
+ if (!messages || messages.length === 0) return;
8
+ const appContext = state["copilotkit"]?.context ?? runtime?.context;
9
+ if (!appContext || typeof appContext === "string" && appContext.trim() === "" || typeof appContext === "object" && Object.keys(appContext).length === 0) return;
10
+ const contextMessageContent = `App Context:\n${typeof appContext === "string" ? appContext : JSON.stringify(appContext, null, 2)}`;
11
+ const contextMessagePrefix = "App Context:\n";
12
+ const getContentString = (msg) => {
13
+ if (typeof msg.content === "string") return msg.content;
14
+ if (Array.isArray(msg.content) && msg.content[0]?.text) return msg.content[0].text;
15
+ return null;
16
+ };
17
+ let firstSystemIndex = -1;
18
+ for (let i = 0; i < messages.length; i++) {
19
+ const msg = messages[i];
20
+ const type = msg._getType?.();
21
+ if (type === "system" || type === "developer") {
22
+ if (getContentString(msg)?.startsWith(contextMessagePrefix)) continue;
23
+ firstSystemIndex = i;
24
+ break;
25
+ }
26
+ }
27
+ let existingContextIndex = -1;
28
+ for (let i = 0; i < messages.length; i++) {
29
+ const msg = messages[i];
30
+ const type = msg._getType?.();
31
+ if (type === "system" || type === "developer") {
32
+ if (getContentString(msg)?.startsWith(contextMessagePrefix)) {
33
+ existingContextIndex = i;
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ const contextMessage = new SystemMessage({ content: contextMessageContent });
39
+ let updatedMessages;
40
+ if (existingContextIndex !== -1) {
41
+ updatedMessages = [...messages];
42
+ updatedMessages[existingContextIndex] = contextMessage;
43
+ } else {
44
+ const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;
45
+ updatedMessages = [
46
+ ...messages.slice(0, insertIndex),
47
+ contextMessage,
48
+ ...messages.slice(insertIndex)
49
+ ];
50
+ }
51
+ return {
52
+ ...state,
53
+ messages: updatedMessages
54
+ };
55
+ };
56
+ const middlewareInput = {
57
+ name: "CopilotKitMiddleware",
58
+ stateSchema: z.object({ copilotkit: z.object({
59
+ actions: z.array(z.any()),
60
+ context: z.any().optional(),
61
+ interceptedToolCalls: z.array(z.any()).optional(),
62
+ originalAIMessageId: z.string().optional()
63
+ }).optional() }),
64
+ wrapModelCall: async (request, handler) => {
65
+ const frontendTools = request.state["copilotkit"]?.actions ?? [];
66
+ if (frontendTools.length === 0) return handler(request);
67
+ const mergedTools = [...request.tools || [], ...frontendTools];
68
+ return handler({
69
+ ...request,
70
+ tools: mergedTools
71
+ });
72
+ },
73
+ beforeAgent: createAppContextBeforeAgent,
74
+ afterAgent: (state) => {
75
+ const interceptedToolCalls = state["copilotkit"]?.interceptedToolCalls;
76
+ const originalMessageId = state["copilotkit"]?.originalAIMessageId;
77
+ if (!interceptedToolCalls?.length || !originalMessageId) return;
78
+ let messageFound = false;
79
+ const updatedMessages = state.messages.map((msg) => {
80
+ if (AIMessage.isInstance(msg) && msg.id === originalMessageId) {
81
+ messageFound = true;
82
+ const existingToolCalls = msg.tool_calls || [];
83
+ return new AIMessage({
84
+ content: msg.content,
85
+ tool_calls: [...existingToolCalls, ...interceptedToolCalls],
86
+ id: msg.id
87
+ });
88
+ }
89
+ return msg;
90
+ });
91
+ if (!messageFound) {
92
+ console.warn(`CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`);
93
+ return;
94
+ }
95
+ return {
96
+ messages: updatedMessages,
97
+ copilotkit: {
98
+ ...state["copilotkit"] ?? {},
99
+ interceptedToolCalls: void 0,
100
+ originalAIMessageId: void 0
101
+ }
102
+ };
103
+ },
104
+ afterModel: (state) => {
105
+ const frontendTools = state["copilotkit"]?.actions ?? [];
106
+ if (frontendTools.length === 0) return;
107
+ const frontendToolNames = new Set(frontendTools.map((t) => t.function?.name || t.name));
108
+ const lastMessage = state.messages[state.messages.length - 1];
109
+ if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls?.length) return;
110
+ const backendToolCalls = [];
111
+ const frontendToolCalls = [];
112
+ for (const call of lastMessage.tool_calls) if (frontendToolNames.has(call.name)) frontendToolCalls.push(call);
113
+ else backendToolCalls.push(call);
114
+ if (frontendToolCalls.length === 0) return;
115
+ const updatedAIMessage = new AIMessage({
116
+ content: lastMessage.content,
117
+ tool_calls: backendToolCalls,
118
+ id: lastMessage.id
119
+ });
120
+ return {
121
+ messages: [...state.messages.slice(0, -1), updatedAIMessage],
122
+ copilotkit: {
123
+ ...state["copilotkit"] ?? {},
124
+ interceptedToolCalls: frontendToolCalls,
125
+ originalAIMessageId: lastMessage.id
126
+ }
127
+ };
128
+ }
129
+ };
130
+ const createCopilotKitMiddleware = () => {
131
+ return createMiddleware(middlewareInput);
132
+ };
133
+ const copilotkitMiddleware = createCopilotKitMiddleware();
134
+
135
+ //#endregion
136
+ export { copilotkitMiddleware };
137
+ //# sourceMappingURL=middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.mjs","names":[],"sources":["../../src/langgraph/middleware.ts"],"sourcesContent":["import { createMiddleware, AIMessage, SystemMessage } from \"langchain\";\nimport type { InteropZodObject } from \"@langchain/core/utils/types\";\nimport * as z from \"zod\";\n\nconst createAppContextBeforeAgent = (state, runtime) => {\n const messages = state.messages;\n\n if (!messages || messages.length === 0) {\n return;\n }\n\n // Get app context from runtime\n const appContext = state[\"copilotkit\"]?.context ?? runtime?.context;\n\n // Check if appContext is missing or empty\n const isEmptyContext =\n !appContext ||\n (typeof appContext === \"string\" && appContext.trim() === \"\") ||\n (typeof appContext === \"object\" && Object.keys(appContext).length === 0);\n\n if (isEmptyContext) {\n return;\n }\n\n // Create the context content\n const contextContent =\n typeof appContext === \"string\"\n ? appContext\n : JSON.stringify(appContext, null, 2);\n const contextMessageContent = `App Context:\\n${contextContent}`;\n const contextMessagePrefix = \"App Context:\\n\";\n\n // Helper to get message content as string\n const getContentString = (msg: any): string | null => {\n if (typeof msg.content === \"string\") return msg.content;\n if (Array.isArray(msg.content) && msg.content[0]?.text)\n return msg.content[0].text;\n return null;\n };\n\n // Find the first system/developer message (not our context message) to determine\n // where to insert our context message (right after it)\n let firstSystemIndex = -1;\n\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n // Skip if this is our own context message\n if (content?.startsWith(contextMessagePrefix)) {\n continue;\n }\n firstSystemIndex = i;\n break;\n }\n }\n\n // Check if our context message already exists\n let existingContextIndex = -1;\n for (let i = 0; i < messages.length; i++) {\n const msg = messages[i];\n const type = msg._getType?.();\n if (type === \"system\" || type === \"developer\") {\n const content = getContentString(msg);\n if (content?.startsWith(contextMessagePrefix)) {\n existingContextIndex = i;\n break;\n }\n }\n }\n\n // Create the context message\n const contextMessage = new SystemMessage({ content: contextMessageContent });\n\n let updatedMessages;\n\n if (existingContextIndex !== -1) {\n // Replace existing context message\n updatedMessages = [...messages];\n updatedMessages[existingContextIndex] = contextMessage;\n } else {\n // Insert after the first system message, or at position 0 if no system message\n const insertIndex = firstSystemIndex !== -1 ? firstSystemIndex + 1 : 0;\n updatedMessages = [\n ...messages.slice(0, insertIndex),\n contextMessage,\n ...messages.slice(insertIndex),\n ];\n }\n\n return {\n ...state,\n messages: updatedMessages,\n };\n};\n\n/**\n * CopilotKit Middleware for LangGraph agents.\n *\n * Enables:\n * - Dynamic frontend tools from state.tools\n * - Context provided from CopilotKit useCopilotReadable\n *\n * Works with any agent (prebuilt or custom).\n *\n * @example\n * ```typescript\n * import { createAgent } from \"langchain\";\n * import { copilotkitMiddleware } from \"@copilotkit/sdk-js/langgraph\";\n *\n * const agent = createAgent({\n * model: \"gpt-4o\",\n * tools: [backendTool],\n * middleware: [copilotkitMiddleware],\n * });\n * ```\n */\nconst copilotKitStateSchema = z.object({\n copilotkit: z\n .object({\n actions: z.array(z.any()),\n context: z.any().optional(),\n interceptedToolCalls: z.array(z.any()).optional(),\n originalAIMessageId: z.string().optional(),\n })\n .optional(),\n});\n\nconst middlewareInput = {\n name: \"CopilotKitMiddleware\",\n\n stateSchema: copilotKitStateSchema as unknown as InteropZodObject,\n\n // Inject frontend tools before model call\n wrapModelCall: async (request, handler) => {\n const frontendTools = request.state[\"copilotkit\"]?.actions ?? [];\n\n if (frontendTools.length === 0) {\n return handler(request);\n }\n\n const existingTools = request.tools || [];\n const mergedTools = [...existingTools, ...frontendTools];\n\n return handler({\n ...request,\n tools: mergedTools,\n });\n },\n\n beforeAgent: createAppContextBeforeAgent,\n\n // Restore frontend tool calls to AIMessage before agent exits\n afterAgent: (state) => {\n const interceptedToolCalls = state[\"copilotkit\"]?.interceptedToolCalls;\n const originalMessageId = state[\"copilotkit\"]?.originalAIMessageId;\n\n if (!interceptedToolCalls?.length || !originalMessageId) {\n return;\n }\n\n let messageFound = false;\n const updatedMessages = state.messages.map((msg: any) => {\n if (AIMessage.isInstance(msg) && msg.id === originalMessageId) {\n messageFound = true;\n const existingToolCalls = msg.tool_calls || [];\n return new AIMessage({\n content: msg.content,\n tool_calls: [...existingToolCalls, ...interceptedToolCalls],\n id: msg.id,\n });\n }\n return msg;\n });\n\n // Only clear intercepted state if we successfully restored the tool calls\n if (!messageFound) {\n console.warn(\n `CopilotKit: Could not find message with id ${originalMessageId} to restore tool calls`,\n );\n return;\n }\n\n return {\n messages: updatedMessages,\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: undefined,\n originalAIMessageId: undefined,\n },\n };\n },\n\n // Intercept frontend tool calls after model returns, before ToolNode executes\n afterModel: (state) => {\n const frontendTools = state[\"copilotkit\"]?.actions ?? [];\n if (frontendTools.length === 0) return;\n\n const frontendToolNames = new Set(\n frontendTools.map((t: any) => t.function?.name || t.name),\n );\n\n const lastMessage = state.messages[state.messages.length - 1];\n if (!AIMessage.isInstance(lastMessage) || !lastMessage.tool_calls?.length) {\n return;\n }\n\n const backendToolCalls: any[] = [];\n const frontendToolCalls: any[] = [];\n\n for (const call of lastMessage.tool_calls) {\n if (frontendToolNames.has(call.name)) {\n frontendToolCalls.push(call);\n } else {\n backendToolCalls.push(call);\n }\n }\n\n if (frontendToolCalls.length === 0) return;\n\n const updatedAIMessage = new AIMessage({\n content: lastMessage.content,\n tool_calls: backendToolCalls,\n id: lastMessage.id,\n });\n\n return {\n messages: [...state.messages.slice(0, -1), updatedAIMessage],\n copilotkit: {\n ...(state[\"copilotkit\"] ?? {}),\n interceptedToolCalls: frontendToolCalls,\n originalAIMessageId: lastMessage.id,\n },\n };\n },\n} as any;\nconst createCopilotKitMiddleware = () => {\n return createMiddleware(middlewareInput);\n};\n\nexport const copilotkitMiddleware = createCopilotKitMiddleware();\n"],"mappings":";;;;AAIA,MAAM,+BAA+B,OAAO,YAAY;CACtD,MAAM,WAAW,MAAM;AAEvB,KAAI,CAAC,YAAY,SAAS,WAAW,EACnC;CAIF,MAAM,aAAa,MAAM,eAAe,WAAW,SAAS;AAQ5D,KAJE,CAAC,cACA,OAAO,eAAe,YAAY,WAAW,MAAM,KAAK,MACxD,OAAO,eAAe,YAAY,OAAO,KAAK,WAAW,CAAC,WAAW,EAGtE;CAQF,MAAM,wBAAwB,iBAH5B,OAAO,eAAe,WAClB,aACA,KAAK,UAAU,YAAY,MAAM,EAAE;CAEzC,MAAM,uBAAuB;CAG7B,MAAM,oBAAoB,QAA4B;AACpD,MAAI,OAAO,IAAI,YAAY,SAAU,QAAO,IAAI;AAChD,MAAI,MAAM,QAAQ,IAAI,QAAQ,IAAI,IAAI,QAAQ,IAAI,KAChD,QAAO,IAAI,QAAQ,GAAG;AACxB,SAAO;;CAKT,IAAI,mBAAmB;AAEvB,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,MAAM,SAAS;EACrB,MAAM,OAAO,IAAI,YAAY;AAC7B,MAAI,SAAS,YAAY,SAAS,aAAa;AAG7C,OAFgB,iBAAiB,IAAI,EAExB,WAAW,qBAAqB,CAC3C;AAEF,sBAAmB;AACnB;;;CAKJ,IAAI,uBAAuB;AAC3B,MAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,MAAM,SAAS;EACrB,MAAM,OAAO,IAAI,YAAY;AAC7B,MAAI,SAAS,YAAY,SAAS,aAEhC;OADgB,iBAAiB,IAAI,EACxB,WAAW,qBAAqB,EAAE;AAC7C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');
2
+ let _langchain_langgraph = require("@langchain/langgraph");
3
+
4
+ //#region src/langgraph/types.ts
5
+ const CopilotKitPropertiesAnnotation = _langchain_langgraph.Annotation.Root({
6
+ actions: _langchain_langgraph.Annotation,
7
+ context: _langchain_langgraph.Annotation,
8
+ interceptedToolCalls: _langchain_langgraph.Annotation,
9
+ originalAIMessageId: _langchain_langgraph.Annotation
10
+ });
11
+ const CopilotKitStateAnnotation = _langchain_langgraph.Annotation.Root({
12
+ copilotkit: _langchain_langgraph.Annotation,
13
+ ..._langchain_langgraph.MessagesAnnotation.spec
14
+ });
15
+
16
+ //#endregion
17
+ exports.CopilotKitPropertiesAnnotation = CopilotKitPropertiesAnnotation;
18
+ exports.CopilotKitStateAnnotation = CopilotKitStateAnnotation;
19
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","names":["Annotation","MessagesAnnotation"],"sources":["../../src/langgraph/types.ts"],"sourcesContent":["import { Annotation, MessagesAnnotation } from \"@langchain/langgraph\";\n\nexport const CopilotKitPropertiesAnnotation = Annotation.Root({\n actions: Annotation<any[]>,\n context: Annotation<{ description: string; value: string }[]>,\n interceptedToolCalls: Annotation<any[]>,\n originalAIMessageId: Annotation<string>,\n});\n\nexport const CopilotKitStateAnnotation = Annotation.Root({\n copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,\n ...MessagesAnnotation.spec,\n});\n\nexport interface IntermediateStateConfig {\n stateKey: string;\n tool: string;\n toolArgument?: string;\n}\n\nexport interface OptionsConfig {\n emitToolCalls?: boolean | string | string[];\n emitMessages?: boolean;\n emitAll?: boolean;\n emitIntermediateState?: IntermediateStateConfig[];\n}\n\nexport type CopilotKitState = typeof CopilotKitStateAnnotation.State;\nexport type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;\n"],"mappings":";;;;AAEA,MAAa,iCAAiCA,gCAAW,KAAK;CAC5D,SAASA;CACT,SAASA;CACT,sBAAsBA;CACtB,qBAAqBA;CACtB,CAAC;AAEF,MAAa,4BAA4BA,gCAAW,KAAK;CACvD,YAAYA;CACZ,GAAGC,wCAAmB;CACvB,CAAC"}