@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
@@ -0,0 +1,192 @@
1
+ import { OptionsConfig } from "./types.mjs";
2
+ import { DynamicStructuredTool } from "@langchain/core/tools";
3
+ import { RunnableConfig } from "@langchain/core/runnables";
4
+
5
+ //#region src/langgraph/utils.d.ts
6
+ /**
7
+ * Customize the LangGraph configuration for use in CopilotKit.
8
+ *
9
+ * To the CopilotKit SDK, run:
10
+ *
11
+ * ```bash
12
+ * npm install @copilotkit/sdk-js
13
+ * ```
14
+ *
15
+ * ### Examples
16
+ *
17
+ * Disable emitting messages and tool calls:
18
+ *
19
+ * ```typescript
20
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
21
+ *
22
+ * config = copilotkitCustomizeConfig(
23
+ * config,
24
+ * emitMessages=false,
25
+ * emitToolCalls=false
26
+ * )
27
+ * ```
28
+ *
29
+ * To emit a tool call as streaming LangGraph state, pass the destination key in state,
30
+ * the tool name and optionally the tool argument. (If you don't pass the argument name,
31
+ * all arguments are emitted under the state key.)
32
+ *
33
+ * ```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
+ * )
46
+ * ```
47
+ */
48
+ declare function copilotkitCustomizeConfig(
49
+ /**
50
+ * The LangChain/LangGraph configuration to customize.
51
+ */
52
+ baseConfig: RunnableConfig,
53
+ /**
54
+ * Configuration options:
55
+ * - `emitMessages: boolean?`
56
+ * Configure how messages are emitted. By default, all messages are emitted. Pass false to
57
+ * disable emitting messages.
58
+ * - `emitToolCalls: boolean | string | string[]?`
59
+ * Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to
60
+ * disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.
61
+ * - `emitIntermediateState: IntermediateStateConfig[]?`
62
+ * Lets you emit tool calls as streaming LangGraph state.
63
+ */
64
+ options?: OptionsConfig): RunnableConfig;
65
+ /**
66
+ * Exits the current agent after the run completes. Calling copilotkit_exit() will
67
+ * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
68
+ * the run completes.
69
+ *
70
+ * ### Examples
71
+ *
72
+ * ```typescript
73
+ * import { copilotkitExit } from "@copilotkit/sdk-js";
74
+ *
75
+ * async function myNode(state: Any):
76
+ * await copilotkitExit(config)
77
+ * return state
78
+ * ```
79
+ */
80
+ declare function copilotkitExit(
81
+ /**
82
+ * The LangChain/LangGraph configuration.
83
+ */
84
+ config: RunnableConfig): Promise<void>;
85
+ /**
86
+ * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to
87
+ * update the user with the current state of the node.
88
+ *
89
+ * ### Examples
90
+ *
91
+ * ```typescript
92
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js";
93
+ *
94
+ * for (let i = 0; i < 10; i++) {
95
+ * await someLongRunningOperation(i);
96
+ * await copilotkitEmitState(config, { progress: i });
97
+ * }
98
+ * ```
99
+ */
100
+ declare function copilotkitEmitState(
101
+ /**
102
+ * The LangChain/LangGraph configuration.
103
+ */
104
+ config: RunnableConfig,
105
+ /**
106
+ * The state to emit.
107
+ */
108
+ state: any): Promise<void>;
109
+ /**
110
+ * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.
111
+ * Important: You still need to return the messages from the node.
112
+ *
113
+ * ### Examples
114
+ *
115
+ * ```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)]
124
+ * }
125
+ * ```
126
+ */
127
+ declare function copilotkitEmitMessage(
128
+ /**
129
+ * The LangChain/LangGraph configuration.
130
+ */
131
+ config: RunnableConfig,
132
+ /**
133
+ * The message to emit.
134
+ */
135
+ message: string): Promise<void>;
136
+ /**
137
+ * Manually emits a tool call to CopilotKit.
138
+ *
139
+ * ### Examples
140
+ *
141
+ * ```typescript
142
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
143
+ *
144
+ * await copilotkitEmitToolCall(config, name="SearchTool", args={"steps": 10})
145
+ * ```
146
+ */
147
+ declare function copilotkitEmitToolCall(
148
+ /**
149
+ * The LangChain/LangGraph configuration.
150
+ */
151
+ config: RunnableConfig,
152
+ /**
153
+ * The name of the tool to emit.
154
+ */
155
+ name: string,
156
+ /**
157
+ * The arguments to emit.
158
+ */
159
+ args: any): Promise<void>;
160
+ declare function convertActionToDynamicStructuredTool(actionInput: any): DynamicStructuredTool<any>;
161
+ /**
162
+ * Use this function to convert a list of actions you get from state
163
+ * to a list of dynamic structured tools.
164
+ *
165
+ * ### Examples
166
+ *
167
+ * ```typescript
168
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
169
+ *
170
+ * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
171
+ * ```
172
+ */
173
+ declare function convertActionsToDynamicStructuredTools(
174
+ /**
175
+ * The list of actions to convert.
176
+ */
177
+ actions: any[]): DynamicStructuredTool<any>[];
178
+ declare function copilotKitInterrupt({
179
+ message,
180
+ action,
181
+ args
182
+ }: {
183
+ message?: string;
184
+ action?: string;
185
+ args?: Record<string, any>;
186
+ }): {
187
+ answer: any;
188
+ messages: any;
189
+ };
190
+ //#endregion
191
+ export { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit };
192
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/langgraph/utils.ts"],"mappings":";;;;;;;AAsDA;;;;;;;;;;;;;;;AAwHA;;;;;;;;;AAmCA;;;;;;;;;;AAoDA;;;;;;iBA/MgB,yBAAA;;;;AAId,UAAA,EAAY,cAAA;;;;;;;;;;;AAsSd;AA1RE,OAAA,GAAU,aAAA,GACT,cAAA;;;;AAmVH;;;;;AAyBA;;;;;;;iBArQsB,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;;;;;;;;;;;;iBAqCK,sBAAA;;;;AAIpB,MAAA,EAAQ,cAAA;;;;AAIR,IAAA;;;;AAIA,IAAA,QAAS,OAAA;AAAA,iBAkCK,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"}
@@ -0,0 +1,273 @@
1
+ import { interrupt } from "@langchain/langgraph";
2
+ import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
3
+ import { CopilotKitMisuseError, convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
4
+ import { DynamicStructuredTool } from "@langchain/core/tools";
5
+ import { AIMessage } from "@langchain/core/messages";
6
+
7
+ //#region src/langgraph/utils.ts
8
+ /**
9
+ * Customize the LangGraph configuration for use in CopilotKit.
10
+ *
11
+ * To the CopilotKit SDK, run:
12
+ *
13
+ * ```bash
14
+ * npm install @copilotkit/sdk-js
15
+ * ```
16
+ *
17
+ * ### Examples
18
+ *
19
+ * Disable emitting messages and tool calls:
20
+ *
21
+ * ```typescript
22
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
23
+ *
24
+ * config = copilotkitCustomizeConfig(
25
+ * config,
26
+ * emitMessages=false,
27
+ * emitToolCalls=false
28
+ * )
29
+ * ```
30
+ *
31
+ * To emit a tool call as streaming LangGraph state, pass the destination key in state,
32
+ * the tool name and optionally the tool argument. (If you don't pass the argument name,
33
+ * all arguments are emitted under the state key.)
34
+ *
35
+ * ```typescript
36
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
37
+ *
38
+ * config = copilotkitCustomizeConfig(
39
+ * config,
40
+ * emitIntermediateState=[
41
+ * {
42
+ * "stateKey": "steps",
43
+ * "tool": "SearchTool",
44
+ * "toolArgument": "steps",
45
+ * },
46
+ * ],
47
+ * )
48
+ * ```
49
+ */
50
+ function copilotkitCustomizeConfig(baseConfig, options) {
51
+ if (baseConfig && typeof baseConfig !== "object") throw new CopilotKitMisuseError({ message: "baseConfig must be an object or null/undefined" });
52
+ if (options && typeof options !== "object") throw new CopilotKitMisuseError({ message: "options must be an object when provided" });
53
+ if (options?.emitIntermediateState) {
54
+ if (!Array.isArray(options.emitIntermediateState)) throw new CopilotKitMisuseError({ message: "emitIntermediateState must be an array when provided" });
55
+ options.emitIntermediateState.forEach((state, index) => {
56
+ if (!state || typeof state !== "object") throw new CopilotKitMisuseError({ message: `emitIntermediateState[${index}] must be an object` });
57
+ if (!state.stateKey || typeof state.stateKey !== "string") throw new CopilotKitMisuseError({ message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property` });
58
+ if (!state.tool || typeof state.tool !== "string") throw new CopilotKitMisuseError({ message: `emitIntermediateState[${index}] must have a valid 'tool' string property` });
59
+ if (state.toolArgument && typeof state.toolArgument !== "string") throw new CopilotKitMisuseError({ message: `emitIntermediateState[${index}].toolArgument must be a string when provided` });
60
+ });
61
+ }
62
+ try {
63
+ const metadata = baseConfig?.metadata || {};
64
+ if (options?.emitAll) {
65
+ metadata["copilotkit:emit-tool-calls"] = true;
66
+ metadata["copilotkit:emit-messages"] = true;
67
+ } else {
68
+ if (options?.emitToolCalls !== void 0) metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
69
+ if (options?.emitMessages !== void 0) metadata["copilotkit:emit-messages"] = options.emitMessages;
70
+ }
71
+ if (options?.emitIntermediateState) metadata["copilotkit:emit-intermediate-state"] = options.emitIntermediateState.map((state) => ({
72
+ tool: state.tool,
73
+ tool_argument: state.toolArgument,
74
+ state_key: state.stateKey
75
+ }));
76
+ baseConfig = baseConfig || {};
77
+ return {
78
+ ...baseConfig,
79
+ metadata
80
+ };
81
+ } catch (error) {
82
+ throw new CopilotKitMisuseError({ message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}` });
83
+ }
84
+ }
85
+ /**
86
+ * Exits the current agent after the run completes. Calling copilotkit_exit() will
87
+ * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
88
+ * the run completes.
89
+ *
90
+ * ### Examples
91
+ *
92
+ * ```typescript
93
+ * import { copilotkitExit } from "@copilotkit/sdk-js";
94
+ *
95
+ * async function myNode(state: Any):
96
+ * await copilotkitExit(config)
97
+ * return state
98
+ * ```
99
+ */
100
+ async function copilotkitExit(config) {
101
+ if (!config) throw new CopilotKitMisuseError({ message: "LangGraph configuration is required for copilotkitExit" });
102
+ try {
103
+ await dispatchCustomEvent("copilotkit_exit", {}, config);
104
+ } catch (error) {
105
+ throw new CopilotKitMisuseError({ message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}` });
106
+ }
107
+ }
108
+ /**
109
+ * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to
110
+ * update the user with the current state of the node.
111
+ *
112
+ * ### Examples
113
+ *
114
+ * ```typescript
115
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js";
116
+ *
117
+ * for (let i = 0; i < 10; i++) {
118
+ * await someLongRunningOperation(i);
119
+ * await copilotkitEmitState(config, { progress: i });
120
+ * }
121
+ * ```
122
+ */
123
+ async function copilotkitEmitState(config, state) {
124
+ if (!config) throw new CopilotKitMisuseError({ message: "LangGraph configuration is required for copilotkitEmitState" });
125
+ if (state === void 0) throw new CopilotKitMisuseError({ message: "State is required for copilotkitEmitState" });
126
+ try {
127
+ await dispatchCustomEvent("copilotkit_manually_emit_intermediate_state", state, config);
128
+ } catch (error) {
129
+ throw new CopilotKitMisuseError({ message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}` });
130
+ }
131
+ }
132
+ /**
133
+ * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.
134
+ * Important: You still need to return the messages from the node.
135
+ *
136
+ * ### Examples
137
+ *
138
+ * ```typescript
139
+ * import { copilotkitEmitMessage } from "@copilotkit/sdk-js";
140
+ *
141
+ * const message = "Step 1 of 10 complete";
142
+ * await copilotkitEmitMessage(config, message);
143
+ *
144
+ * // Return the message from the node
145
+ * return {
146
+ * "messages": [AIMessage(content=message)]
147
+ * }
148
+ * ```
149
+ */
150
+ async function copilotkitEmitMessage(config, message) {
151
+ if (!config) throw new CopilotKitMisuseError({ message: "LangGraph configuration is required for copilotkitEmitMessage" });
152
+ if (!message || typeof message !== "string") throw new CopilotKitMisuseError({ message: "Message must be a non-empty string for copilotkitEmitMessage" });
153
+ try {
154
+ await dispatchCustomEvent("copilotkit_manually_emit_message", {
155
+ message,
156
+ message_id: randomId(),
157
+ role: "assistant"
158
+ }, config);
159
+ } catch (error) {
160
+ throw new CopilotKitMisuseError({ message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}` });
161
+ }
162
+ }
163
+ /**
164
+ * Manually emits a tool call to CopilotKit.
165
+ *
166
+ * ### Examples
167
+ *
168
+ * ```typescript
169
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
170
+ *
171
+ * await copilotkitEmitToolCall(config, name="SearchTool", args={"steps": 10})
172
+ * ```
173
+ */
174
+ async function copilotkitEmitToolCall(config, name, args) {
175
+ if (!config) throw new CopilotKitMisuseError({ message: "LangGraph configuration is required for copilotkitEmitToolCall" });
176
+ if (!name || typeof name !== "string") throw new CopilotKitMisuseError({ message: "Tool name must be a non-empty string for copilotkitEmitToolCall" });
177
+ if (args === void 0) throw new CopilotKitMisuseError({ message: "Tool arguments are required for copilotkitEmitToolCall" });
178
+ try {
179
+ await dispatchCustomEvent("copilotkit_manually_emit_tool_call", {
180
+ name,
181
+ args,
182
+ id: randomId()
183
+ }, config);
184
+ } catch (error) {
185
+ throw new CopilotKitMisuseError({ message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}` });
186
+ }
187
+ }
188
+ function convertActionToDynamicStructuredTool(actionInput) {
189
+ if (!actionInput) throw new CopilotKitMisuseError({ message: "Action input is required but was not provided" });
190
+ if (!actionInput.name || typeof actionInput.name !== "string") throw new CopilotKitMisuseError({ message: "Action must have a valid 'name' property of type string" });
191
+ if (actionInput.description == void 0 || actionInput.description == null || typeof actionInput.description !== "string") throw new CopilotKitMisuseError({ message: `Action '${actionInput.name}' must have a valid 'description' property of type string` });
192
+ if (!actionInput.parameters) throw new CopilotKitMisuseError({ message: `Action '${actionInput.name}' must have a 'parameters' property` });
193
+ try {
194
+ return new DynamicStructuredTool({
195
+ name: actionInput.name,
196
+ description: actionInput.description,
197
+ schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),
198
+ func: async () => {
199
+ return "";
200
+ }
201
+ });
202
+ } catch (error) {
203
+ throw new CopilotKitMisuseError({ message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}` });
204
+ }
205
+ }
206
+ /**
207
+ * Use this function to convert a list of actions you get from state
208
+ * to a list of dynamic structured tools.
209
+ *
210
+ * ### Examples
211
+ *
212
+ * ```typescript
213
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
214
+ *
215
+ * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
216
+ * ```
217
+ */
218
+ function convertActionsToDynamicStructuredTools(actions) {
219
+ if (!Array.isArray(actions)) throw new CopilotKitMisuseError({ message: "Actions must be an array" });
220
+ return actions.map((action, index) => {
221
+ try {
222
+ return convertActionToDynamicStructuredTool(action.type === "function" ? action.function : action);
223
+ } catch (error) {
224
+ throw new CopilotKitMisuseError({ message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}` });
225
+ }
226
+ });
227
+ }
228
+ function copilotKitInterrupt({ message, action, args }) {
229
+ if (!message && !action) throw new CopilotKitMisuseError({ message: "Either message or action (and optional arguments) must be provided for copilotKitInterrupt" });
230
+ if (action && typeof action !== "string") throw new CopilotKitMisuseError({ message: "Action must be a string when provided to copilotKitInterrupt" });
231
+ if (message && typeof message !== "string") throw new CopilotKitMisuseError({ message: "Message must be a string when provided to copilotKitInterrupt" });
232
+ if (args && typeof args !== "object") throw new CopilotKitMisuseError({ message: "Args must be an object when provided to copilotKitInterrupt" });
233
+ let interruptValues = null;
234
+ let interruptMessage = null;
235
+ let answer = null;
236
+ try {
237
+ if (message) {
238
+ interruptValues = message;
239
+ interruptMessage = new AIMessage({
240
+ content: message,
241
+ id: randomId()
242
+ });
243
+ } else {
244
+ interruptMessage = new AIMessage({
245
+ content: "",
246
+ tool_calls: [{
247
+ id: randomId(),
248
+ name: action,
249
+ args: args ?? {}
250
+ }]
251
+ });
252
+ interruptValues = {
253
+ action,
254
+ args: args ?? {}
255
+ };
256
+ }
257
+ const response = interrupt({
258
+ __copilotkit_interrupt_value__: interruptValues,
259
+ __copilotkit_messages__: [interruptMessage]
260
+ });
261
+ answer = response[response.length - 1].content;
262
+ return {
263
+ answer,
264
+ messages: response
265
+ };
266
+ } catch (error) {
267
+ throw new CopilotKitMisuseError({ message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}` });
268
+ }
269
+ }
270
+
271
+ //#endregion
272
+ export { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit };
273
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/langgraph/utils.ts"],"sourcesContent":["import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport {\n convertJsonSchemaToZodSchema,\n randomId,\n CopilotKitMisuseError,\n} from \"@copilotkit/shared\";\nimport { interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\nimport { 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 * await copilotkitEmitToolCall(config, name=\"SearchTool\", args={\"steps\": 10})\n * ```\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 if (!config) {\n throw new CopilotKitMisuseError({\n message: \"LangGraph configuration is required for copilotkitEmitToolCall\",\n });\n }\n\n if (!name || typeof name !== \"string\") {\n throw new CopilotKitMisuseError({\n message:\n \"Tool name must be a non-empty string 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 await dispatchCustomEvent(\n \"copilotkit_manually_emit_tool_call\",\n { name, args, id: randomId() },\n config,\n );\n } catch (error) {\n throw new CopilotKitMisuseError({\n message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}`,\n });\n }\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 : String(error)}`,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,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,gCAAgC;AACzC,YAAS,8BAA8B;SAClC;AACL,OAAI,SAAS,kBAAkB,OAC7B,UAAS,gCAAgC,QAAQ;AAEnD,OAAI,SAAS,iBAAiB,OAC5B,UAAS,8BAA8B,QAAQ;;AAInD,MAAI,SAA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AgC;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"}
@@ -0,0 +1,16 @@
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
+ const require_middleware = require('./langgraph/middleware.cjs');
5
+
6
+ exports.CopilotKitPropertiesAnnotation = require_types.CopilotKitPropertiesAnnotation;
7
+ exports.CopilotKitStateAnnotation = require_types.CopilotKitStateAnnotation;
8
+ exports.convertActionToDynamicStructuredTool = require_utils.convertActionToDynamicStructuredTool;
9
+ exports.convertActionsToDynamicStructuredTools = require_utils.convertActionsToDynamicStructuredTools;
10
+ exports.copilotKitInterrupt = require_utils.copilotKitInterrupt;
11
+ exports.copilotkitCustomizeConfig = require_utils.copilotkitCustomizeConfig;
12
+ exports.copilotkitEmitMessage = require_utils.copilotkitEmitMessage;
13
+ exports.copilotkitEmitState = require_utils.copilotkitEmitState;
14
+ exports.copilotkitEmitToolCall = require_utils.copilotkitEmitToolCall;
15
+ exports.copilotkitExit = require_utils.copilotkitExit;
16
+ exports.copilotkitMiddleware = require_middleware.copilotkitMiddleware;
@@ -0,0 +1,4 @@
1
+ import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig } from "./langgraph/types.cjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.cjs";
3
+ import { copilotkitMiddleware } from "./langgraph/middleware.cjs";
4
+ export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware };
@@ -0,0 +1,4 @@
1
+ import { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig } from "./langgraph/types.mjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
3
+ import { copilotkitMiddleware } from "./langgraph/middleware.mjs";
4
+ export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, IntermediateStateConfig, OptionsConfig, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware };
@@ -1,27 +1,5 @@
1
- import {
2
- CopilotKitPropertiesAnnotation,
3
- CopilotKitStateAnnotation,
4
- convertActionToDynamicStructuredTool,
5
- convertActionsToDynamicStructuredTools,
6
- copilotKitInterrupt,
7
- copilotkitCustomizeConfig,
8
- copilotkitEmitMessage,
9
- copilotkitEmitState,
10
- copilotkitEmitToolCall,
11
- copilotkitExit,
12
- copilotkitMiddleware
13
- } from "./chunk-A7ZQHBQI.mjs";
14
- export {
15
- CopilotKitPropertiesAnnotation,
16
- CopilotKitStateAnnotation,
17
- convertActionToDynamicStructuredTool,
18
- convertActionsToDynamicStructuredTools,
19
- copilotKitInterrupt,
20
- copilotkitCustomizeConfig,
21
- copilotkitEmitMessage,
22
- copilotkitEmitState,
23
- copilotkitEmitToolCall,
24
- copilotkitExit,
25
- copilotkitMiddleware
26
- };
27
- //# sourceMappingURL=langgraph.mjs.map
1
+ import { CopilotKitPropertiesAnnotation, CopilotKitStateAnnotation } from "./langgraph/types.mjs";
2
+ import { convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit } from "./langgraph/utils.mjs";
3
+ import { copilotkitMiddleware } from "./langgraph/middleware.mjs";
4
+
5
+ export { CopilotKitPropertiesAnnotation, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit, copilotkitMiddleware };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@copilotkit/sdk-js",
3
3
  "private": false,
4
+ "type": "module",
4
5
  "homepage": "https://github.com/CopilotKit/CopilotKit",
5
6
  "repository": {
6
7
  "type": "git",
@@ -9,47 +10,43 @@
9
10
  "publishConfig": {
10
11
  "access": "public"
11
12
  },
12
- "version": "1.51.5-next.0",
13
+ "version": "1.51.5-next.1",
13
14
  "sideEffects": false,
14
- "main": "./dist/index.js",
15
+ "main": "./dist/index.cjs",
15
16
  "module": "./dist/index.mjs",
16
17
  "exports": {
17
18
  ".": {
18
- "types": "./dist/index.d.ts",
19
- "require": "./dist/index.js",
20
- "import": "./dist/index.mjs"
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.cjs"
21
21
  },
22
22
  "./langchain": {
23
- "types": "./dist/langchain.d.ts",
24
- "require": "./dist/langchain.js",
25
- "import": "./dist/langchain.mjs"
23
+ "import": "./dist/langchain.mjs",
24
+ "require": "./dist/langchain.cjs"
26
25
  },
27
26
  "./langgraph": {
28
- "types": "./dist/langgraph.d.ts",
29
- "require": "./dist/langgraph.js",
30
- "import": "./dist/langgraph.mjs"
31
- }
27
+ "import": "./dist/langgraph.mjs",
28
+ "require": "./dist/langgraph.cjs"
29
+ },
30
+ "./package.json": "./package.json"
32
31
  },
33
- "types": "./dist/index.d.ts",
32
+ "types": "./dist/index.d.cts",
34
33
  "license": "MIT",
35
34
  "dependencies": {
36
- "@copilotkit/shared": "1.51.5-next.0"
35
+ "@copilotkit/shared": "1.51.5-next.1"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@langchain/core": "^1.1.8",
40
39
  "@langchain/langgraph": "^1.0.7",
41
40
  "@swc/core": "1.5.28",
42
41
  "@types/express": "^4.17.21",
43
- "@types/jest": "^29.5.4",
44
42
  "@types/node": "^18.11.17",
45
43
  "@whatwg-node/server": "^0.9.34",
46
44
  "eslint": "^8.56.0",
47
- "jest": "^29.6.4",
48
45
  "langchain": "^1.2.3",
49
46
  "nodemon": "^3.1.3",
50
- "ts-jest": "^29.1.1",
51
47
  "ts-node": "^10.9.2",
52
- "tsup": "^6.7.0",
48
+ "vitest": "^3.2.4",
49
+ "tsdown": "^0.20.3",
53
50
  "typescript": "^5.2.3",
54
51
  "eslint-config-custom": "1.4.8",
55
52
  "tsconfig": "1.4.8"
@@ -75,11 +72,14 @@
75
72
  "textarea"
76
73
  ],
77
74
  "scripts": {
78
- "build": "tsup --clean",
79
- "dev": "tsup --watch --no-splitting",
80
- "test": "jest --passWithNoTests",
75
+ "build": "tsdown",
76
+ "dev": "tsdown --watch",
77
+ "test": "vitest run",
78
+ "test:watch": "vitest",
81
79
  "check-types": "tsc --noEmit",
82
80
  "link:global": "pnpm link --global",
83
- "unlink:global": "pnpm unlink --global"
81
+ "unlink:global": "pnpm unlink --global",
82
+ "publint": "publint .",
83
+ "attw": "attw --pack . --profile node16"
84
84
  }
85
85
  }