@copilotkit/sdk-js 1.5.15-next.7 → 1.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @copilotkit/sdk-js
2
2
 
3
+ ## 1.5.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 06f9f35: - feat(interrupt): add copilotkit interrupt as messages with copilotkit interrupt convenience fn
8
+ - chore(deps): update dependencies for demos
9
+ - chore(interrupt-as-message): add e2e test for interrupt as message
10
+ - Updated dependencies [7b3141d]
11
+ - @copilotkit/shared@1.5.15
12
+
13
+ ## 1.5.15-next.8
14
+
15
+ ### Patch Changes
16
+
17
+ - 06f9f35: - feat(interrupt): add copilotkit interrupt as messages with copilotkit interrupt convenience fn
18
+ - chore(deps): update dependencies for demos
19
+ - chore(interrupt-as-message): add e2e test for interrupt as message
20
+ - @copilotkit/shared@1.5.15-next.8
21
+
3
22
  ## 1.5.15-next.7
4
23
 
5
24
  ### Patch Changes
@@ -4,8 +4,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  // src/langgraph.ts
5
5
  import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
6
6
  import { convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
7
- import { Annotation, MessagesAnnotation } from "@langchain/langgraph";
7
+ import { Annotation, MessagesAnnotation, interrupt } from "@langchain/langgraph";
8
8
  import { DynamicStructuredTool } from "@langchain/core/tools";
9
+ import { AIMessage } from "@langchain/core/messages";
9
10
  var CopilotKitPropertiesAnnotation = Annotation.Root({
10
11
  actions: Annotation
11
12
  });
@@ -80,6 +81,52 @@ function convertActionsToDynamicStructuredTools(actions) {
80
81
  return actions.map((action) => convertActionToDynamicStructuredTool(action));
81
82
  }
82
83
  __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
84
+ function copilotKitInterrupt({ message, action, args }) {
85
+ if (!message && !action) {
86
+ throw new Error("Either message or action (and optional arguments) must be provided");
87
+ }
88
+ let interruptValues = null;
89
+ let interruptMessage = null;
90
+ let answer = null;
91
+ if (message) {
92
+ interruptValues = message;
93
+ interruptMessage = new AIMessage({
94
+ content: message,
95
+ id: randomId()
96
+ });
97
+ } else {
98
+ const toolId = randomId();
99
+ interruptMessage = new AIMessage({
100
+ content: "",
101
+ tool_calls: [
102
+ {
103
+ id: toolId,
104
+ name: action,
105
+ args: args ?? {}
106
+ }
107
+ ]
108
+ });
109
+ interruptValues = {
110
+ action,
111
+ args: args ?? {}
112
+ };
113
+ }
114
+ const response = interrupt({
115
+ __copilotkit_interrupt_value__: interruptValues,
116
+ __copilotkit_messages__: [
117
+ interruptMessage
118
+ ]
119
+ });
120
+ answer = response.content;
121
+ return {
122
+ answer,
123
+ messages: [
124
+ interruptMessage,
125
+ response
126
+ ]
127
+ };
128
+ }
129
+ __name(copilotKitInterrupt, "copilotKitInterrupt");
83
130
 
84
131
  export {
85
132
  CopilotKitPropertiesAnnotation,
@@ -90,6 +137,7 @@ export {
90
137
  copilotkitEmitMessage,
91
138
  copilotkitEmitToolCall,
92
139
  convertActionToDynamicStructuredTool,
93
- convertActionsToDynamicStructuredTools
140
+ convertActionsToDynamicStructuredTools,
141
+ copilotKitInterrupt
94
142
  };
95
- //# sourceMappingURL=chunk-HGYWIU6Y.mjs.map
143
+ //# sourceMappingURL=chunk-H76O4R7D.mjs.map
@@ -0,0 +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 } 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) {\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) {\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.content;\n\n return {\n answer,\n messages: [interruptMessage, response],\n };\n}\n"],"mappings":"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","names":["dispatchCustomEvent","convertJsonSchemaToZodSchema","randomId","Annotation","MessagesAnnotation","interrupt","DynamicStructuredTool","AIMessage","CopilotKitPropertiesAnnotation","Annotation","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__","messages"]}
package/dist/langchain.js CHANGED
@@ -37,6 +37,7 @@ var import_dispatch = require("@langchain/core/callbacks/dispatch");
37
37
  var import_shared = require("@copilotkit/shared");
38
38
  var import_langgraph = require("@langchain/langgraph");
