@copilotkit/sdk-js 2.0.0-rc.5 → 2.0.0-rc.50

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.
@@ -6,7 +6,7 @@ import { DynamicStructuredTool } from "@langchain/core/tools";
6
6
  /**
7
7
  * Customize the LangGraph configuration for use in CopilotKit.
8
8
  *
9
- * To the CopilotKit SDK, run:
9
+ * To install the CopilotKit SDK, run:
10
10
  *
11
11
  * ```bash
12
12
  * npm install @copilotkit/sdk-js
@@ -17,13 +17,15 @@ import { DynamicStructuredTool } from "@langchain/core/tools";
17
17
  * Disable emitting messages and tool calls:
18
18
  *
19
19
  * ```typescript
20
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
21
- *
22
- * config = copilotkitCustomizeConfig(
23
- * config,
24
- * emitMessages=false,
25
- * emitToolCalls=false
26
- * )
20
+ * import type { RunnableConfig } from "@langchain/core/runnables";
21
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
22
+ *
23
+ * function customize(config: RunnableConfig) {
24
+ * return copilotkitCustomizeConfig(config, {
25
+ * emitMessages: false,
26
+ * emitToolCalls: false,
27
+ * });
28
+ * }
27
29
  * ```
28
30
  *
29
31
  * To emit a tool call as streaming LangGraph state, pass the destination key in state,
@@ -31,18 +33,20 @@ import { DynamicStructuredTool } from "@langchain/core/tools";
31
33
  * all arguments are emitted under the state key.)
32
34
  *
33
35
  * ```typescript
34
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
35
- *
36
- * config = copilotkitCustomizeConfig(
37
- * config,
38
- * emitIntermediateState=[
39
- * {
40
- * "stateKey": "steps",
41
- * "tool": "SearchTool",
42
- * "toolArgument": "steps",
43
- * },
44
- * ],
45
- * )
36
+ * import type { RunnableConfig } from "@langchain/core/runnables";
37
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
38
+ *
39
+ * function customize(config: RunnableConfig) {
40
+ * return copilotkitCustomizeConfig(config, {
41
+ * emitIntermediateState: [
42
+ * {
43
+ * stateKey: "steps",
44
+ * tool: "SearchTool",
45
+ * toolArgument: "steps",
46
+ * },
47
+ * ],
48
+ * });
49
+ * }
46
50
  * ```
47
51
  */
48
52
  declare function copilotkitCustomizeConfig(
@@ -63,18 +67,23 @@ baseConfig: RunnableConfig,
63
67
  */
64
68
  options?: OptionsConfig): RunnableConfig;
65
69
  /**
66
- * Exits the current agent after the run completes. Calling copilotkit_exit() will
70
+ * Exits the current agent after the run completes. Calling copilotkitExit() will
67
71
  * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
68
72
  * the run completes.
69
73
  *
70
74
  * ### Examples
71
75
  *
72
76
  * ```typescript
73
- * import { copilotkitExit } from "@copilotkit/sdk-js";
77
+ * import type { RunnableConfig } from "@langchain/core/runnables";
78
+ * import type { MessagesAnnotation } from "@langchain/langgraph";
79
+ * import { copilotkitExit } from "@copilotkit/sdk-js/langgraph";
74
80
  *
75
- * async function myNode(state: Any):
76
- * await copilotkitExit(config)
77
- * return state
81
+ * type AgentState = typeof MessagesAnnotation.State;
82
+ *
83
+ * async function myNode(state: AgentState, config: RunnableConfig) {
84
+ * await copilotkitExit(config);
85
+ * return state;
86
+ * }
78
87
  * ```
79
88
  */
80
89
  declare function copilotkitExit(
@@ -89,11 +98,16 @@ config: RunnableConfig): Promise<void>;
89
98
  * ### Examples
90
99
  *
91
100
  * ```typescript
92
- * import { copilotkitEmitState } from "@copilotkit/sdk-js";
101
+ * import type { RunnableConfig } from "@langchain/core/runnables";
102
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js/langgraph";
93
103
  *
94
- * for (let i = 0; i < 10; i++) {
95
- * await someLongRunningOperation(i);
96
- * await copilotkitEmitState(config, { progress: i });
104
+ * declare function someLongRunningOperation(step: number): Promise<void>;
105
+ *
106
+ * async function myNode(config: RunnableConfig) {
107
+ * for (let i = 0; i < 10; i++) {
108
+ * await someLongRunningOperation(i);
109
+ * await copilotkitEmitState(config, { progress: i });
110
+ * }
97
111
  * }
98
112
  * ```
99
113
  */
@@ -113,14 +127,18 @@ state: any): Promise<void>;
113
127
  * ### Examples
114
128
  *
115
129
  * ```typescript
116
- * import { copilotkitEmitMessage } from "@copilotkit/sdk-js";
117
- *
118
- * const message = "Step 1 of 10 complete";
119
- * await copilotkitEmitMessage(config, message);
120
- *
121
- * // Return the message from the node
122
- * return {
123
- * "messages": [AIMessage(content=message)]
130
+ * import type { RunnableConfig } from "@langchain/core/runnables";
131
+ * import { AIMessage } from "@langchain/core/messages";
132
+ * import { copilotkitEmitMessage } from "@copilotkit/sdk-js/langgraph";
133
+ *
134
+ * async function myNode(config: RunnableConfig) {
135
+ * const message = "Step 1 of 10 complete";
136
+ * await copilotkitEmitMessage(config, message);
137
+ *
138
+ * // Return the message from the node
139
+ * return {
140
+ * messages: [new AIMessage({ content: message })],
141
+ * };
124
142
  * }
125
143
  * ```
126
144
  */
@@ -139,15 +157,18 @@ message: string): Promise<void>;
139
157
  * ### Examples
140
158
  *
141
159
  * ```typescript
142
- * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
160
+ * import type { RunnableConfig } from "@langchain/core/runnables";
161
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js/langgraph";
143
162
  *
144
- * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
163
+ * async function myNode(config: RunnableConfig) {
164
+ * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
145
165
  *
146
- * // With a custom ID for correlation/idempotency:
147
- * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
166
+ * // With a custom ID for correlation/idempotency:
167
+ * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
168
+ * }
148
169
  * ```
149
170
  *
