@copilotkit/sdk-js 1.5.12-next.6 → 1.5.12

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,18 @@
1
1
  # @copilotkit/sdk-js
2
2
 
3
+ ## 1.5.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [6136a57]
8
+ - @copilotkit/shared@1.5.12
9
+
10
+ ## 1.5.12-next.7
11
+
12
+ ### Patch Changes
13
+
14
+ - @copilotkit/shared@1.5.12-next.7
15
+
3
16
  ## 1.5.12-next.6
4
17
 
5
18
  ### Patch Changes
@@ -0,0 +1,95 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/langgraph.ts
5
+ import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
6
+ import { convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
7
+ import { Annotation, MessagesAnnotation } from "@langchain/langgraph";
8
+ import { DynamicStructuredTool } from "@langchain/core/tools";
9
+ var CopilotKitPropertiesAnnotation = Annotation.Root({
10
+ actions: Annotation
11
+ });
12
+ var CopilotKitStateAnnotation = Annotation.Root({
13
+ copilotkit: Annotation,
14
+ ...MessagesAnnotation.spec
15
+ });
16
+ function copilotkitCustomizeConfig(baseConfig, options) {
17
+ const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
18
+ if (options == null ? void 0 : options.emitAll) {
19
+ metadata["copilotkit:emit-tool-calls"] = true;
20
+ metadata["copilotkit:emit-messages"] = true;
21
+ } else {
22
+ if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
23
+ metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
24
+ }
25
+ if ((options == null ? void 0 : options.emitMessages) !== void 0) {
26
+ metadata["copilotkit:emit-messages"] = options.emitMessages;
27
+ }
28
+ }
29
+ if (options == null ? void 0 : options.emitIntermediateState) {
30
+ const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
31
+ tool: state.tool,
32
+ tool_argument: state.toolArgument,
33
+ state_key: state.stateKey
34
+ }));
35
+ metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
36
+ }
37
+ baseConfig = baseConfig || {};
38
+ return {
39
+ ...baseConfig,
40
+ metadata
41
+ };
42
+ }
43
+ __name(copilotkitCustomizeConfig, "copilotkitCustomizeConfig");
44
+ async function copilotkitExit(config) {
45
+ await dispatchCustomEvent("copilotkit_exit", {}, config);
46
+ }
47
+ __name(copilotkitExit, "copilotkitExit");
48
+ async function copilotkitEmitState(config, state) {
49
+ await dispatchCustomEvent("copilotkit_manually_emit_intermediate_state", state, config);
50
+ }
51
+ __name(copilotkitEmitState, "copilotkitEmitState");
52
+ async function copilotkitEmitMessage(config, message) {
53
+ await dispatchCustomEvent("copilotkit_manually_emit_message", {
54
+ message,
55
+ message_id: randomId(),
56
+ role: "assistant"
57
+ }, config);
58
+ }
59
+ __name(copilotkitEmitMessage, "copilotkitEmitMessage");
60
+ async function copilotkitEmitToolCall(config, name, args) {
61
+ await dispatchCustomEvent("copilotkit_manually_emit_tool_call", {
62
+ name,
63
+ args,
64
+ id: randomId()
65
+ }, config);
66
+ }
67
+ __name(copilotkitEmitToolCall, "copilotkitEmitToolCall");
68
+ function convertActionToDynamicStructuredTool(actionInput) {
69
+ return new DynamicStructuredTool({
70
+ name: actionInput.name,
71
+ description: actionInput.description,
72
+ schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),
73
+ func: async () => {
74
+ return "";
75
+ }
76
+ });
77
+ }
78
+ __name(convertActionToDynamicStructuredTool, "convertActionToDynamicStructuredTool");
79
+ function convertActionsToDynamicStructuredTools(actions) {
80
+ return actions.map((action) => convertActionToDynamicStructuredTool(action));
81
+ }
82
+ __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
83
+
84
+ export {
85
+ CopilotKitPropertiesAnnotation,
86
+ CopilotKitStateAnnotation,
87
+ copilotkitCustomizeConfig,
88
+ copilotkitExit,
89
+ copilotkitEmitState,
90
+ copilotkitEmitMessage,
91
+ copilotkitEmitToolCall,
92
+ convertActionToDynamicStructuredTool,
93
+ convertActionsToDynamicStructuredTools
94
+ };
95
+ //# sourceMappingURL=chunk-HGYWIU6Y.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 } 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"]}
@@ -1,73 +1,6 @@
1
- import * as zod from 'zod';
2
- import * as _langchain_core_messages from '@langchain/core/messages';
3
- import * as _langchain_langgraph from '@langchain/langgraph';
4
- import { RunnableConfig } from '@langchain/core/runnables';
5
- import { DynamicStructuredTool } from '@langchain/core/tools';
6
-
7
- interface IntermediateStateConfig {
8
- stateKey: string;
9
- tool: string;
10
- toolArgument?: string;
11
- }
12
- interface OptionsConfig {
13
- emitToolCalls?: boolean | string | string[];
14
- emitMessages?: boolean;
15
- emitAll?: boolean;
16
- emitIntermediateState?: IntermediateStateConfig[];
17
- }
18
- declare const CopilotKitPropertiesAnnotation: _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<{
19
- actions: {
20
- (): _langchain_langgraph.LastValue<any[]>;
21
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
22
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
23
- };
24
- }>;
25
- declare const CopilotKitStateAnnotation: _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<{
26
- messages: _langchain_langgraph.BinaryOperatorAggregate<_langchain_core_messages.BaseMessage[], _langchain_langgraph.Messages>;
27
- copilotkit: {
28
- (): _langchain_langgraph.LastValue<_langchain_langgraph.StateType<{
29
- actions: {
30
- (): _langchain_langgraph.LastValue<any[]>;
31
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
32
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
33
- };
34
- }>>;
35
- (annotation: _langchain_langgraph.SingleReducer<_langchain_langgraph.StateType<{
36
- actions: {
37
- (): _langchain_langgraph.LastValue<any[]>;
38
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
39
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
40
- };
41
- }>, _langchain_langgraph.StateType<{
42
- actions: {
43
- (): _langchain_langgraph.LastValue<any[]>;
44
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
45
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
46
- };
47
- }>>): _langchain_langgraph.BinaryOperatorAggregate<_langchain_langgraph.StateType<{
48
- actions: {
49
- (): _langchain_langgraph.LastValue<any[]>;
50
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
51
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
52
- };
53
- }>, _langchain_langgraph.StateType<{
54
- actions: {
55
- (): _langchain_langgraph.LastValue<any[]>;
56
- (annotation: _langchain_langgraph.SingleReducer<any[], any[]>): _langchain_langgraph.BinaryOperatorAggregate<any[], any[]>;
57
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
58
- };
59
- }>>;
60
- Root: <S extends _langchain_langgraph.StateDefinition>(sd: S) => _langchain_langgraph._INTERNAL_ANNOTATION_ROOT<S>;
61
- };
62
- }>;
63
- type CopilotKitState = typeof CopilotKitStateAnnotation.State;
64
- type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;
65
- declare function copilotKitCustomizeConfig(baseConfig: RunnableConfig, options?: OptionsConfig): RunnableConfig;
66
- declare function copilotKitExit(config: RunnableConfig): Promise<void>;
67
- declare function copilotKitEmitState(config: RunnableConfig, state: any): Promise<void>;
68
- declare function copilotKitEmitMessage(config: RunnableConfig, message: string): Promise<void>;
69
- declare function copilotKitEmitToolCall(config: RunnableConfig, name: string, args: any): Promise<void>;
70
- declare function convertActionToDynamicStructuredTool(actionInput: any): DynamicStructuredTool<zod.ZodType<any, zod.ZodTypeDef, any>>;
71
- declare function convertActionsToDynamicStructuredTools(actions: any[]): DynamicStructuredTool<zod.ZodType<any, zod.ZodTypeDef, any>>[];
72
-
73
- export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotKitCustomizeConfig, copilotKitEmitMessage, copilotKitEmitState, copilotKitEmitToolCall, copilotKitExit };
1
+ export { CopilotKitProperties, CopilotKitPropertiesAnnotation, CopilotKitState, CopilotKitStateAnnotation, convertActionToDynamicStructuredTool, convertActionsToDynamicStructuredTools, copilotkitCustomizeConfig as copilotKitCustomizeConfig, copilotkitEmitMessage as copilotKitEmitMessage, copilotkitEmitState as copilotKitEmitState, copilotkitEmitToolCall as copilotKitEmitToolCall, copilotkitExit as copilotKitExit } from './langgraph.js';
2
+ import 'zod';
3
+ import '@langchain/core/messages';
4
+ import '@langchain/langgraph';
5
+ import '@langchain/core/runnables';
6
+ import '@langchain/core/tools';
package/dist/langchain.js CHANGED
@@ -24,13 +24,15 @@ __export(langchain_exports, {
24
24
  CopilotKitStateAnnotation: () => CopilotKitStateAnnotation,
25
25
  convertActionToDynamicStructuredTool: () => convertActionToDynamicStructuredTool,
26
26
  convertActionsToDynamicStructuredTools: () => convertActionsToDynamicStructuredTools,
27
- copilotKitCustomizeConfig: () => copilotKitCustomizeConfig,
28
- copilotKitEmitMessage: () => copilotKitEmitMessage,
29
- copilotKitEmitState: () => copilotKitEmitState,
30
- copilotKitEmitToolCall: () => copilotKitEmitToolCall,
31
- copilotKitExit: () => copilotKitExit
27
+ copilotKitCustomizeConfig: () => copilotkitCustomizeConfig,
28
+ copilotKitEmitMessage: () => copilotkitEmitMessage,
29
+ copilotKitEmitState: () => copilotkitEmitState,
30
+ copilotKitEmitToolCall: () => copilotkitEmitToolCall,
31
+ copilotKitExit: () => copilotkitExit
32
32
  });
