@copilotkit/sdk-js 0.0.0-mme-load-agent-state-20250117154700

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/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@copilotkit/sdk-js",
3
+ "private": false,
4
+ "homepage": "https://github.com/CopilotKit/CopilotKit",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/CopilotKit/CopilotKit.git"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "version": "0.0.0-mme-load-agent-state-20250117154700",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "exports": {
17
+ ".": {
18
+ "require": "./dist/index.js",
19
+ "import": "./dist/index.mjs"
20
+ },
21
+ "./langchain": {
22
+ "require": "./dist/langchain.js",
23
+ "import": "./dist/langchain.mjs"
24
+ },
25
+ "./langgraph": {
26
+ "require": "./dist/langgraph.js",
27
+ "import": "./dist/langgraph.mjs"
28
+ }
29
+ },
30
+ "types": "./dist/index.d.ts",
31
+ "typesVersions": {
32
+ "*": {
33
+ "langchain": [
34
+ "dist/langchain.d.ts"
35
+ ],
36
+ "langgraph": [
37
+ "dist/langgraph.d.ts"
38
+ ],
39
+ "*": [
40
+ "dist/*"
41
+ ]
42
+ }
43
+ },
44
+ "license": "MIT",
45
+ "devDependencies": {
46
+ "@swc/core": "1.5.28",
47
+ "@types/express": "^4.17.21",
48
+ "@types/jest": "^29.5.4",
49
+ "@types/node": "^18.11.17",
50
+ "@whatwg-node/server": "^0.9.34",
51
+ "eslint": "^8.56.0",
52
+ "jest": "^29.6.4",
53
+ "nodemon": "^3.1.3",
54
+ "ts-jest": "^29.1.1",
55
+ "ts-node": "^10.9.2",
56
+ "tsup": "^6.7.0",
57
+ "typescript": "^5.2.3",
58
+ "zod-to-json-schema": "^3.23.5",
59
+ "tsconfig": "1.4.6",
60
+ "eslint-config-custom": "1.4.6"
61
+ },
62
+ "dependencies": {
63
+ "@langchain/community": "^0.0.53",
64
+ "@langchain/core": "^0.3.13",
65
+ "@langchain/langgraph": "^0.2.22",
66
+ "@langchain/langgraph-sdk": "^0.0.16",
67
+ "langchain": "^0.3.3",
68
+ "zod": "^3.23.3",
69
+ "@copilotkit/shared": "0.0.0-mme-load-agent-state-20250117154700"
70
+ },
71
+ "keywords": [
72
+ "copilotkit",
73
+ "copilot",
74
+ "react",
75
+ "nextjs",
76
+ "nodejs",
77
+ "ai",
78
+ "assistant",
79
+ "javascript",
80
+ "automation",
81
+ "textarea"
82
+ ],
83
+ "scripts": {
84
+ "build": "tsup --clean",
85
+ "dev": "tsup --watch --no-splitting",
86
+ "test": "jest --passWithNoTests",
87
+ "check-types": "tsc --noEmit",
88
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next",
89
+ "link:global": "pnpm link --global",
90
+ "unlink:global": "pnpm unlink --global"
91
+ }
92
+ }
package/src/index.ts ADDED
File without changes
@@ -0,0 +1,17 @@
1
+ console.warn(
2
+ "Warning: '@copilotkit/sdk-js/langchain' is deprecated and will be removed in a future release. Please use '@copilotkit/sdk-js/langgraph' instead.",
3
+ );
4
+
5
+ export {
6
+ CopilotKitPropertiesAnnotation,
7
+ CopilotKitStateAnnotation,
8
+ type CopilotKitState,
9
+ type CopilotKitProperties,
10
+ copilotkitCustomizeConfig as copilotKitCustomizeConfig,
11
+ copilotkitExit as copilotKitExit,
12
+ copilotkitEmitState as copilotKitEmitState,
13
+ copilotkitEmitMessage as copilotKitEmitMessage,
14
+ copilotkitEmitToolCall as copilotKitEmitToolCall,
15
+ convertActionToDynamicStructuredTool,
16
+ convertActionsToDynamicStructuredTools,
17
+ } from "./langgraph";
@@ -0,0 +1,268 @@
1
+ import { RunnableConfig } from "@langchain/core/runnables";
2
+ import { dispatchCustomEvent } from "@langchain/core/callbacks/dispatch";
3
+ import { convertJsonSchemaToZodSchema, randomId } from "@copilotkit/shared";
4
+ import { Annotation, MessagesAnnotation } from "@langchain/langgraph";
5
+ import { DynamicStructuredTool } from "@langchain/core/tools";
6
+
7
+ interface IntermediateStateConfig {
8
+ stateKey: string;
9
+ tool: string;
10
+ toolArgument?: string;
11
+ }
12
+
13
+ interface OptionsConfig {
14
+ emitToolCalls?: boolean | string | string[];
15
+ emitMessages?: boolean;
16
+ emitAll?: boolean;
17
+ emitIntermediateState?: IntermediateStateConfig[];
18
+ }
19
+
20
+ export const CopilotKitPropertiesAnnotation = Annotation.Root({
21
+ actions: Annotation<any[]>,
22
+ });
23
+
24
+ export const CopilotKitStateAnnotation = Annotation.Root({
25
+ copilotkit: Annotation<typeof CopilotKitPropertiesAnnotation.State>,
26
+ ...MessagesAnnotation.spec,
27
+ });
28
+
29
+ export type CopilotKitState = typeof CopilotKitStateAnnotation.State;
30
+ export type CopilotKitProperties = typeof CopilotKitPropertiesAnnotation.State;
31
+
32
+ /**
33
+ * Customize the LangGraph configuration for use in CopilotKit.
34
+ *
35
+ * To the CopilotKit SDK, run:
36
+ *
37
+ * ```bash
38
+ * npm install @copilotkit/sdk-js
39
+ * ```
40
+ *
41
+ * ### Examples
42
+ *
43
+ * Disable emitting messages and tool calls:
44
+ *
45
+ * ```typescript
46
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
47
+ *
48
+ * config = copilotkitCustomizeConfig(
49
+ * config,
50
+ * emitMessages=false,
51
+ * emitToolCalls=false
52
+ * )
53
+ * ```
54
+ *
55
+ * To emit a tool call as streaming LangGraph state, pass the destination key in state,
56
+ * the tool name and optionally the tool argument. (If you don't pass the argument name,
57
+ * all arguments are emitted under the state key.)
58
+ *
59
+ * ```typescript
60
+ * import { copilotkitCustomizeConfig } from "@copilotkit/sdk-js";
61
+ *
62
+ * config = copilotkitCustomizeConfig(
63
+ * config,
64
+ * emitIntermediateState=[
65
+ * {
66
+ * "stateKey": "steps",
67
+ * "tool": "SearchTool",
68
+ * "toolArgument": "steps",
69
+ * },
70
+ * ],
71
+ * )
72
+ * ```
73
+ */
74
+ export function copilotkitCustomizeConfig(
75
+ /**
76
+ * The LangChain/LangGraph configuration to customize.
77
+ */
78
+ baseConfig: RunnableConfig,
79
+ /**
80
+ * Configuration options:
81
+ * - `emitMessages: boolean?`
82
+ * Configure how messages are emitted. By default, all messages are emitted. Pass false to
83
+ * disable emitting messages.
84
+ * - `emitToolCalls: boolean | string | string[]?`
85
+ * Configure how tool calls are emitted. By default, all tool calls are emitted. Pass false to
86
+ * disable emitting tool calls. Pass a string or list of strings to emit only specific tool calls.
87
+ * - `emitIntermediateState: IntermediateStateConfig[]?`
88
+ * Lets you emit tool calls as streaming LangGraph state.
89
+ */
90
+ options?: OptionsConfig,
91
+ ): RunnableConfig {
92
+ const metadata = baseConfig?.metadata || {};
93
+
94
+ if (options?.emitAll) {
95
+ metadata["copilotkit:emit-tool-calls"] = true;
96
+ metadata["copilotkit:emit-messages"] = true;
97
+ } else {
98
+ if (options?.emitToolCalls !== undefined) {
99
+ metadata["copilotkit:emit-tool-calls"] = options.emitToolCalls;
100
+ }
101
+ if (options?.emitMessages !== undefined) {
102
+ metadata["copilotkit:emit-messages"] = options.emitMessages;
103
+ }
104
+ }
105
+
106
+ if (options?.emitIntermediateState) {
107
+ const snakeCaseIntermediateState = options.emitIntermediateState.map((state) => ({
108
+ tool: state.tool,
109
+ tool_argument: state.toolArgument,
110
+ state_key: state.stateKey,
111
+ }));
112
+
113
+ metadata["copilotkit:emit-intermediate-state"] = snakeCaseIntermediateState;
114
+ }
115
+
116
+ baseConfig = baseConfig || {};
117
+
118
+ return {
119
+ ...baseConfig,
120
+ metadata: metadata,
121
+ };
122
+ }
123
+ /**
124
+ * Exits the current agent after the run completes. Calling copilotkit_exit() will
125
+ * not immediately stop the agent. Instead, it signals to CopilotKit to stop the agent after
126
+ * the run completes.
127
+ *
128
+ * ### Examples
129
+ *
130
+ * ```typescript
131
+ * import { copilotkitExit } from "@copilotkit/sdk-js";
132
+ *
133
+ * async function myNode(state: Any):
134
+ * await copilotkitExit(config)
135
+ * return state
136
+ * ```
137
+ */
138
+ export async function copilotkitExit(
139
+ /**
140
+ * The LangChain/LangGraph configuration.
141
+ */
142
+ config: RunnableConfig,
143
+ ) {
144
+ await dispatchCustomEvent("copilotkit_exit", {}, config);
145
+ }
146
+ /**
147
+ * Emits intermediate state to CopilotKit. Useful if you have a longer running node and you want to
148
+ * update the user with the current state of the node.
149
+ *
150
+ * ### Examples
151
+ *
152
+ * ```typescript
153
+ * import { copilotkitEmitState } from "@copilotkit/sdk-js";
154
+ *
155
+ * for (let i = 0; i < 10; i++) {
156
+ * await someLongRunningOperation(i);
157
+ * await copilotkitEmitState(config, { progress: i });
158
+ * }
159
+ * ```
160
+ */
161
+ export async function copilotkitEmitState(
162
+ /**
163
+ * The LangChain/LangGraph configuration.
164
+ */
165
+ config: RunnableConfig,
166
+ /**
167
+ * The state to emit.
168
+ */
169
+ state: any,
170
+ ) {
171
+ await dispatchCustomEvent("copilotkit_manually_emit_intermediate_state", state, config);
172
+ }
173
+ /**
174
+ * Manually emits a message to CopilotKit. Useful in longer running nodes to update the user.
175
+ * Important: You still need to return the messages from the node.
176
+ *
177
+ * ### Examples
178
+ *
179
+ * ```typescript
180
+ * import { copilotkitEmitMessage } from "@copilotkit/sdk-js";
181
+ *
182
+ * const message = "Step 1 of 10 complete";
183
+ * await copilotkitEmitMessage(config, message);
184
+ *
185
+ * // Return the message from the node
186
+ * return {
187
+ * "messages": [AIMessage(content=message)]
188
+ * }
189
+ * ```
190
+ */
191
+ export async function copilotkitEmitMessage(
192
+ /**
193
+ * The LangChain/LangGraph configuration.
194
+ */
195
+ config: RunnableConfig,
196
+ /**
197
+ * The message to emit.
198
+ */
199
+ message: string,
200
+ ) {
201
+ await dispatchCustomEvent(
202
+ "copilotkit_manually_emit_message",
203
+ { message, message_id: randomId(), role: "assistant" },
204
+ config,
205
+ );
206
+ }
207
+ /**
208
+ * Manually emits a tool call to CopilotKit.
209
+ *
210
+ * ### Examples
211
+ *
212
+ * ```typescript
213
+ * import { copilotkitEmitToolCall } from "@copilotkit/sdk-js";
214
+ *
215
+ * await copilotkitEmitToolCall(config, name="SearchTool", args={"steps": 10})
216
+ * ```
217
+ */
218
+ export async function copilotkitEmitToolCall(
219
+ /**
220
+ * The LangChain/LangGraph configuration.
221
+ */
222
+ config: RunnableConfig,
223
+ /**
224
+ * The name of the tool to emit.
225
+ */
226
+ name: string,
227
+ /**
228
+ * The arguments to emit.
229
+ */
230
+ args: any,
231
+ ) {
232
+ await dispatchCustomEvent(
233
+ "copilotkit_manually_emit_tool_call",
234
+ { name, args, id: randomId() },
235
+ config,
236
+ );
237
+ }
238
+
239
+ export function convertActionToDynamicStructuredTool(actionInput: any) {
240
+ return new DynamicStructuredTool({
241
+ name: actionInput.name,
242
+ description: actionInput.description,
243
+ schema: convertJsonSchemaToZodSchema(actionInput.parameters, true),
244
+ func: async () => {
245
+ return "";
246
+ },
247
+ });
248
+ }
249
+ /**
250
+ * Use this function to convert a list of actions you get from state
251
+ * to a list of dynamic structured tools.
252
+ *
253
+ * ### Examples
254
+ *
255
+ * ```typescript
256
+ * import { convertActionsToDynamicStructuredTools } from "@copilotkit/sdk-js";
257
+ *
258
+ * const tools = convertActionsToDynamicStructuredTools(state.copilotkit.actions);
259
+ * ```
260
+ */
261
+ export function convertActionsToDynamicStructuredTools(
262
+ /**
263
+ * The list of actions to convert.
264
+ */
265
+ actions: any[],
266
+ ) {
267
+ return actions.map((action) => convertActionToDynamicStructuredTool(action));
268
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../utilities/tsconfig/base.json",
3
+ "compilerOptions": {
4
+ "lib": ["es2017", "dom"],
5
+ "emitDecoratorMetadata": true,
6
+ "experimentalDecorators": true,
7
+ "strict": false
8
+ },
9
+ "include": ["./src/**/*.ts"],
10
+ "exclude": ["dist", "build", "node_modules", "**/*.test.ts", "**/*.test.tsx", "**/__tests__/*"]
11
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { defineConfig, Options } from "tsup";
2
+
3
+ export default defineConfig((options: Options) => ({
4
+ ...options,
5
+ entry: {
6
+ index: "src/index.ts",
7
+ langchain: "src/langchain.ts",
8
+ langgraph: "src/langgraph.ts",
9
+ },
10
+ format: ["esm", "cjs"],
11
+ dts: {
12
+ entry: ["src/index.ts", "src/langchain.ts", "src/langgraph.ts"],
13
+ },
14
+ minify: false,
15
+ external: [],
16
+ sourcemap: true,
17
+ entryNames: "[name]",
18
+ exclude: [
19
+ "**/*.test.ts", // Exclude TypeScript test files
20
+ "**/*.test.tsx", // Exclude TypeScript React test files
21
+ "**/__tests__/*", // Exclude any files inside a __tests__ directory
22
+ ],
23
+ }));
package/typedoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": ["../../typedoc.base.json"],
3
+ "entryPoints": ["src/index.ts"]
4
+ }