150
- * @returns The tool call ID used for the emitted call — equals `options.toolCallId`
171
+ * @returns The tool call ID used for the emitted call. It equals `options.toolCallId`
151
172
  * when provided, otherwise a randomly generated ID.
152
173
  */
153
174
  declare function copilotkitEmitToolCall(
@@ -182,7 +203,7 @@ declare function convertActionToDynamicStructuredTool(actionInput: any): Dynamic
182
203
  * ### Examples
183
204
  *
184
205
  * ```typescript
185
- * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
206
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js/langgraph";
186
207
  *
187
208
  * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
188
209
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/langgraph/utils.ts"],"mappings":";;;;;;;AAuDA;;;;;;;;;;;;;;;AAwHA;;;;;;;;;AAmCA;;;;;;;;;;AAoDA;;;;;;iBA/MgB,yBAAA;;;;AAId,UAAA,EAAY,cAAA;;;;;;;;;;;;AAYZ,OAAA,GAAU,aAAA,GACT,cAAA;AAmUH;;;;;AA0DA;;;;;AAyBA;;;;;AAnFA,iBA5NsB,cAAA;;;;AAIpB,MAAA,EAAQ,cAAA,GAAc,OAAA;;;;;;;;;;;;;;;;iBA+BF,mBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,KAAA,QAAU,OAAA;;;;;;;;;;;;;;;;;;;iBA4CU,qBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,OAAA,WAAe,OAAA;;;;;;;;;;;;;;;;;;iBA2CK,sBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,IAAA;;;;AAIA,IAAA;;;;AAIA,OAAA;;;;;;EAME,UAAA;AAAA,IAED,OAAA;AAAA,iBA0Da,oCAAA,CACd,WAAA,QACC,qBAAA;;;;;;;;;;;;;iBAwDa,sCAAA;;;;AAId,OAAA,UACC,qBAAA;AAAA,iBAoBa,mBAAA,CAAA;EACd,OAAA;EACA,MAAA;EACA;AAAA;EAEA,OAAA;EACA,MAAA;EACA,IAAA,GAAO,MAAA;AAAA"}
1
+ {"version":3,"file":"utils.d.cts","names":[],"sources":["../../src/langgraph/utils.ts"],"mappings":";;;;;;;AA2DA;;;;;;;;;;;;;;;AA6HA;;;;;;;;;AAwCA;;;;;;;;;;AAwDA;;;;;;;;;;iBA7NgB,yBAAA;;;;AAId,UAAA,EAAY,cAAA;;;;;;;;;AAiWd;;;AArVE,OAAA,GAAU,aAAA,GACT,cAAA;;AA8YH;;;;;AAyBA;;;;;;;;;;;;;;iBA3TsB,cAAA;;;;AAIpB,MAAA,EAAQ,cAAA,GAAc,OAAA;;;;;;;;;;;;;;;;;;;;;iBAoCF,mBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,KAAA,QAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;iBAgDU,qBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,OAAA,WAAe,OAAA;;;;;;;;;;;;;;;;;;;;;iBA8CK,sBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,IAAA;;;;AAIA,IAAA;;;;AAIA,OAAA;;;;;;EAME,UAAA;AAAA,IAED,OAAA;AAAA,iBA0Da,oCAAA,CACd,WAAA,QACC,qBAAA;;;;;;;;;;;;;iBAwDa,sCAAA;;;;AAId,OAAA,UACC,qBAAA;AAAA,iBAoBa,mBAAA,CAAA;EACd,OAAA;EACA,MAAA;EACA;AAAA;EAEA,OAAA;EACA,MAAA;EACA,IAAA,GAAO,MAAA;AAAA"}
@@ -6,7 +6,7 @@ import { RunnableConfig } from "@langchain/core/runnables";
6
6
  /**
7
7
  * Customize the LangGraph configuration for use in CopilotKit.
8
8
  *
9
- * To the CopilotKit SDK, run:
9
+ * To install the CopilotKit SDK, run:
10
10
  *
11
11
  * ```bash
12
12
  * npm install @copilotkit/sdk-js
@@ -17,13 +17,15 @@ import { RunnableConfig } from "@langchain/core/runnables";
17
17
  * Disable emitting messages and tool calls:
18
18
  *
19
19
  * ```typescript
20
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
21
- *
22
- * config = copilotkitCustomizeConfig(
23
- * config,
24
- * emitMessages=false,
25
- * emitToolCalls=false
26
- * )
20
+ * import type { RunnableConfig } from "@langchain/core/runnables";
21
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
22
+ *
23
+ * function customize(config: RunnableConfig) {
24
+ * return copilotkitCustomizeConfig(config, {
25
+ * emitMessages: false,
26
+ * emitToolCalls: false,
27
+ * });
28
+ * }
27
29
  * ```
28
30
  *
29
31
  * To emit a tool call as streaming LangGraph state, pass the destination key in state,
@@ -31,18 +33,20 @@ import { RunnableConfig } from "@langchain/core/runnables";
31
33
  * all arguments are emitted under the state key.)
32
34
  *
33
35
  * ```typescript
34
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
35
- *
36
- * config = copilotkitCustomizeConfig(
37
- * config,
38
- * emitIntermediateState=[
39
- * {
40
- * "stateKey": "steps",
41
- * "tool": "SearchTool",
42
- * "toolArgument": "steps",
43
- * },
44
- * ],
45
- * )
36
+ * import type { RunnableConfig } from "@langchain/core/runnables";
37
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
38
+ *
39
+ * function customize(config: RunnableConfig) {
40
+ * return copilotkitCustomizeConfig(config, {
41
+ * emitIntermediateState: [
42
+ * {
43
+ * stateKey: "steps",
44
+ * tool: "SearchTool",
45
+ * toolArgument: "steps",
46
+ * },
47
+ * ],
48
+ * });
49
+ * }
46
50
  * ```
47
51
  */
48
52
  declare function copilotkitCustomizeConfig(
@@ -63,18 +67,23 @@ baseConfig: RunnableConfig,
63
67
  */
64
68
  options?: OptionsConfig): RunnableConfig;