33
33
  module.exports = __toCommonJS(langchain_exports);
34
+
35
+ // src/langgraph.ts
34
36
  var import_dispatch = require("@langchain/core/callbacks/dispatch");
35
37
  var import_shared = require("@copilotkit/shared");
36
38
  var import_langgraph = require("@langchain/langgraph");
@@ -42,7 +44,7 @@ var CopilotKitStateAnnotation = import_langgraph.Annotation.Root({
42
44
  copilotkit: import_langgraph.Annotation,
43
45
  ...import_langgraph.MessagesAnnotation.spec
44
46
  });
45
- function copilotKitCustomizeConfig(baseConfig, options) {
47
+ function copilotkitCustomizeConfig(baseConfig, options) {
46
48
  const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
47
49
  if (options == null ? void 0 : options.emitAll) {
48
50
  metadata["copilotkit:emit-tool-calls"] = true;
@@ -69,31 +71,31 @@ function copilotKitCustomizeConfig(baseConfig, options) {
69
71
  metadata
70
72
  };
71
73
  }
72
- __name(copilotKitCustomizeConfig, "copilotKitCustomizeConfig");
73
- async function copilotKitExit(config) {
74
+ __name(copilotkitCustomizeConfig, "copilotkitCustomizeConfig");
75
+ async function copilotkitExit(config) {
74
76
  await (0, import_dispatch.dispatchCustomEvent)("copilotkit_exit", {}, config);
75
77
  }
76
- __name(copilotKitExit, "copilotKitExit");
77
- async function copilotKitEmitState(config, state) {
78
+ __name(copilotkitExit, "copilotkitExit");
79
+ async function copilotkitEmitState(config, state) {
78
80
  await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_intermediate_state", state, config);
79
81
  }
80
- __name(copilotKitEmitState, "copilotKitEmitState");
81
- async function copilotKitEmitMessage(config, message) {
82
+ __name(copilotkitEmitState, "copilotkitEmitState");
83
+ async function copilotkitEmitMessage(config, message) {
82
84
  await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_message", {
83
85
  message,
84
86
  message_id: (0, import_shared.randomId)(),
85
87
  role: "assistant"
86
88
  }, config);
87
89
  }
88
- __name(copilotKitEmitMessage, "copilotKitEmitMessage");
89
- async function copilotKitEmitToolCall(config, name, args) {
90
+ __name(copilotkitEmitMessage, "copilotkitEmitMessage");
91
+ async function copilotkitEmitToolCall(config, name, args) {
90
92
  await (0, import_dispatch.dispatchCustomEvent)("copilotkit_manually_emit_tool_call", {
91
93
  name,
92
94
  args,
93
95
  id: (0, import_shared.randomId)()
94
96
  }, config);
95
97
  }
96
- __name(copilotKitEmitToolCall, "copilotKitEmitToolCall");
98
+ __name(copilotkitEmitToolCall, "copilotkitEmitToolCall");
97
99
  function convertActionToDynamicStructuredTool(actionInput) {
98
100
  return new import_tools.DynamicStructuredTool({
99
101
  name: actionInput.name,
@@ -109,6 +111,9 @@ function convertActionsToDynamicStructuredTools(actions) {
109
111
  return actions.map((action) => convertActionToDynamicStructuredTool(action));
110
112
  }
111
113
  __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
114
+
115
+ // src/langchain.ts
116
+ console.warn("Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.");
112
117
  // Annotate the CommonJS export names for ESM import in node:
113
118
  0 && (module.exports = {
114
119
  CopilotKitPropertiesAnnotation,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/langchain.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\nexport function copilotKitCustomizeConfig(\n baseConfig: RunnableConfig,\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\nexport async function copilotKitExit(config: RunnableConfig) {\n await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\n}\n\nexport async function copilotKitEmitState(config: RunnableConfig, state: any) {\n await dispatchCustomEvent(\"copilotkit_manually_emit_intermediate_state\", state, config);\n}\n\nexport async function copilotKitEmitMessage(config: RunnableConfig, message: string) {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\n );\n}\n\nexport async function copilotKitEmitToolCall(config: RunnableConfig, name: string, args: any) {\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\nexport function convertActionsToDynamicStructuredTools(actions: any[]) {\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;AAKO,SAASC,0BACdC,YACAC,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;AAlCgBH;AAoChB,eAAsBiB,eAAeC,QAAsB;AACzD,YAAMC,qCAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAFsBD;AAItB,eAAsBG,oBAAoBF,QAAwBP,OAAU;AAC1E,YAAMQ,qCAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAFsBE;AAItB,eAAsBC,sBAAsBH,QAAwBI,SAAe;AACjF,YAAMH,qCACJ,oCACA;IAAEG;IAASC,gBAAYC,wBAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AANsBG;AAQtB,eAAsBK,uBAAuBR,QAAwBS,MAAcC,MAAS;AAC1F,YAAMT,qCACJ,sCACA;IAAEQ;IAAMC;IAAMC,QAAIL,wBAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AANsBQ;AAQf,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;AAWT,SAASQ,uCAAuC3C,SAAc;AACnE,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAFgBD;","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/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,94 +1,26 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import {
2
+ CopilotKitPropertiesAnnotation,
3
+ CopilotKitStateAnnotation,
4
+ convertActionToDynamicStructuredTool,
5
+ convertActionsToDynamicStructuredTools,
6
+ copilotkitCustomizeConfig,
7
+ copilotkitEmitMessage,
8
+ copilotkitEmitState,
9
+ copilotkitEmitToolCall,
10
+ copilotkitExit
11
+ } from "./chunk-HGYWIU6Y.mjs";
3
12
 
4
13
  // src/langchain.ts
5
- import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
6
- import { convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
7
- import { Annotation, MessagesAnnotation } from "@langchain/langgraph";
8
- import { DynamicStructuredTool } from "@langchain/core/tools";
9
- var CopilotKitPropertiesAnnotation = Annotation.Root({
10
- actions: Annotation
11
- });
12
- var CopilotKitStateAnnotation = Annotation.Root({
13
- copilotkit: Annotation,
14
- ...MessagesAnnotation.spec
15
- });
16
- function copilotKitCustomizeConfig(baseConfig, options) {
17
- const metadata = (baseConfig == null ? void 0 : baseConfig.metadata) || {};
18
- if (options == null ? void 0 : options.emitAll) {
19
- metadata["copilotkit:emit-tool-calls"] = true;
20
- metadata["copilotkit:emit-messages"] = true;
21
- } else {
22
- if ((options == null ? void 0 : options.emitToolCalls) !== void 0) {
23
- metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
24
- }
25
- if ((options == null ? void 0 : options.emitMessages) !== void 0) {
26
- metadata["copilotkit:emit-messages"] = options.emitMessages;
27
- }
28
- }
29
- if (options == null ? void 0 : options.emitIntermediateState) {
30
- const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
31
- tool: state.tool,
32
- tool_argument: state.toolArgument,
33
- state_key: state.stateKey
34
- }));
35
- metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
36
- }
37
- baseConfig = baseConfig || {};
38
- return {
39
- ...baseConfig,
40
- metadata
41
- };
42
- }
43
- __name(copilotKitCustomizeConfig, "copilotKitCustomizeConfig");
44
- async function copilotKitExit(config) {
45
- await dispatchCustomEvent("copilotkit_exit", {}, config);
46
- }
47
- __name(copilotKitExit, "copilotKitExit");
48
- async function copilotKitEmitState(config, state) {
49
- await dispatchCustomEvent("copilotkit_manually_emit_intermediate_state", state, config);
50
- }
51
- __name(copilotKitEmitState, "copilotKitEmitState");
52
- async function copilotKitEmitMessage(config, message) {
53
- await dispatchCustomEvent("copilotkit_manually_emit_message", {
54
- message,
55
- message_id: randomId(),
56
- role: "assistant"
57
- }, config);
58
- }
59
- __name(copilotKitEmitMessage, "copilotKitEmitMessage");
60
- async function copilotKitEmitToolCall(config, name, args) {
61
- await dispatchCustomEvent("copilotkit_manually_emit_tool_call", {
62
- name,
63
- args,
64
- id: randomId()
65
- }, config);
66
- }
67
- __name(copilotKitEmitToolCall, "copilotKitEmitToolCall");
68
- function convertActionToDynamicStructuredTool(actionInput) {
69
- return new DynamicStructuredTool({
70
- name: actionInput.name,
71
- description: actionInput.description,
72
- schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),
73
- func: async () => {
74
- return "";
75
- }
76
- });
77
- }
78
- __name(convertActionToDynamicStructuredTool, "convertActionToDynamicStructuredTool");
79
- function convertActionsToDynamicStructuredTools(actions) {
80
- return actions.map((action) => convertActionToDynamicStructuredTool(action));
81
- }
82
- __name(convertActionsToDynamicStructuredTools, "convertActionsToDynamicStructuredTools");
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.");
83
15
  export {
84
16
  CopilotKitPropertiesAnnotation,
85
17
  CopilotKitStateAnnotation,
86
18
  convertActionToDynamicStructuredTool,
87
19
  convertActionsToDynamicStructuredTools,
88
- copilotKitCustomizeConfig,
89
- copilotKitEmitMessage,
90
- copilotKitEmitState,
91
- copilotKitEmitToolCall,
92
- copilotKitExit
20
+ copilotkitCustomizeConfig as copilotKitCustomizeConfig,
21
+ copilotkitEmitMessage as copilotKitEmitMessage,
22
+ copilotkitEmitState as copilotKitEmitState,
23
+ copilotkitEmitToolCall as copilotKitEmitToolCall,
24
+ copilotkitExit as copilotKitExit
93
25
  };
94
26
  //# sourceMappingURL=langchain.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/langchain.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\nexport function copilotKitCustomizeConfig(\n baseConfig: RunnableConfig,\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\nexport async function copilotKitExit(config: RunnableConfig) {\n await dispatchCustomEvent(\"copilotkit_exit\", {}, config);\n}\n\nexport async function copilotKitEmitState(config: RunnableConfig, state: any) {\n await dispatchCustomEvent(\"copilotkit_manually_emit_intermediate_state\", state, config);\n}\n\nexport async function copilotKitEmitMessage(config: RunnableConfig, message: string) {\n await dispatchCustomEvent(\n \"copilotkit_manually_emit_message\",\n { message, message_id: randomId(), role: \"assistant\" },\n config,\n );\n}\n\nexport async function copilotKitEmitToolCall(config: RunnableConfig, name: string, args: any) {\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\nexport function convertActionsToDynamicStructuredTools(actions: any[]) {\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;AAKO,SAASC,0BACdC,YACAC,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;AAlCgBH;AAoChB,eAAsBiB,eAAeC,QAAsB;AACzD,QAAMC,oBAAoB,mBAAmB,CAAC,GAAGD,MAAAA;AACnD;AAFsBD;AAItB,eAAsBG,oBAAoBF,QAAwBP,OAAU;AAC1E,QAAMQ,oBAAoB,+CAA+CR,OAAOO,MAAAA;AAClF;AAFsBE;AAItB,eAAsBC,sBAAsBH,QAAwBI,SAAe;AACjF,QAAMH,oBACJ,oCACA;IAAEG;IAASC,YAAYC,SAAAA;IAAYC,MAAM;EAAY,GACrDP,MAAAA;AAEJ;AANsBG;AAQtB,eAAsBK,uBAAuBR,QAAwBS,MAAcC,MAAS;AAC1F,QAAMT,oBACJ,sCACA;IAAEQ;IAAMC;IAAMC,IAAIL,SAAAA;EAAW,GAC7BN,MAAAA;AAEJ;AANsBQ;AAQf,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;AAWT,SAASQ,uCAAuC3C,SAAc;AACnE,SAAOA,QAAQe,IAAI,CAAC6B,WAAWT,qCAAqCS,MAAAA,CAAAA;AACtE;AAFgBD;","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"]}
1
+ {"version":3,"sources":["../src/langchain.ts"],"sourcesContent":["console.warn(\n \"Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.\",\n);\n\nexport {\n CopilotKitPropertiesAnnotation,\n CopilotKitStateAnnotation,\n type CopilotKitState,\n type CopilotKitProperties,\n copilotkitCustomizeConfig as copilotKitCustomizeConfig,\n copilotkitExit as copilotKitExit,\n copilotkitEmitState as copilotKitEmitState,\n copilotkitEmitMessage as copilotKitEmitMessage,\n copilotkitEmitToolCall as copilotKitEmitToolCall,\n convertActionToDynamicStructuredTool,\n convertActionsToDynamicStructuredTools,\n} from \"./langgraph\";\n"],"mappings":";;;;;;;;;;;;;AAAAA,QAAQC,KACN,mJAAA;","names":["console","warn"]}