39
39
  var import_tools = require("@langchain/core/tools");
40
+ var import_messages = require("@langchain/core/messages");
40
41
  var CopilotKitPropertiesAnnotation = import_langgraph.Annotation.Root({
41
42
  actions: import_langgraph.Annotation
42
43
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/langchain.ts","../src/langgraph.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n","import { RunnableConfig } from \"@langchain/core/runnables\";\nimport { dispatchCustomEvent } from \"@langchain/core/callbacks/dispatch\";\nimport { convertJsonSchemaToZodSchema, randomId } from \"@copilotkit/shared\";\nimport { Annotation, MessagesAnnotation } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\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) {\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) {\n return actions.map((action) => convertActionToDynamicStructuredTool(action));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAAA;;;;;;;;;;;;;;;ACCA,sBAAoC;AACpC,oBAAuD;AACvD,uBAA+C;AAC/C,mBAAsC;AAe/B,IAAMC,iCAAiCC,4BAAWC,KAAK;EAC5DC,SAASF;AACX,CAAA;AAEO,IAAMG,4BAA4BH,4BAAWC,KAAK;EACvDG,YAAYJ;EACZ,GAAGK,oCAAmBC;AACxB,CAAA;AA+CO,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,QAAMC,YAAWF,yCAAYE,aAAY,CAAC;AAE1C,MAAID,mCAASE,SAAS;AACpBD,aAAS,4BAAA,IAAgC;AACzCA,aAAS,0BAAA,IAA8B;EACzC,OAAO;AACL,SAAID,mCAASG,mBAAkBC,QAAW;AACxCH,eAAS,4BAAA,IAAgCD,QAAQG;IACnD;AACA,SAAIH,mCAASK,kBAAiBD,QAAW;AACvCH,eAAS,0BAAA,IAA8BD,QAAQK;IACjD;EACF;AAEA,MAAIL,mCAASM,uBAAuB;AAClC,UAAMC,6BAA6BP,QAAQM,sBAAsBE,IAAI,CAACC,WAAW;MAC/EC,MAAMD,MAAMC;MACZC,eAAeF,MAAMG;MACrBC,WAAWJ,MAAMK;IACnB,EAAA;AAEAb,aAAS,oCAAA,IAAwCM;EACnD;AAEAR,eAAaA,cAAc,CAAC;AAE5B,SAAO;IACL,GAAGA;IACHE;EACF;AACF;AAhDgBH;AAgEhB,eAAsBiB,eAIpBC,QAAsB;AAEtB,YAAMC,qCAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAPsBD;AAuBtB,eAAsBG,oBAIpBF,QAIAP,OAAU;AAEV,YAAMQ,qCAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAXsBE;AA8BtB,eAAsBC,sBAIpBH,QAIAI,SAAe;AAEf,YAAMH,qCACJ,oCACA;IAAEG;IAASC,gBAAYC,wBAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AAfsBG;AA2BtB,eAAsBK,uBAIpBR,QAIAS,MAIAC,MAAS;AAET,YAAMT,qCACJ,sCACA;IAAEQ;IAAMC;IAAMC,QAAIL,wBAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AAnBsBQ;AAqBf,SAASI,qCAAqCC,aAAgB;AACnE,SAAO,IAAIC,mCAAsB;IAC/BL,MAAMI,YAAYJ;IAClBM,aAAaF,YAAYE;IACzBC,YAAQC,4CAA6BJ,YAAYK,YAAY,IAAA;IAC7DC,MAAM,YAAA;AACJ,aAAO;IACT;EACF,CAAA;AACF;AATgBP;AAsBT,SAASQ,uCAId3C,SAAc;AAEd,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAPgBD;;;ADpQhBE,QAAQC,KACN,mJAAA;","names":["console","CopilotKitPropertiesAnnotation","Annotation","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","console","warn"]}
1
+ {"version":3,"sources":["../src/langchain.ts","../src/langgraph.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n","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) {\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) {\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.content;\n\n return {\n answer,\n messages: [interruptMessage, response],\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAAA;;;;;;;;;;;;;;;ACCA,sBAAoC;AACpC,oBAAuD;AACvD,uBAA0D;AAC1D,mBAAsC;AACtC,sBAA0B;AAenB,IAAMC,iCAAiCC,4BAAWC,KAAK;EAC5DC,SAASF;AACX,CAAA;AAEO,IAAMG,4BAA4BH,4BAAWC,KAAK;EACvDG,YAAYJ;EACZ,GAAGK,oCAAmBC;AACxB,CAAA;AA+CO,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,QAAMC,YAAWF,yCAAYE,aAAY,CAAC;AAE1C,MAAID,mCAASE,SAAS;AACpBD,aAAS,4BAAA,IAAgC;AACzCA,aAAS,0BAAA,IAA8B;EACzC,OAAO;AACL,SAAID,mCAASG,mBAAkBC,QAAW;AACxCH,eAAS,4BAAA,IAAgCD,QAAQG;IACnD;AACA,SAAIH,mCAASK,kBAAiBD,QAAW;AACvCH,eAAS,0BAAA,IAA8BD,QAAQK;IACjD;EACF;AAEA,MAAIL,mCAASM,uBAAuB;AAClC,UAAMC,6BAA6BP,QAAQM,sBAAsBE,IAAI,CAACC,WAAW;MAC/EC,MAAMD,MAAMC;MACZC,eAAeF,MAAMG;MACrBC,WAAWJ,MAAMK;IACnB,EAAA;AAEAb,aAAS,oCAAA,IAAwCM;EACnD;AAEAR,eAAaA,cAAc,CAAC;AAE5B,SAAO;IACL,GAAGA;IACHE;EACF;AACF;AAhDgBH;AAgEhB,eAAsBiB,eAIpBC,QAAsB;AAEtB,YAAMC,qCAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAPsBD;AAuBtB,eAAsBG,oBAIpBF,QAIAP,OAAU;AAEV,YAAMQ,qCAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAXsBE;AA8BtB,eAAsBC,sBAIpBH,QAIAI,SAAe;AAEf,YAAMH,qCACJ,oCACA;IAAEG;IAASC,gBAAYC,wBAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AAfsBG;AA2BtB,eAAsBK,uBAIpBR,QAIAS,MAIAC,MAAS;AAET,YAAMT,qCACJ,sCACA;IAAEQ;IAAMC;IAAMC,QAAIL,wBAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AAnBsBQ;AAqBf,SAASI,qCAAqCC,aAAgB;AACnE,SAAO,IAAIC,mCAAsB;IAC/BL,MAAMI,YAAYJ;IAClBM,aAAaF,YAAYE;IACzBC,YAAQC,4CAA6BJ,YAAYK,YAAY,IAAA;IAC7DC,MAAM,YAAA;AACJ,aAAO;IACT;EACF,CAAA;AACF;AATgBP;AAsBT,SAASQ,uCAId3C,SAAc;AAEd,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAPgBD;;;ADrQhBE,QAAQC,KACN,mJAAA;","names":["console","CopilotKitPropertiesAnnotation","Annotation","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","console","warn"]}
@@ -8,7 +8,7 @@ import {
8
8
  copilotkitEmitState,
9
9
  copilotkitEmitToolCall,
10
10
  copilotkitExit
11
- } from "./chunk-HGYWIU6Y.mjs";
11
+ } from "./chunk-H76O4R7D.mjs";
12
12
 
13
13
  // src/langchain.ts
14
14
  console.warn("Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.");
@@ -234,5 +234,13 @@ declare function convertActionsToDynamicStructuredTools(
234
234
  * The list of actions to convert.
235
235
  */
236
236
  actions: any[]): DynamicStructuredTool<zod.ZodType<any, zod.ZodTypeDef, any>>[];
237
+ declare function copilotKitInterrupt({ message, action, args, }: {
238
+ message?: string;
239
+ action?: string;
240
+ args?: Record<string, any>;
241
+ }): {
242
+ answer: any;
243
+ messages: any[];
244
+ };
237
245
 
238
- export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit };
246
+ export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitInterrupt, copilotkitCustomizeConfig, copilotkitEmitMessage, copilotkitEmitState, copilotkitEmitToolCall, copilotkitExit };
package/dist/langgraph.js CHANGED
@@ -24,6 +24,7 @@ __export(langgraph_exports, {
24
24
  CopilotKitStateAnnotation: () => CopilotKitStateAnnotation,
25
25
  convertActionToDynamicStructuredTool: () => convertActionToDynamicStructuredTool,
26
26
  convertActionsToDynamicStructuredTools: () => convertActionsToDynamicStructuredTools,
27
+ copilotKitInterrupt: () => copilotKitInterrupt,
27
28
  copilotkitCustomizeConfig: () => copilotkitCustomizeConfig,
28
29
  copilotkitEmitMessage: () => copilotkitEmitMessage,
29
30
  copilotkitEmitState: () => copilotkitEmitState,
@@ -35,6 +36,7 @@ var import_dispatch = require("@langchain/core/callbacks/dispatch");
35
36
  var import_shared = require("@copilotkit/shared");
36
37
  var import_langgraph = require("@langchain/langgraph");
37
38
  var import_tools = require("@langchain/core/tools");
39
+ var import_messages = require("@langchain/core/messages");
38
40
  var CopilotKitPropertiesAnnotation = import_langgraph.Annotation.Root({
39
41
  actions: import_langgraph.Annotation
40
42
  });
@@ -109,12 +111,59 @@ function convertActionsToDynamicStructuredTools(actions) {
109
111
  return actions.map((action) => convertActionToDynamicStructuredTool(action));
110
112
  }
111
113
  __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
114
+ function copilotKitInterrupt({ message, action, args }) {
115
+ if (!message && !action) {
116
+ throw new Error("Either message or action (and optional arguments) must be provided");
117
+ }
118
+ let interruptValues = null;
119
+ let interruptMessage = null;
120
+ let answer = null;
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
+ }
137
+ ]
138
+ });
139
+ interruptValues = {
140
+ action,
141
+ args: args ?? {}
142
+ };
143
+ }
144
+ const response = (0, import_langgraph.interrupt)({
145
+ __copilotkit_interrupt_value__: interruptValues,
146
+ __copilotkit_messages__: [
147
+ interruptMessage
148
+ ]
149
+ });
150
+ answer = response.content;
151
+ return {
152
+ answer,
153
+ messages: [
154
+ interruptMessage,
155
+ response
156
+ ]
157
+ };
158
+ }
159
+ __name(copilotKitInterrupt, "copilotKitInterrupt");
112
160
  // Annotate the CommonJS export names for ESM import in node:
113
161
  0 && (module.exports = {
114
162
  CopilotKitPropertiesAnnotation,
115
163
  CopilotKitStateAnnotation,
116
164
  convertActionToDynamicStructuredTool,
117
165
  convertActionsToDynamicStructuredTools,
166
+ copilotKitInterrupt,
118
167
  copilotkitCustomizeConfig,
119
168
  copilotkitEmitMessage,
120
169
  copilotkitEmitState,
@@ -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 } from \"@copilotkit/shared\";\nimport { Annotation, MessagesAnnotation } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\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) {\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) {\n return actions.map((action) => convertActionToDynamicStructuredTool(action));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AACA;;;;;;;;;;;;;sBAAoC;AACpC,oBAAuD;AACvD,uBAA+C;AAC/C,mBAAsC;AAe/B,IAAMA,iCAAiCC,4BAAWC,KAAK;EAC5DC,SAASF;AACX,CAAA;AAEO,IAAMG,4BAA4BH,4BAAWC,KAAK;EACvDG,YAAYJ;EACZ,GAAGK,oCAAmBC;AACxB,CAAA;AA+CO,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,QAAMC,YAAWF,yCAAYE,aAAY,CAAC;AAE1C,MAAID,mCAASE,SAAS;AACpBD,aAAS,4BAAA,IAAgC;AACzCA,aAAS,0BAAA,IAA8B;EACzC,OAAO;AACL,SAAID,mCAASG,mBAAkBC,QAAW;AACxCH,eAAS,4BAAA,IAAgCD,QAAQG;IACnD;AACA,SAAIH,mCAASK,kBAAiBD,QAAW;AACvCH,eAAS,0BAAA,IAA8BD,QAAQK;IACjD;EACF;AAEA,MAAIL,mCAASM,uBAAuB;AAClC,UAAMC,6BAA6BP,QAAQM,sBAAsBE,IAAI,CAACC,WAAW;MAC/EC,MAAMD,MAAMC;MACZC,eAAeF,MAAMG;MACrBC,WAAWJ,MAAMK;IACnB,EAAA;AAEAb,aAAS,oCAAA,IAAwCM;EACnD;AAEAR,eAAaA,cAAc,CAAC;AAE5B,SAAO;IACL,GAAGA;IACHE;EACF;AACF;AAhDgBH;AAgEhB,eAAsBiB,eAIpBC,QAAsB;AAEtB,YAAMC,qCAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAPsBD;AAuBtB,eAAsBG,oBAIpBF,QAIAP,OAAU;AAEV,YAAMQ,qCAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAXsBE;AA8BtB,eAAsBC,sBAIpBH,QAIAI,SAAe;AAEf,YAAMH,qCACJ,oCACA;IAAEG;IAASC,gBAAYC,wBAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AAfsBG;AA2BtB,eAAsBK,uBAIpBR,QAIAS,MAIAC,MAAS;AAET,YAAMT,qCACJ,sCACA;IAAEQ;IAAMC;IAAMC,QAAIL,wBAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AAnBsBQ;AAqBf,SAASI,qCAAqCC,aAAgB;AACnE,SAAO,IAAIC,mCAAsB;IAC/BL,MAAMI,YAAYJ;IAClBM,aAAaF,YAAYE;IACzBC,YAAQC,4CAA6BJ,YAAYK,YAAY,IAAA;IAC7DC,MAAM,YAAA;AACJ,aAAO;IACT;EACF,CAAA;AACF;AATgBP;AAsBT,SAASQ,uCAId3C,SAAc;AAEd,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAPgBD;","names":["CopilotKitPropertiesAnnotation","Annotation","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"]}
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) {\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) {\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.content;\n\n return {\n answer,\n messages: [interruptMessage, response],\n };\n}\n"],"mappings":"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","names":["CopilotKitPropertiesAnnotation","Annotation","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__","messages"]}
@@ -3,17 +3,19 @@ import {
3
3
  CopilotKitStateAnnotation,
4
4
  convertActionToDynamicStructuredTool,
5
5
  convertActionsToDynamicStructuredTools,
6
+ copilotKitInterrupt,
6
7
  copilotkitCustomizeConfig,
7
8
  copilotkitEmitMessage,
8
9
  copilotkitEmitState,
9
10
  copilotkitEmitToolCall,
10
11
  copilotkitExit
11
- } from "./chunk-HGYWIU6Y.mjs";
12
+ } from "./chunk-H76O4R7D.mjs";
12
13
  export {
13
14
  CopilotKitPropertiesAnnotation,
14
15
  CopilotKitStateAnnotation,
15
16
  convertActionToDynamicStructuredTool,
16
17
  convertActionsToDynamicStructuredTools,
18
+ copilotKitInterrupt,
17
19
  copilotkitCustomizeConfig,
18
20
  copilotkitEmitMessage,
19
21
  copilotkitEmitState,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.5.15-next.7",
12
+ "version": "1.5.15",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -56,17 +56,17 @@
56
56
  "tsup": "^6.7.0",
57
57
  "typescript": "^5.2.3",
58
58
  "zod-to-json-schema": "^3.23.5",
59
- "tsconfig": "1.4.6",
60
- "eslint-config-custom": "1.4.6"
59
+ "eslint-config-custom": "1.4.6",
60
+ "tsconfig": "1.4.6"
61
61
  },