65
69
  /**
66
- * Exits the current agent after the run completes. Calling copilotkit_exit() will
70
+ * Exits the current agent after the run completes. Calling copilotkitExit() will
67
71
  * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
68
72
  * the run completes.
69
73
  *
70
74
  * ### Examples
71
75
  *
72
76
  * ```typescript
73
- * import { copilotkitExit } from "@copilotkit/sdk-js";
77
+ * import type { RunnableConfig } from "@langchain/core/runnables";
78
+ * import type { MessagesAnnotation } from "@langchain/langgraph";
79
+ * import { copilotkitExit } from "@copilotkit/sdk-js/langgraph";
74
80
  *
75
- * async function myNode(state: Any):
76
- * await copilotkitExit(config)
77
- * return state
81
+ * type AgentState = typeof MessagesAnnotation.State;
82
+ *
83
+ * async function myNode(state: AgentState, config: RunnableConfig) {
84
+ * await copilotkitExit(config);
85
+ * return state;
86
+ * }
78
87
  * ```
79
88
  */
80
89
  declare function copilotkitExit(
@@ -89,11 +98,16 @@ config: RunnableConfig): Promise<void>;
89
98
  * ### Examples
90
99
  *
91
100
  * ```typescript
92
- * import { copilotkitEmitState } from "@copilotkit/sdk-js";
101
+ * import type { RunnableConfig } from "@langchain/core/runnables";
102
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js/langgraph";
93
103
  *
94
- * for (let i = 0; i < 10; i++) {
95
- * await someLongRunningOperation(i);
96
- * await copilotkitEmitState(config, { progress: i });
104
+ * declare function someLongRunningOperation(step: number): Promise<void>;
105
+ *
106
+ * async function myNode(config: RunnableConfig) {
107
+ * for (let i = 0; i < 10; i++) {
108
+ * await someLongRunningOperation(i);
109
+ * await copilotkitEmitState(config, { progress: i });
110
+ * }
97
111
  * }
98
112
  * ```
99
113
  */
@@ -113,14 +127,18 @@ state: any): Promise<void>;
113
127
  * ### Examples
114
128
  *
115
129
  * ```typescript
116
- * import { copilotkitEmitMessage } from "@copilotkit/sdk-js";
117
- *
118
- * const message = "Step 1 of 10 complete";
119
- * await copilotkitEmitMessage(config, message);
120
- *
121
- * // Return the message from the node
122
- * return {
123
- * "messages": [AIMessage(content=message)]
130
+ * import type { RunnableConfig } from "@langchain/core/runnables";
131
+ * import { AIMessage } from "@langchain/core/messages";
132
+ * import { copilotkitEmitMessage } from "@copilotkit/sdk-js/langgraph";
133
+ *
134
+ * async function myNode(config: RunnableConfig) {
135
+ * const message = "Step 1 of 10 complete";
136
+ * await copilotkitEmitMessage(config, message);
137
+ *
138
+ * // Return the message from the node
139
+ * return {
140
+ * messages: [new AIMessage({ content: message })],
141
+ * };
124
142
  * }
125
143
  * ```
126
144
  */
@@ -139,15 +157,18 @@ message: string): Promise<void>;
139
157
  * ### Examples
140
158
  *
141
159
  * ```typescript
142
- * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
160
+ * import type { RunnableConfig } from "@langchain/core/runnables";
161
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js/langgraph";
143
162
  *
144
- * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
163
+ * async function myNode(config: RunnableConfig) {
164
+ * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
145
165
  *
146
- * // With a custom ID for correlation/idempotency:
147
- * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
166
+ * // With a custom ID for correlation/idempotency:
167
+ * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
168
+ * }
148
169
  * ```
149
170
  *
150
- * @returns The tool call ID used for the emitted call — equals `options.toolCallId`
171
+ * @returns The tool call ID used for the emitted call. It equals `options.toolCallId`
151
172
  * when provided, otherwise a randomly generated ID.
152
173
  */
153
174
  declare function copilotkitEmitToolCall(
@@ -182,7 +203,7 @@ declare function convertActionToDynamicStructuredTool(actionInput: any): Dynamic
182
203
  * ### Examples
183
204
  *
184
205
  * ```typescript
185
- * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
206
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js/langgraph";
186
207
  *
187
208
  * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
188
209
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/langgraph/utils.ts"],"mappings":";;;;;;;AAuDA;;;;;;;;;;;;;;;AAwHA;;;;;;;;;AAmCA;;;;;;;;;;AAoDA;;;;;;iBA/MgB,y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,cAAA;;;;AAIR,OAAA,WAAe,OAAA;;;;;;;;;;;;;;;;;;;;;iBA8CK,sBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,IAAA;;;;AAIA,IAAA;;;;AAIA,OAAA;;;;;;EAME,UAAA;AAAA,IAED,OAAA;AAAA,iBA0Da,oCAAA,CACd,WAAA,QACC,qBAAA;;;;;;;;;;;;;iBAwDa,sCAAA;;;;AAId,OAAA,UACC,qBAAA;AAAA,iBAoBa,mBAAA,CAAA;EACd,OAAA;EACA,MAAA;EACA;AAAA;EAEA,OAAA;EACA,MAAA;EACA,IAAA,GAAO,MAAA;AAAA"}
@@ -1,6 +1,7 @@
1
+ import { convertJsonSchemaToZodSchema } from "./json-schema-to-zod.mjs";
1
2
  import { interrupt } from "@langchain/langgraph";
2
3
  import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
3
- import { CopilotKitMisuseError, convertJsonSchemaToZodSchema, randomId, randomUUID } from "@copilotkit/shared";
4
+ import { CopilotKitMisuseError, randomId, randomUUID } from "@copilotkit/shared";
4
5
  import { DynamicStructuredTool } from "@langchain/core/tools";
5
6
  import { AIMessage } from "@langchain/core/messages";
6
7
 
@@ -8,7 +9,7 @@ import { AIMessage } from "@langchain/core/messages";
8
9
  /**
9
10
  * Customize the LangGraph configuration for use in CopilotKit.
10
11
  *
11
- * To the CopilotKit SDK, run:
12
+ * To install the CopilotKit SDK, run:
12
13
  *
13
14
  * ```bash
14
15
  * npm install @copilotkit/sdk-js
@@ -19,13 +20,15 @@ import { AIMessage } from "@langchain/core/messages";
19
20
  * Disable emitting messages and tool calls:
20
21
  *
21
22
  * ```typescript
22
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
23
+ * import type { RunnableConfig } from "@langchain/core/runnables";
24
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
23
25
  *
24
- * config = copilotkitCustomizeConfig(
25
- * config,
26
- * emitMessages=false,
27
- * emitToolCalls=false
28
- * )
26
+ * function customize(config: RunnableConfig) {
27
+ * return copilotkitCustomizeConfig(config, {
28
+ * emitMessages: false,
29
+ * emitToolCalls: false,
30
+ * });
31
+ * }
29
32
  * ```
30
33
  *
31
34
  * To emit a tool call as streaming LangGraph state, pass the destination key in state,
@@ -33,18 +36,20 @@ import { AIMessage } from "@langchain/core/messages";
33
36
  * all arguments are emitted under the state key.)
