@copilotkit/sdk-js 1.9.2-next.10 → 1.9.2-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/langgraph.js CHANGED
@@ -45,284 +45,113 @@ var CopilotKitStateAnnotation = import_langgraph.Annotation.Root({
45
45
  ...import_langgraph.MessagesAnnotation.spec
46
46
  });
47
47
  function copilotkitCustomizeConfig(baseConfig, options) {
48
- if (baseConfig && typeof baseConfig !== "object") {
49
- throw new import_shared.CopilotKitMisuseError({
50
- message: "baseConfig must be an object or null/undefined"
51
- });
52
- }
53
- if (options && typeof options !== "object") {
54
- throw new import_shared.CopilotKitMisuseError({
55
- message: "options must be an object when provided"
56
- });
57
- }
58
- if (options == null ? void 0 : options.emitIntermediateState) {
59
- if (!Array.isArray(options.emitIntermediateState)) {
60
- throw new import_shared.CopilotKitMisuseError({
61
- message: "emitIntermediateState must be an array when provided"
62
- });
48
+ const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
49
+ if (options == null ? void 0 : options.emitAll) {
50
+ metadata["copilotkit:emit-tool-calls"] = true;
51
+ metadata["copilotkit:emit-messages"] = true;
52
+ } else {
53
+ if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
54
+ metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
63
55
  }
64
- options.emitIntermediateState.forEach((state, index) => {
65
- if (!state || typeof state !== "object") {
66
- throw new import_shared.CopilotKitMisuseError({
67
- message: `emitIntermediateState[${index}] must be an object`
68
- });
69
- }
70
- if (!state.stateKey || typeof state.stateKey !== "string") {
71
- throw new import_shared.CopilotKitMisuseError({
72
- message: `emitIntermediateState[${index}] must have a valid 'stateKey' string property`
73
- });
74
- }
75
- if (!state.tool || typeof state.tool !== "string") {
76
- throw new import_shared.CopilotKitMisuseError({
77
- message: `emitIntermediateState[${index}] must have a valid 'tool' string property`
78
- });
79
- }
80
- if (state.toolArgument && typeof state.toolArgument !== "string") {
81
- throw new import_shared.CopilotKitMisuseError({
82
- message: `emitIntermediateState[${index}].toolArgument must be a string when provided`
83
- });
84
- }
85
- });
86
- }
87
- try {
88
- const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
89
- if (options == null ? void 0 : options.emitAll) {
90
- metadata["copilotkit:emit-tool-calls"] = true;
91
- metadata["copilotkit:emit-messages"] = true;
92
- } else {
93
- if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
94
- metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
95
- }
96
- if ((options == null ? void 0 : options.emitMessages) !== void 0) {
97
- metadata["copilotkit:emit-messages"] = options.emitMessages;
98
- }
56
+ if ((options == null ? void 0 : options.emitMessages) !== void 0) {
57
+ metadata["copilotkit:emit-messages"] = options.emitMessages;
99
58
  }
100
- if (options == null ? void 0 : options.emitIntermediateState) {
101
- const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
102
- tool: state.tool,
103
- tool_argument: state.toolArgument,
104
- state_key: state.stateKey
105
- }));
106
- metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
107
- }
108
- baseConfig = baseConfig || {};
109
- return {
110
- ...baseConfig,
111
- metadata
112
- };
113
- } catch (error) {
114
- throw new import_shared.CopilotKitMisuseError({
115
- message: `Failed to customize config: ${error instanceof Error ? error.message : String(error)}`
116
- });
117
59
  }
60
+ if (options == null ? void 0 : options.emitIntermediateState) {
61
+ const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
62
+ tool: state.tool,
63
+ tool_argument: state.toolArgument,
64
+ state_key: state.stateKey
65
+ }));
66
+ metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
67
+ }
68
+ baseConfig = baseConfig || {};
69
+ return {
70
+ ...baseConfig,
71
+ metadata
72
+ };
118
73
  }
119
74
  __name(copilotkitCustomizeConfig, "copilotkitCustomizeConfig");
120
75
  async function copilotkitExit(config) {
121
- if (!config) {
122
- throw new import_shared.CopilotKitMisuseError({
123
- message: "LangGraph configuration is required for copilotkitExit"
124
- });
125
- }
126
- try {
127
- await (0, import_dispatch.dispatchCustomEvent)("copilotkit_exit", {}, config);
128
- } catch (error) {
129
- throw new import_shared.CopilotKitMisuseError({
130
- message: `Failed to dispatch exit event: ${error instanceof Error ? error.message : String(error)}`
131
- });
132
- }
76
+ await (0, import_dispatch.dispatchCustomEvent)("copilotkit_exit", {}, config);
133
77
  }