62
62
  "dependencies": {
63
63
  "@langchain/community": "^0.0.53",
64
64
  "@langchain/core": "^0.3.13",
65
- "@langchain/langgraph": "^0.2.22",
66
- "@langchain/langgraph-sdk": "^0.0.16",
65
+ "@langchain/langgraph": "^0.2.44",
66
+ "@langchain/langgraph-sdk": "^0.0.36",
67
67
  "langchain": "^0.3.3",
68
68
  "zod": "^3.23.3",
69
- "@copilotkit/shared": "1.5.15-next.7"
69
+ "@copilotkit/shared": "1.5.15"
70
70
  },
71
71
  "keywords": [
72
72
  "copilotkit",
package/src/langgraph.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { RunnableConfig } from "@langchain/core/runnables";
2
2
  import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
3
3
  import { convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
4
- import { Annotation, MessagesAnnotation } from "@langchain/langgraph";
4
+ import { Annotation, MessagesAnnotation, interrupt } from "@langchain/langgraph";
5
5
  import { DynamicStructuredTool } from "@langchain/core/tools";
6
+ import { AIMessage } from "@langchain/core/messages";
6
7
 
7
8
  interface IntermediateStateConfig {
8
9
  stateKey: string;
@@ -266,3 +267,46 @@ export function convertActionsToDynamicStructuredTools(
266
267
  ) {
267
268
  return actions.map((action) => convertActionToDynamicStructuredTool(action));
268
269
  }
270
+
271
+ export function copilotKitInterrupt({
272
+ message,
273
+ action,
274
+ args,
275
+ }: {
276
+ message?: string;
277
+ action?: string;
278
+ args?: Record<string, any>;
279
+ }) {
280
+ if (!message && !action) {
281
+ throw new Error("Either message or action (and optional arguments) must be provided");
282
+ }
283
+
284
+ let interruptValues = null;
285
+ let interruptMessage = null;
286
+ let answer = null;
287
+ if (message) {
288
+ interruptValues = message;
289
+ interruptMessage = new AIMessage({ content: message, id: randomId() });
290
+ } else {
291
+ const toolId = randomId();
292
+ interruptMessage = new AIMessage({
293
+ content: "",
294
+ tool_calls: [{ id: toolId, name: action, args: args ?? {} }],
295
+ });
296
+ interruptValues = {
297
+ action,
298
+ args: args ?? {},
299
+ };
300
+ }
301
+
302
+ const response = interrupt({
303
+ __copilotkit_interrupt_value__: interruptValues,
304
+ __copilotkit_messages__: [interruptMessage],
305
+ });
306
+ answer = response.content;
307
+
308
+ return {
309
+ answer,
310
+ messages: [interruptMessage, response],
311
+ };
312
+ }
@@ -1 +0,0 @@
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 } from \"@langchain/langgraph\";\nimport { DynamicStructuredTool } from \"@langchain/core/tools\";\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) {\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) {\n return actions.map((action) => convertActionToDynamicStructuredTool(action));\n}\n"],"mappings":";;;;AACA,SAASA,2BAA2B;AACpC,SAASC,8BAA8BC,gBAAgB;AACvD,SAASC,YAAYC,0BAA0B;AAC/C,SAASC,6BAA6B;AAe/B,IAAMC,iCAAiCC,WAAWC,KAAK;EAC5DC,SAASF;AACX,CAAA;AAEO,IAAMG,4BAA4BH,WAAWC,KAAK;EACvDG,YAAYJ;EACZ,GAAGK,mBAAmBC;AACxB,CAAA;AA+CO,SAASC,0BAIdC,YAYAC,SAAuB;AAEvB,QAAMC,YAAWF,yCAAYE,aAAY,CAAC;AAE1C,MAAID,mCAASE,SAAS;AACpBD,aAAS,4BAAA,IAAgC;AACzCA,aAAS,0BAAA,IAA8B;EACzC,OAAO;AACL,SAAID,mCAASG,mBAAkBC,QAAW;AACxCH,eAAS,4BAAA,IAAgCD,QAAQG;IACnD;AACA,SAAIH,mCAASK,kBAAiBD,QAAW;AACvCH,eAAS,0BAAA,IAA8BD,QAAQK;IACjD;EACF;AAEA,MAAIL,mCAASM,uBAAuB;AAClC,UAAMC,6BAA6BP,QAAQM,sBAAsBE,IAAI,CAACC,WAAW;MAC/EC,MAAMD,MAAMC;MACZC,eAAeF,MAAMG;MACrBC,WAAWJ,MAAMK;IACnB,EAAA;AAEAb,aAAS,oCAAA,IAAwCM;EACnD;AAEAR,eAAaA,cAAc,CAAC;AAE5B,SAAO;IACL,GAAGA;IACHE;EACF;AACF;AAhDgBH;AAgEhB,eAAsBiB,eAIpBC,QAAsB;AAEtB,QAAMC,oBAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAPsBD;AAuBtB,eAAsBG,oBAIpBF,QAIAP,OAAU;AAEV,QAAMQ,oBAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAXsBE;AA8BtB,eAAsBC,sBAIpBH,QAIAI,SAAe;AAEf,QAAMH,oBACJ,oCACA;IAAEG;IAASC,YAAYC,SAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AAfsBG;AA2BtB,eAAsBK,uBAIpBR,QAIAS,MAIAC,MAAS;AAET,QAAMT,oBACJ,sCACA;IAAEQ;IAAMC;IAAMC,IAAIL,SAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AAnBsBQ;AAqBf,SAASI,qCAAqCC,aAAgB;AACnE,SAAO,IAAIC,sBAAsB;IAC/BL,MAAMI,YAAYJ;IAClBM,aAAaF,YAAYE;IACzBC,QAAQC,6BAA6BJ,YAAYK,YAAY,IAAA;IAC7DC,MAAM,YAAA;AACJ,aAAO;IACT;EACF,CAAA;AACF;AATgBP;AAsBT,SAASQ,uCAId3C,SAAc;AAEd,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAPgBD;","names":["dispatchCustomEvent","convertJsonSchemaToZodSchema","randomId","Annotation","MessagesAnnotation","DynamicStructuredTool","CopilotKitPropertiesAnnotation","Annotation","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"]}