34
37
  *
35
38
  * ```typescript
36
- * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
39
+ * import type { RunnableConfig } from "@langchain/core/runnables";
40
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js/langgraph";
37
41
  *
38
- * config = copilotkitCustomizeConfig(
39
- * config,
40
- * emitIntermediateState=[
41
- * {
42
- * "stateKey": "steps",
43
- * "tool": "SearchTool",
44
- * "toolArgument": "steps",
45
- * },
46
- * ],
47
- * )
42
+ * function customize(config: RunnableConfig) {
43
+ * return copilotkitCustomizeConfig(config, {
44
+ * emitIntermediateState: [
45
+ * {
46
+ * stateKey: "steps",
47
+ * tool: "SearchTool",
48
+ * toolArgument: "steps",
49
+ * },
50
+ * ],
51
+ * });
52
+ * }
48
53
  * ```
49
54
  */
50
55
  function copilotkitCustomizeConfig(baseConfig, options) {
@@ -83,18 +88,23 @@ function copilotkitCustomizeConfig(baseConfig, options) {
83
88
  }
84
89
  }
85
90
  /**
86
- * Exits the current agent after the run completes. Calling copilotkit_exit() will
91
+ * Exits the current agent after the run completes. Calling copilotkitExit() will
87
92
  * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
88
93
  * the run completes.
89
94
  *
90
95
  * ### Examples
91
96
  *
92
97
  * ```typescript
93
- * import { copilotkitExit } from "@copilotkit/sdk-js";
98
+ * import type { RunnableConfig } from "@langchain/core/runnables";
99
+ * import type { MessagesAnnotation } from "@langchain/langgraph";
100
+ * import { copilotkitExit } from "@copilotkit/sdk-js/langgraph";
101
+ *
102
+ * type AgentState = typeof MessagesAnnotation.State;
94
103
  *
95
- * async function myNode(state: Any):
96
- * await copilotkitExit(config)
97
- * return state
104
+ * async function myNode(state: AgentState, config: RunnableConfig) {
105
+ * await copilotkitExit(config);
106
+ * return state;
107
+ * }
98
108
  * ```
99
109
  */