134
78
  __name(copilotkitExit, "copilotkitExit");
135
79
  async function copilotkitEmitState(config, state) {
136
- if (!config) {
137
- throw new import_shared.CopilotKitMisuseError({
138
- message: "LangGraph configuration is required for copilotkitEmitState"
139
- });
140
- }
141
- if (state === void 0) {
142
- throw new import_shared.CopilotKitMisuseError({
143
- message: "State is required for copilotkitEmitState"
144
- });
145
- }
146
- try {
147
- await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_intermediate_state", state, config);
148
- } catch (error) {
149
- throw new import_shared.CopilotKitMisuseError({
150
- message: `Failed to emit state: ${error instanceof Error ? error.message : String(error)}`
151
- });
152
- }
80
+ await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_intermediate_state", state, config);
153
81
  }
154
82
  __name(copilotkitEmitState, "copilotkitEmitState");
155
83
  async function copilotkitEmitMessage(config, message) {
156
- if (!config) {
157
- throw new import_shared.CopilotKitMisuseError({
158
- message: "LangGraph configuration is required for copilotkitEmitMessage"
159
- });
160
- }
161
- if (!message || typeof message !== "string") {
162
- throw new import_shared.CopilotKitMisuseError({
163
- message: "Message must be a non-empty string for copilotkitEmitMessage"
164
- });
165
- }
166
- try {
167
- await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_message", {
168
- message,
169
- message_id: (0, import_shared.randomId)(),
170
- role: "assistant"
171
- }, config);
172
- } catch (error) {
173
- throw new import_shared.CopilotKitMisuseError({
174
- message: `Failed to emit message: ${error instanceof Error ? error.message : String(error)}`
175
- });
176
- }
84
+ await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_message", {
85
+ message,
86
+ message_id: (0, import_shared.randomId)(),
87
+ role: "assistant"
88
+ }, config);
177
89
  }
178
90
  __name(copilotkitEmitMessage, "copilotkitEmitMessage");
179
91
  async function copilotkitEmitToolCall(config, name, args) {
180
- if (!config) {
181
- throw new import_shared.CopilotKitMisuseError({
182
- message: "LangGraph configuration is required for copilotkitEmitToolCall"
183
- });
184
- }
185
- if (!name || typeof name !== "string") {
186
- throw new import_shared.CopilotKitMisuseError({
187
- message: "Tool name must be a non-empty string for copilotkitEmitToolCall"
188
- });
189
- }
190
- if (args === void 0) {
191
- throw new import_shared.CopilotKitMisuseError({
192
- message: "Tool arguments are required for copilotkitEmitToolCall"
193
- });
194
- }
195
- try {
196
- await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_tool_call", {
197
- name,
198
- args,
199
- id: (0, import_shared.randomId)()
200
- }, config);
201
- } catch (error) {
202
- throw new import_shared.CopilotKitMisuseError({
203
- message: `Failed to emit tool call '${name}': ${error instanceof Error ? error.message : String(error)}`
204
- });
205
- }
92
+ await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_tool_call", {
93
+ name,
94
+ args,
95
+ id: (0, import_shared.randomId)()
96
+ }, config);
206
97
  }
207
98
  __name(copilotkitEmitToolCall, "copilotkitEmitToolCall");
208
99
  function convertActionToDynamicStructuredTool(actionInput) {
209
- if (!actionInput) {
210
- throw new import_shared.CopilotKitMisuseError({
211
- message: "Action input is required but was not provided"
212
- });
213
- }
214
- if (!actionInput.name || typeof actionInput.name !== "string") {
215
- throw new import_shared.CopilotKitMisuseError({
216
- message: "Action must have a valid 'name' property of type string"
217
- });
218
- }
219
- if (!actionInput.description || typeof actionInput.description !== "string") {
220
- throw new import_shared.CopilotKitMisuseError({
221
- message: `Action '${actionInput.name}' must have a valid 'description' property of type string`
222
- });
223
- }
224
- if (!actionInput.parameters) {
225
- throw new import_shared.CopilotKitMisuseError({
226
- message: `Action '${actionInput.name}' must have a 'parameters' property`
227
- });
228
- }
229
- try {
230
- return new import_tools.DynamicStructuredTool({
231
- name: actionInput.name,
232
- description: actionInput.description,
233
- schema: (0, import_shared.convertJsonSchemaToZodSchema)(actionInput.parameters, true),
234
- func: async () => {
235
- return "";
236
- }
237
- });
238
- } catch (error) {
239
- throw new import_shared.CopilotKitMisuseError({
240
- message: `Failed to convert action '${actionInput.name}' to DynamicStructuredTool: ${error instanceof Error ? error.message : String(error)}`
241
- });
242
- }
100
+ return new import_tools.DynamicStructuredTool({
101
+ name: actionInput.name,
102
+ description: actionInput.description,
103
+ schema: (0, import_shared.convertJsonSchemaToZodSchema)(actionInput.parameters, true),
104
+ func: async () => {
105
+ return "";
106
+ }
107
+ });
243
108
  }