100
110
  async function copilotkitExit(config) {
@@ -112,11 +122,16 @@ async function copilotkitExit(config) {
112
122
  * ### Examples
113
123
  *
114
124
  * ```typescript
115
- * import { copilotkitEmitState } from "@copilotkit/sdk-js";
125
+ * import type { RunnableConfig } from "@langchain/core/runnables";
126
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js/langgraph";
127
+ *
128
+ * declare function someLongRunningOperation(step: number): Promise<void>;
116
129
  *
117
- * for (let i = 0; i < 10; i++) {
118
- * await someLongRunningOperation(i);
119
- * await copilotkitEmitState(config, { progress: i });
130
+ * async function myNode(config: RunnableConfig) {
131
+ * for (let i = 0; i < 10; i++) {
132
+ * await someLongRunningOperation(i);
133
+ * await copilotkitEmitState(config, { progress: i });
134
+ * }
120
135
  * }
121
136
  * ```
122
137
  */
@@ -136,14 +151,18 @@ async function copilotkitEmitState(config, state) {
136
151
  * ### Examples
137
152
  *
138
153
  * ```typescript
139
- * import { copilotkitEmitMessage } from "@copilotkit/sdk-js";
154
+ * import type { RunnableConfig } from "@langchain/core/runnables";
155
+ * import { AIMessage } from "@langchain/core/messages";
156
+ * import { copilotkitEmitMessage } from "@copilotkit/sdk-js/langgraph";
140
157
  *
141
- * const message = "Step 1 of 10 complete";
142
- * await copilotkitEmitMessage(config, message);
158
+ * async function myNode(config: RunnableConfig) {
159
+ * const message = "Step 1 of 10 complete";
160
+ * await copilotkitEmitMessage(config, message);
143
161
  *
144
- * // Return the message from the node
145
- * return {
146
- * "messages": [AIMessage(content=message)]
162
+ * // Return the message from the node
163
+ * return {
164
+ * messages: [new AIMessage({ content: message })],
165
+ * };
147
166
  * }
148
167
  * ```
149
168
  */
@@ -166,15 +185,18 @@ async function copilotkitEmitMessage(config, message) {
166
185
  * ### Examples
167
186
  *
168
187
  * ```typescript
169
- * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
188
+ * import type { RunnableConfig } from "@langchain/core/runnables";
189
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js/langgraph";
170
190
  *
171
- * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
191
+ * async function myNode(config: RunnableConfig) {
192
+ * const autoId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 });
172
193
  *
173
- * // With a custom ID for correlation/idempotency:
174
- * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
194
+ * // With a custom ID for correlation/idempotency:
195
+ * const customId = await copilotkitEmitToolCall(config, "SearchTool", { steps: 10 }, { toolCallId: "my-custom-id" });
196
+ * }
175
197
  * ```
176
198
  *
177
- * @returns The tool call ID used for the emitted call — equals `options.toolCallId`
199
+ * @returns The tool call ID used for the emitted call. It equals `options.toolCallId`
178
200
  * when provided, otherwise a randomly generated ID.
179
201
  */
180
202
  async function copilotkitEmitToolCall(config, name, args, options) {
@@ -226,7 +248,7 @@ function convertActionToDynamicStructuredTool(actionInput) {
226
248
  * ### Examples
227
249
  *
228
250
  * ```typescript
229
- * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
251
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js/langgraph";
230
252
  *
231
253
  * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
232
254
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/langgraph/utils.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport {\n convertJsonSchemaToZodSchema,\n randomId,\n randomUUID,\n CopilotKitMisuseError,\n} from \"@copilotkit/shared\";\nimport { interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\nimport type { OptionsConfig } from \"./types\";\n\n/**\n * Customize the LangGraph configuration for use in CopilotKit.\n *\n * To the CopilotKit SDK, run:\n *\n * ```bash\n * npm install @copilotkit/sdk-js\n * ```\n *\n * ### Examples\n *\n * Disable emitting messages and tool calls:\n *\n * ```typescript\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js\";\n *\n * config = copilotkitCustomizeConfig(\n * config,\n * emitMessages=false,\n * emitToolCalls=false\n * )\n * ```\n *\n * To emit a tool call as streaming LangGraph state, pass the destination key in state,\n * the tool name and optionally the tool argument. (If you don't pass the argument name,\n * all arguments are emitted under the state key.)\n *\n * ```typescript\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js\";\n *\n * config = copilotkitCustomizeConfig(\n * config,\n * emitIntermediateState=[\n * {\n * \"stateKey\": \"steps\",\n * \"tool\": \"SearchTool\",\n * \"toolArgument\": \"steps\",\n * },\n * ],\n * )\n * ```\n */\nexport function copilotkitCustomizeConfig(\n /**\n * The LangChain/LangGraph configuration to customize.\n */\n baseConfig: RunnableConfig,\n /**\n * Configuration options:\n * - `emitMessages: boolean?`\n * Configure how messages are emitted. By default, all messages are emitted. Pass false to\n * disable emitting messages.\n * - `emitToolCalls: boolean | string | string[]?`\n * Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to\n * disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.\n * - `emitIntermediateState: IntermediateStateConfig[]?`\n * Lets you emit tool calls as streaming LangGraph state.\n */\n options?: OptionsConfig,\n): RunnableConfig {\n if (baseConfig && typeof baseConfig !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"baseConfig must be an object or null/undefined\",\n });\n }\n\n if (options && typeof options !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"options must be an object when provided\",\n });\n }\n\n // Validate emitIntermediateState structure\n if (options?.emitIntermediateState) {\n if (!Array.isArray(options.emitIntermediateState)) {\n throw new CopilotKitMisuseError({\n message: \"emitIntermediateState must be an array when provided\",\n });\n }\n\n options.emitIntermediateState.forEach((state, index) => {\n if (!state || typeof state !== \"object\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must be an object`,\n });\n }\n\n if (!state.stateKey || typeof state.stateKey !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`,\n });\n }\n\n if (!state.tool || typeof state.tool !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'tool' string property`,\n });\n }\n\n if (state.toolArgument && typeof state.toolArgument !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}].toolArgument must be a string when provided`,\n });\n }\n });\n }\n\n try {\n const metadata = baseConfig?.metadata || {};\n\n if (options?.emitAll) {\n metadata[\"copilotkit:emit-tool-calls\"] = true;\n metadata[\"copilotkit:emit-messages\"] = true;\n } else {\n if (options?.emitToolCalls !== undefined) {\n metadata[\"copilotkit:emit-tool-calls\"] = options.emitToolCalls;\n }\n if (options?.emitMessages !== undefined) {\n metadata[\"copilotkit:emit-messages\"] = options.emitMessages;\n }\n }\n\n if (options?.emitIntermediateState) {\n const snakeCaseIntermediateState = options.emitIntermediateState.map(\n (state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }),\n );\n\n metadata[\"copilotkit:emit-intermediate-state\"] =\n snakeCaseIntermediateState;\n }\n\n baseConfig = baseConfig || {};\n\n return {\n ...baseConfig,\n metadata: metadata,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Exits the current agent after the run completes. Calling copilotkit_exit() will\n * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after\n * the run completes.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitExit } from \"@copilotkit/sdk-js\";\n *\n * async function myNode(state: Any):\n * await copilotkitExit(config)\n * return state\n * ```\n */\nexport async function copilotkitExit(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitExit\",\n });\n }\n\n try {\n await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to\n * update the user with the current state of the node.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitState } from \"@copilotkit/sdk-js\";\n *\n * for (let i = 0; i < 10; i++) {\n * await someLongRunningOperation(i);\n * await copilotkitEmitState(config, { progress: i });\n * }\n * ```\n */\nexport async function copilotkitEmitState(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The state to emit.\n */\n state: any,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitState\",\n });\n }\n\n if (state === undefined) {\n throw new CopilotKitMisuseError({\n message: \"State is required for copilotkitEmitState\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_intermediate_state\",\n state,\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.\n * Important: You still need to return the messages from the node.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitMessage } from \"@copilotkit/sdk-js\";\n *\n * const message = \"Step 1 of 10 complete\";\n * await copilotkitEmitMessage(config, message);\n *\n * // Return the message from the node\n * return {\n * \"messages\": [AIMessage(content=message)]\n * }\n * ```\n */\nexport async function copilotkitEmitMessage(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The message to emit.\n */\n message: string,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitMessage\",\n });\n }\n\n if (!message || typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a non-empty string for copilotkitEmitMessage\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a tool call to CopilotKit.\n *\n * ### Examples\n *\n * ```typescript\n * import { copilotkitEmitToolCall } from \"@copilotkit/sdk-js\";\n *\n * const autoId = await copilotkitEmitToolCall(config, \"SearchTool\", { steps: 10 });\n *\n * // With a custom ID for correlation/idempotency:\n * const customId = await copilotkitEmitToolCall(config, \"SearchTool\", { steps: 10 }, { toolCallId: \"my-custom-id\" });\n * ```\n *\n * @returns The tool call ID used for the emitted call — equals `options.toolCallId`\n * when provided, otherwise a randomly generated ID.\n */\nexport async function copilotkitEmitToolCall(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The name of the tool to emit.\n */\n name: string,\n /**\n * The arguments to emit.\n */\n args: any,\n /**\n * Options for the tool call emission.\n */\n options?: {\n /**\n * Optional tool call ID. If not provided, a random ID is generated.\n * When provided, this ID is used as the toolCallId and parentMessageId\n * in AG-UI protocol events. The caller is responsible for ensuring uniqueness.\n */\n toolCallId?: string;\n },\n): Promise<string> {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitToolCall\",\n });\n }\n\n if (typeof name !== \"string\" || name.trim().length === 0) {\n throw new CopilotKitMisuseError({\n message:\n \"Tool name must be a non-empty string for copilotkitEmitToolCall\",\n });\n }\n\n if (\n options?.toolCallId !== undefined &&\n (typeof options.toolCallId !== \"string\" ||\n options.toolCallId.trim().length === 0)\n ) {\n throw new CopilotKitMisuseError({\n message:\n \"Tool call id must be a non-empty string when provided for copilotkitEmitToolCall\",\n });\n }\n\n if (args === undefined) {\n throw new CopilotKitMisuseError({\n message: \"Tool arguments are required for copilotkitEmitToolCall\",\n });\n }\n\n try {\n JSON.stringify(args);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Tool arguments for '${name}' are not JSON-serializable: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n\n const toolCallId = options?.toolCallId ?? randomUUID();\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_tool_call\",\n { name, args, id: toolCallId },\n config,\n );\n } catch (error) {\n const wrapped = new Error(\n `copilotkitEmitToolCall dispatch failed for tool=\"${name}\" id=\"${toolCallId}\": ${error instanceof Error ? error.message : String(error)}`,\n );\n (wrapped as any).cause = error;\n throw wrapped;\n }\n\n return toolCallId;\n}\n\nexport function convertActionToDynamicStructuredTool(\n actionInput: any,\n): DynamicStructuredTool<any> {\n if (!actionInput) {\n throw new CopilotKitMisuseError({\n message: \"Action input is required but was not provided\",\n });\n }\n\n if (!actionInput.name || typeof actionInput.name !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must have a valid 'name' property of type string\",\n });\n }\n\n if (\n actionInput.description == undefined ||\n actionInput.description == null ||\n typeof actionInput.description !== \"string\"\n ) {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a valid 'description' property of type string`,\n });\n }\n\n if (!actionInput.parameters) {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a 'parameters' property`,\n });\n }\n\n try {\n return new DynamicStructuredTool({\n name: actionInput.name,\n description: actionInput.description,\n schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),\n func: async () => {\n return \"\";\n },\n });\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Use this function to convert a list of actions you get from state\n * to a list of dynamic structured tools.\n *\n * ### Examples\n *\n * ```typescript\n * import { convertActionsToDynamicStructuredTools } from \"@copilotkit/sdk-js\";\n *\n * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);\n * ```\n */\nexport function convertActionsToDynamicStructuredTools(\n /**\n * The list of actions to convert.\n */\n actions: any[],\n): DynamicStructuredTool<any>[] {\n if (!Array.isArray(actions)) {\n throw new CopilotKitMisuseError({\n message: \"Actions must be an array\",\n });\n }\n\n return actions.map((action, index) => {\n try {\n return convertActionToDynamicStructuredTool(\n action.type === \"function\" ? action.function : action,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n });\n}\n\nexport function copilotKitInterrupt({\n message,\n action,\n args,\n}: {\n message?: string;\n action?: string;\n args?: Record<string, any>;\n}) {\n if (!message && !action) {\n throw new CopilotKitMisuseError({\n message:\n \"Either message or action (and optional arguments) must be provided for copilotKitInterrupt\",\n });\n }\n\n if (action && typeof action !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (message && typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (args && typeof args !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"Args must be an object when provided to copilotKitInterrupt\",\n });\n }\n\n let interruptValues = null;\n let interruptMessage = null;\n let answer = null;\n\n try {\n if (message) {\n interruptValues = message;\n interruptMessage = new AIMessage({ content: message, id: randomId() });\n } else {\n const toolId = randomId();\n interruptMessage = new AIMessage({\n content: \"\",\n tool_calls: [{ id: toolId, name: action, args: args ?? {} }],\n });\n interruptValues = {\n action,\n args: args ?? {},\n };\n }\n\n const response = interrupt({\n __copilotkit_interrupt_value__: interruptValues,\n __copilotkit_messages__: [interruptMessage],\n });\n answer = response[response.length - 1].content;\n\n return {\n answer,\n messages: response,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to create interrupt: ${error instanceof Error ? error.message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IAAI,SAAS;AAEb,KAAI;AACF,MAAI,SAAS;AACX,qBAAkB;AAClB,sBAAmB,IAAI,UAAU;IAAE,SAAS;IAAS,IAAI,UAAU;IAAE,CAAC;SACjE;AAEL,sBAAmB,IAAI,UAAU;IAC/B,SAAS;IACT,YAAY,CAAC;KAAE,IAHF,UAAU;KAGI,MAAM;KAAQ,MAAM,QAAQ,EAAE;KAAE,CAAC;IAC7D,CAAC;AACF,qBAAkB;IAChB;IACA,MAAM,QAAQ,EAAE;IACjB;;EAGH,MAAM,WAAW,UAAU;GACzB,gCAAgC;GAChC,yBAAyB,CAAC,iBAAiB;GAC5C,CAAC;AACF,WAAS,SAAS,SAAS,SAAS,GAAG;AAEvC,SAAO;GACL;GACA,UAAU;GACX;UACM,OAAO;AACd,QAAM,IAAI,sBAAsB,EAC9B,SAAS,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,IAC/F,CAAC"}
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/langgraph/utils.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport {\n randomId,\n randomUUID,\n CopilotKitMisuseError,\n} from \"@copilotkit/shared\";\nimport { interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\nimport type { OptionsConfig } from \"./types\";\nimport { convertJsonSchemaToZodSchema } from \"./json-schema-to-zod\";\n\n/**\n * Customize the LangGraph configuration for use in CopilotKit.\n *\n * To install the CopilotKit SDK, run:\n *\n * ```bash\n * npm install @copilotkit/sdk-js\n * ```\n *\n * ### Examples\n *\n * Disable emitting messages and tool calls:\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js/langgraph\";\n *\n * function customize(config: RunnableConfig) {\n * return copilotkitCustomizeConfig(config, {\n * emitMessages: false,\n * emitToolCalls: false,\n * });\n * }\n * ```\n *\n * To emit a tool call as streaming LangGraph state, pass the destination key in state,\n * the tool name and optionally the tool argument. (If you don't pass the argument name,\n * all arguments are emitted under the state key.)\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import { copilotkitCustomizeConfig } from \"@copilotkit/sdk-js/langgraph\";\n *\n * function customize(config: RunnableConfig) {\n * return copilotkitCustomizeConfig(config, {\n * emitIntermediateState: [\n * {\n * stateKey: \"steps\",\n * tool: \"SearchTool\",\n * toolArgument: \"steps\",\n * },\n * ],\n * });\n * }\n * ```\n */\nexport function copilotkitCustomizeConfig(\n /**\n * The LangChain/LangGraph configuration to customize.\n */\n baseConfig: RunnableConfig,\n /**\n * Configuration options:\n * - `emitMessages: boolean?`\n * Configure how messages are emitted. By default, all messages are emitted. Pass false to\n * disable emitting messages.\n * - `emitToolCalls: boolean | string | string[]?`\n * Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to\n * disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.\n * - `emitIntermediateState: IntermediateStateConfig[]?`\n * Lets you emit tool calls as streaming LangGraph state.\n */\n options?: OptionsConfig,\n): RunnableConfig {\n if (baseConfig && typeof baseConfig !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"baseConfig must be an object or null/undefined\",\n });\n }\n\n if (options && typeof options !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"options must be an object when provided\",\n });\n }\n\n // Validate emitIntermediateState structure\n if (options?.emitIntermediateState) {\n if (!Array.isArray(options.emitIntermediateState)) {\n throw new CopilotKitMisuseError({\n message: \"emitIntermediateState must be an array when provided\",\n });\n }\n\n options.emitIntermediateState.forEach((state, index) => {\n if (!state || typeof state !== \"object\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must be an object`,\n });\n }\n\n if (!state.stateKey || typeof state.stateKey !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`,\n });\n }\n\n if (!state.tool || typeof state.tool !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}] must have a valid 'tool' string property`,\n });\n }\n\n if (state.toolArgument && typeof state.toolArgument !== \"string\") {\n throw new CopilotKitMisuseError({\n message: `emitIntermediateState[${index}].toolArgument must be a string when provided`,\n });\n }\n });\n }\n\n try {\n const metadata = baseConfig?.metadata || {};\n\n if (options?.emitAll) {\n metadata[\"copilotkit:emit-tool-calls\"] = true;\n metadata[\"copilotkit:emit-messages\"] = true;\n } else {\n if (options?.emitToolCalls !== undefined) {\n metadata[\"copilotkit:emit-tool-calls\"] = options.emitToolCalls;\n }\n if (options?.emitMessages !== undefined) {\n metadata[\"copilotkit:emit-messages\"] = options.emitMessages;\n }\n }\n\n if (options?.emitIntermediateState) {\n const snakeCaseIntermediateState = options.emitIntermediateState.map(\n (state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }),\n );\n\n metadata[\"copilotkit:emit-intermediate-state\"] =\n snakeCaseIntermediateState;\n }\n\n baseConfig = baseConfig || {};\n\n return {\n ...baseConfig,\n metadata: metadata,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Exits the current agent after the run completes. Calling copilotkitExit() will\n * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after\n * the run completes.\n *\n * ### Examples\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import type { MessagesAnnotation } from \"@langchain/langgraph\";\n * import { copilotkitExit } from \"@copilotkit/sdk-js/langgraph\";\n *\n * type AgentState = typeof MessagesAnnotation.State;\n *\n * async function myNode(state: AgentState, config: RunnableConfig) {\n * await copilotkitExit(config);\n * return state;\n * }\n * ```\n */\nexport async function copilotkitExit(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitExit\",\n });\n }\n\n try {\n await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to\n * update the user with the current state of the node.\n *\n * ### Examples\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import { copilotkitEmitState } from \"@copilotkit/sdk-js/langgraph\";\n *\n * declare function someLongRunningOperation(step: number): Promise<void>;\n *\n * async function myNode(config: RunnableConfig) {\n * for (let i = 0; i < 10; i++) {\n * await someLongRunningOperation(i);\n * await copilotkitEmitState(config, { progress: i });\n * }\n * }\n * ```\n */\nexport async function copilotkitEmitState(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The state to emit.\n */\n state: any,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitState\",\n });\n }\n\n if (state === undefined) {\n throw new CopilotKitMisuseError({\n message: \"State is required for copilotkitEmitState\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_intermediate_state\",\n state,\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.\n * Important: You still need to return the messages from the node.\n *\n * ### Examples\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import { AIMessage } from \"@langchain/core/messages\";\n * import { copilotkitEmitMessage } from \"@copilotkit/sdk-js/langgraph\";\n *\n * async function myNode(config: RunnableConfig) {\n * const message = \"Step 1 of 10 complete\";\n * await copilotkitEmitMessage(config, message);\n *\n * // Return the message from the node\n * return {\n * messages: [new AIMessage({ content: message })],\n * };\n * }\n * ```\n */\nexport async function copilotkitEmitMessage(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The message to emit.\n */\n message: string,\n) {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitMessage\",\n });\n }\n\n if (!message || typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a non-empty string for copilotkitEmitMessage\",\n });\n }\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Manually emits a tool call to CopilotKit.\n *\n * ### Examples\n *\n * ```typescript\n * import type { RunnableConfig } from \"@langchain/core/runnables\";\n * import { copilotkitEmitToolCall } from \"@copilotkit/sdk-js/langgraph\";\n *\n * async function myNode(config: RunnableConfig) {\n * const autoId = await copilotkitEmitToolCall(config, \"SearchTool\", { steps: 10 });\n *\n * // With a custom ID for correlation/idempotency:\n * const customId = await copilotkitEmitToolCall(config, \"SearchTool\", { steps: 10 }, { toolCallId: \"my-custom-id\" });\n * }\n * ```\n *\n * @returns The tool call ID used for the emitted call. It equals `options.toolCallId`\n * when provided, otherwise a randomly generated ID.\n */\nexport async function copilotkitEmitToolCall(\n /**\n * The LangChain/LangGraph configuration.\n */\n config: RunnableConfig,\n /**\n * The name of the tool to emit.\n */\n name: string,\n /**\n * The arguments to emit.\n */\n args: any,\n /**\n * Options for the tool call emission.\n */\n options?: {\n /**\n * Optional tool call ID. If not provided, a random ID is generated.\n * When provided, this ID is used as the toolCallId and parentMessageId\n * in AG-UI protocol events. The caller is responsible for ensuring uniqueness.\n */\n toolCallId?: string;\n },\n): Promise<string> {\n if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitToolCall\",\n });\n }\n\n if (typeof name !== \"string\" || name.trim().length === 0) {\n throw new CopilotKitMisuseError({\n message:\n \"Tool name must be a non-empty string for copilotkitEmitToolCall\",\n });\n }\n\n if (\n options?.toolCallId !== undefined &&\n (typeof options.toolCallId !== \"string\" ||\n options.toolCallId.trim().length === 0)\n ) {\n throw new CopilotKitMisuseError({\n message:\n \"Tool call id must be a non-empty string when provided for copilotkitEmitToolCall\",\n });\n }\n\n if (args === undefined) {\n throw new CopilotKitMisuseError({\n message: \"Tool arguments are required for copilotkitEmitToolCall\",\n });\n }\n\n try {\n JSON.stringify(args);\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Tool arguments for '${name}' are not JSON-serializable: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n\n const toolCallId = options?.toolCallId ?? randomUUID();\n\n try {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_tool_call\",\n { name, args, id: toolCallId },\n config,\n );\n } catch (error) {\n const wrapped = new Error(\n `copilotkitEmitToolCall dispatch failed for tool=\"${name}\" id=\"${toolCallId}\": ${error instanceof Error ? error.message : String(error)}`,\n );\n (wrapped as any).cause = error;\n throw wrapped;\n }\n\n return toolCallId;\n}\n\nexport function convertActionToDynamicStructuredTool(\n actionInput: any,\n): DynamicStructuredTool<any> {\n if (!actionInput) {\n throw new CopilotKitMisuseError({\n message: \"Action input is required but was not provided\",\n });\n }\n\n if (!actionInput.name || typeof actionInput.name !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must have a valid 'name' property of type string\",\n });\n }\n\n if (\n actionInput.description == undefined ||\n actionInput.description == null ||\n typeof actionInput.description !== \"string\"\n ) {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a valid 'description' property of type string`,\n });\n }\n\n if (!actionInput.parameters) {\n throw new CopilotKitMisuseError({\n message: `Action '${actionInput.name}' must have a 'parameters' property`,\n });\n }\n\n try {\n return new DynamicStructuredTool({\n name: actionInput.name,\n description: actionInput.description,\n schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),\n func: async () => {\n return \"\";\n },\n });\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n/**\n * Use this function to convert a list of actions you get from state\n * to a list of dynamic structured tools.\n *\n * ### Examples\n *\n * ```typescript\n * import { convertActionsToDynamicStructuredTools } from \"@copilotkit/sdk-js/langgraph\";\n *\n * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);\n * ```\n */\nexport function convertActionsToDynamicStructuredTools(\n /**\n * The list of actions to convert.\n */\n actions: any[],\n): DynamicStructuredTool<any>[] {\n if (!Array.isArray(actions)) {\n throw new CopilotKitMisuseError({\n message: \"Actions must be an array\",\n });\n }\n\n return actions.map((action, index) => {\n try {\n return convertActionToDynamicStructuredTool(\n action.type === \"function\" ? action.function : action,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n });\n}\n\nexport function copilotKitInterrupt({\n message,\n action,\n args,\n}: {\n message?: string;\n action?: string;\n args?: Record<string, any>;\n}) {\n if (!message && !action) {\n throw new CopilotKitMisuseError({\n message:\n \"Either message or action (and optional arguments) must be provided for copilotKitInterrupt\",\n });\n }\n\n if (action && typeof action !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Action must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (message && typeof message !== \"string\") {\n throw new CopilotKitMisuseError({\n message: \"Message must be a string when provided to copilotKitInterrupt\",\n });\n }\n\n if (args && typeof args !== \"object\") {\n throw new CopilotKitMisuseError({\n message: \"Args must be an object when provided to copilotKitInterrupt\",\n });\n }\n\n let interruptValues = null;\n let interruptMessage = null;\n let answer = null;\n\n try {\n if (message) {\n interruptValues = message;\n interruptMessage = new AIMessage({ content: message, id: randomId() });\n } else {\n const toolId = randomId();\n interruptMessage = new AIMessage({\n content: \"\",\n tool_calls: [{ id: toolId, name: action, args: args ?? {} }],\n });\n interruptValues = {\n action,\n args: args ?? {},\n };\n }\n\n const response = interrupt({\n __copilotkit_interrupt_value__: interruptValues,\n __copilotkit_messages__: [interruptMessage],\n });\n answer = response[response.length - 1].content;\n\n return {\n answer,\n messages: response,\n };\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,SAAgB,0BAId,YAYA,SACgB;AAChB,KAAI,cAAc,OAAO,eAAe,SACtC,OAAM,IAAI,sBAAsB,EAC9B,SAAS,kDACV,CAAC;AAGJ,KAAI,WAAW,OAAO,YAAY,SAChC,OAAM,IAAI,sBAAsB,EAC9B,SAAS,2CACV,CAAC;AAIJ,KAAI,SAAS,uBAAuB;AAClC,MAAI,CAAC,MAAM,QAAQ,QAAQ,sBAAsB,CAC/C,OAAM,IAAI,sBAAsB,EAC9B,SAAS,wDACV,CAAC;AAGJ,UAAQ,sBAAsB,SAAS,OAAO,UAAU;AACtD,OAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,OAAM,IAAI,sBAAsB,EAC9B,SAAS,yBAAyB,MAAM,sBACzC,CAAC;AAGJ,OAAI,CAAC,MAAM,YAAY,OAAO,MAAM,aAAa,SAC/C,OAAM,IAAI,sBAAsB,EAC9B,SAAS,yBAAyB,MAAM,iDACzC,CAAC;AAGJ,OAAI,CAAC,MAAM,QAAQ,OAAO,MAAM,SAAS,SACvC,OAAM,IAAI,sBAAsB,EAC9B,SAAS,yBAAyB,MAAM,6CACzC,CAAC;AAGJ,OAAI,MAAM,gBAAgB,OAAO,MAAM,iBAAiB,SACtD,OAAM,IAAI,sBAAsB,EAC9B,SAAS,yBAAyB,MAAM,gDACzC,CAAC;IAEJ;;AAGJ,KAAI;EACF,MAAM,WAAW,YAAY,YAAY,EAAE;AAE3C,MAAI,SAAS,SAAS;AACpB,YAAS,gC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