244
109
  __name(convertActionToDynamicStructuredTool, "convertActionToDynamicStructuredTool");
245
110
  function convertActionsToDynamicStructuredTools(actions) {
246
- if (!Array.isArray(actions)) {
247
- throw new import_shared.CopilotKitMisuseError({
248
- message: "Actions must be an array"
249
- });
250
- }
251
- return actions.map((action, index) => {
252
- try {
253
- return convertActionToDynamicStructuredTool(action);
254
- } catch (error) {
255
- throw new import_shared.CopilotKitMisuseError({
256
- message: `Failed to convert action at index ${index}: ${error instanceof Error ? error.message : String(error)}`
257
- });
258
- }
259
- });
111
+ return actions.map((action) => convertActionToDynamicStructuredTool(action));
260
112
  }
261
113
  __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
262
114
  function copilotKitInterrupt({ message, action, args }) {
263
115
  if (!message && !action) {
264
- throw new import_shared.CopilotKitMisuseError({
265
- message: "Either message or action (and optional arguments) must be provided for copilotKitInterrupt"
266
- });
267
- }
268
- if (action && typeof action !== "string") {
269
- throw new import_shared.CopilotKitMisuseError({
270
- message: "Action must be a string when provided to copilotKitInterrupt"
271
- });
272
- }
273
- if (message && typeof message !== "string") {
274
- throw new import_shared.CopilotKitMisuseError({
275
- message: "Message must be a string when provided to copilotKitInterrupt"
276
- });
277
- }
278
- if (args && typeof args !== "object") {
279
- throw new import_shared.CopilotKitMisuseError({
280
- message: "Args must be an object when provided to copilotKitInterrupt"
281
- });
116
+ throw new Error("Either message or action (and optional arguments) must be provided");
282
117
  }
283
118
  let interruptValues = null;
284
119
  let interruptMessage = null;
285
120
  let answer = null;
286
- try {
287
- if (message) {
288
- interruptValues = message;
289
- interruptMessage = new import_messages.AIMessage({
290
- content: message,
291
- id: (0, import_shared.randomId)()
292
- });
293
- } else {
294
- const toolId = (0, import_shared.randomId)();
295
- interruptMessage = new import_messages.AIMessage({
296
- content: "",
297
- tool_calls: [
298
- {
299
- id: toolId,
300
- name: action,
301
- args: args ?? {}
302
- }
303
- ]
304
- });
305
- interruptValues = {
306
- action,
307
- args: args ?? {}
308
- };
309
- }
310
- const response = (0, import_langgraph.interrupt)({
311
- __copilotkit_interrupt_value__: interruptValues,
312
- __copilotkit_messages__: [
313
- interruptMessage
121
+ if (message) {
122
+ interruptValues = message;
123
+ interruptMessage = new import_messages.AIMessage({
124
+ content: message,
125
+ id: (0, import_shared.randomId)()
126
+ });
127
+ } else {
128
+ const toolId = (0, import_shared.randomId)();
129
+ interruptMessage = new import_messages.AIMessage({
130
+ content: "",
131
+ tool_calls: [
132
+ {
133
+ id: toolId,
134
+ name: action,
135
+ args: args ?? {}
136
+ }
314
137
  ]
315
138
  });
316
- answer = response[response.length - 1].content;
317
- return {
318
- answer,
319
- messages: response
139
+ interruptValues = {
140
+ action,
141
+ args: args ?? {}
320
142
  };
321
- } catch (error) {
322
- throw new import_shared.CopilotKitMisuseError({
323
- message: `Failed to create interrupt: ${error instanceof Error ? error.message : String(error)}`
324
- });
325
143
  }
144
+ const response = (0, import_langgraph.interrupt)({
145
+ __copilotkit_interrupt_value__: interruptValues,
146
+ __copilotkit_messages__: [
147
+ interruptMessage
148
+ ]
149
+ });
150
+ answer = response[response.length - 1].content;
151
+ return {
152
+ answer,
153
+ messages: response
154
+ };
326
155
  }
327
156
  __name(copilotKitInterrupt, "copilotKitInterrupt");
328
157
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/langgraph.ts"],"sourcesContent":["import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport { convertJsonSchemaToZodSchema, randomId, CopilotKitMisuseError } from \"@copilotkit/shared\";\nimport { Annotation, MessagesAnnotation, interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\n\ninterface IntermediateStateConfig {\n stateKey: string;\n tool: string;\n toolArgument?: string;\n}\n\ninterface OptionsConfig {\n emitToolCalls?: boolean | string | string[];\n emitMessages?: boolean;\n emitAll?: boolean;\n emitIntermediateState?: IntermediateStateConfig[];\n}\n\nexport const CopilotKitPropertiesAnnotation = Annotation.Root({\n actions: Annotation<any[]>,\n});\n\nexport const CopilotKitStateAnnotation = Annotation.Root({\n copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,\n ...MessagesAnnotation.spec,\n});\n\nexport type CopilotKitState = typeof CopilotKitStateAnnotation.State;\nexport type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;\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((state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }));\n\n metadata[\"copilotkit:emit-intermediate-state\"] = 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(\"copilotkit_manually_emit_intermediate_state\", state, config);\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: \"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(actionInput: any): 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 (!actionInput.description || typeof actionInput.description !== \"string\") {\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(action);\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":";;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;;;sBAAoC;AACpC,oBAA8E;AAC9E,uBAA0D;A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AX,KAAI,GAKL;AACC,MAAI,CAAChC,WAAW,CAAC2C,QAAQ;AACvB,UAAM,IAAI5C,oCAAsB;MAC9BC,SACE;IACJ,CAAA;EACF;AAEA,MAAI2C,UAAU,OAAOA,WAAW,UAAU;AACxC,UAAM,IAAI5C,oCAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAEA,MAAIA,WAAW,OAAOA,YAAY,UAAU;AAC1C,UAAM,IAAID,oCAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAEA,MAAIgC,QAAQ,OAAOA,SAAS,UAAU;AACpC,UAAM,IAAIjC,oCAAsB;MAC9BC,SAAS;IACX,CAAA;EACF;AAEA,MAAI6C,kBAAkB;AACtB,MAAIC,mBAAmB;AACvB,MAAIC,SAAS;AAEb,MAAI;AACF,QAAI/C,SAAS;AACX6C,wBAAkB7C;AAClB8C,yBAAmB,IAAIE,0BAAU;QAAEC,SAASjD;QAASiC,QAAIL,wBAAAA;MAAW,CAAA;IACtE,OAAO;AACL,YAAMsB,aAAStB,wBAAAA;AACfkB,yBAAmB,IAAIE,0BAAU;QAC/BC,SAAS;QACTE,YAAY;UAAC;YAAElB,IAAIiB;YAAQnB,MAAMY;YAAQX,MAAMA,QAAQ,CAAC;UAAE;;MAC5D,CAAA;AACAa,wBAAkB;QAChBF;QACAX,MAAMA,QAAQ,CAAC;MACjB;IACF;AAEA,UAAMoB,eAAWC,4BAAU;MACzBC,gCAAgCT;MAChCU,yBAAyB;QAACT;;IAC5B,CAAA;AACAC,aAASK,SAASA,SAASI,SAAS,CAAA,EAAGP;AAEvC,WAAO;MACLF;MACAU,UAAUL;IACZ;EACF,SAASjC,OAAP;AACA,UAAM,IAAIpB,oCAAsB;MAC9BC,SAAS,+BAA+BmB,iBAAiBC,QAAQD,MAAMnB,UAAUqB,OAAOF,KAAAA;IAC1F,CAAA;EACF;AACF;AArEgByB;","names":["CopilotKitPropertiesAnnotation","Annotation","Root","actions","CopilotKitStateAnnotation","copilotkit","MessagesAnnotation","spec","copilotkitCustomizeConfig","baseConfig","options","CopilotKitMisuseError","message","emitIntermediateState","Array","isArray","forEach","state","index","stateKey","tool","toolArgument","metadata","emitAll","emitToolCalls","undefined","emitMessages","snakeCaseIntermediateState","map","tool_argument","state_key","error","Error","String","copilotkitExit","config","dispatchCustomEvent","copilotkitEmitState","copilotkitEmitMessage","message_id","randomId","role","copilotkitEmitToolCall","name","args","id","convertActionToDynamicStructuredTool","actionInput","description","parameters","DynamicStructuredTool","schema","convertJsonSchemaToZodSchema","func","convertActionsToDynamicStructuredTools","action","copilotKitInterrupt","interruptValues","interruptMessage","answer","AIMessage","content","toolId","tool_calls","response","interrupt","__copilotkit_interrupt_value__","__copilotkit_messages__","length","messages"]}
1
+ {"version":3,"sources":["../src/langgraph.ts"],"sourcesContent":["import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport { convertJsonSchemaToZodSchema, randomId } from \"@copilotkit/shared\";\nimport { Annotation, MessagesAnnotation, interrupt } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\nimport { AIMessage } from \"@langchain/core/messages\";\n\ninterface IntermediateStateConfig {\n stateKey: string;\n tool: string;\n toolArgument?: string;\n}\n\ninterface OptionsConfig {\n emitToolCalls?: boolean | string | string[];\n emitMessages?: boolean;\n emitAll?: boolean;\n emitIntermediateState?: IntermediateStateConfig[];\n}\n\nexport const CopilotKitPropertiesAnnotation = Annotation.Root({\n actions: Annotation<any[]>,\n});\n\nexport const CopilotKitStateAnnotation = Annotation.Root({\n copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,\n ...MessagesAnnotation.spec,\n});\n\nexport type CopilotKitState = typeof CopilotKitStateAnnotation.State;\nexport type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;\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 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((state) => ({\n tool: state.tool,\n tool_argument: state.toolArgument,\n state_key: state.stateKey,\n }));\n\n metadata[\"copilotkit:emit-intermediate-state\"] = snakeCaseIntermediateState;\n }\n\n baseConfig = baseConfig || {};\n\n return {\n ...baseConfig,\n metadata: metadata,\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 await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\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 await dispatchCustomEvent(\"copilotkit_manually_emit_intermediate_state\", state, config);\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 await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\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 await dispatchCustomEvent(\n \"copilotkit_manually_emit_tool_call\",\n { name, args, id: randomId() },\n config,\n );\n}\n\nexport function convertActionToDynamicStructuredTool(actionInput: any): DynamicStructuredTool<any> {\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}\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 return actions.map((action) => convertActionToDynamicStructuredTool(action));\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 Error(\"Either message or action (and optional arguments) must be provided\");\n }\n\n let interruptValues = null;\n let interruptMessage = null;\n let answer = null;\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 mess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Root","actions","CopilotKitStateAnnotation","copilotkit","MessagesAnnotation","spec","copilotkitCustomizeConfig","baseConfig","options","metadata","emitAll","emitToolCalls","undefined","emitMessages","emitIntermediateState","snakeCaseIntermediateState","map","state","tool","tool_argument","toolArgument","state_key","stateKey","copilotkitExit","config","dispatchCustomEvent","copilotkitEmitState","copilotkitEmitMessage","message","message_id","randomId","role","copilotkitEmitToolCall","name","args","id","convertActionToDynamicStructuredTool","actionInput","DynamicStructuredTool","description","schema","convertJsonSchemaToZodSchema","parameters","func","convertActionsToDynamicStructuredTools","action","copilotKitInterrupt","Error","interruptValues","interruptMessage","answer","AIMessage","content","toolId","tool_calls","response","interrupt","__copilotkit_interrupt_value__","__copilotkit_messages__","length","messages"]}
@@ -9,7 +9,7 @@ import {
9
9
  copilotkitEmitState,
10
10
  copilotkitEmitToolCall,
11
11
  copilotkitExit
12
- } from "./chunk-Q5S2AURJ.mjs";
12
+ } from "./chunk-PMVIZ7R2.mjs";
13
13
  export {
14
14
  CopilotKitPropertiesAnnotation,
15
15
  CopilotKitStateAnnotation,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.9.2-next.10",
12
+ "version": "1.9.2-next.3",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -52,10 +52,10 @@
52
52
  "dependencies": {
53
53
  "@langchain/community": "^0.0.53",
54
54
  "@langchain/core": "^0.3.13",
55
- "@langchain/langgraph": "0.2.44",
55
+ "@langchain/langgraph": "^0.2.44",
56
56
  "langchain": "^0.3.3",
57
57
  "zod": "^3.23.3",
58
- "@copilotkit/shared": "1.9.2-next.10"
58
+ "@copilotkit/shared": "1.9.2-next.3"
59
59
  },
60
60
  "keywords": [
61
61
  "copilotkit",