@langgraph-js/sdk 1.6.4 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.env +0 -0
  2. package/.turbo/turbo-build.log +5 -0
  3. package/LICENSE +201 -201
  4. package/README.md +163 -163
  5. package/dist/LangGraphClient.d.ts +2 -0
  6. package/dist/LangGraphClient.js +11 -0
  7. package/dist/server/createState.d.ts +13 -0
  8. package/dist/server/createState.js +20 -0
  9. package/dist/server/feTools.d.ts +16 -0
  10. package/dist/server/feTools.js +37 -0
  11. package/dist/server/index.d.ts +3 -0
  12. package/dist/server/index.js +3 -0
  13. package/dist/server/interrupt/index.d.ts +23 -0
  14. package/dist/server/interrupt/index.js +36 -0
  15. package/dist/server/swarm/handoff.d.ts +11 -0
  16. package/dist/server/swarm/handoff.js +84 -0
  17. package/dist/server/swarm/keepState.d.ts +6 -0
  18. package/dist/server/swarm/keepState.js +21 -0
  19. package/dist/server/tools/index.d.ts +1 -0
  20. package/dist/server/tools/index.js +1 -0
  21. package/dist/server/tools/sequential-thinking.d.ts +52 -0
  22. package/dist/server/tools/sequential-thinking.js +69 -0
  23. package/dist/server/utils.d.ts +3 -0
  24. package/dist/server/utils.js +24 -0
  25. package/dist/ui-store/createChatStore.d.ts +1 -0
  26. package/dist/ui-store/createChatStore.js +4 -0
  27. package/package.json +1 -1
  28. package/src/LangGraphClient.ts +657 -646
  29. package/src/SpendTime.ts +60 -60
  30. package/src/ToolManager.ts +131 -131
  31. package/src/index.ts +5 -5
  32. package/src/tool/ToolUI.ts +41 -41
  33. package/src/tool/copilotkit-actions.ts +72 -72
  34. package/src/tool/createTool.ts +102 -102
  35. package/src/tool/index.ts +3 -3
  36. package/src/tool/utils.ts +158 -158
  37. package/src/ui-store/UnionStore.ts +29 -29
  38. package/src/ui-store/createChatStore.ts +298 -294
  39. package/src/ui-store/index.ts +2 -2
  40. package/src/ui-store/rafDebounce.ts +29 -29
  41. package/test/testResponse.json +5418 -5418
  42. package/tsconfig.json +112 -112
@@ -0,0 +1,52 @@
1
+ import { z } from "zod";
2
+ export declare const SequentialThinkingTool: import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
3
+ thought: z.ZodString;
4
+ nextThoughtNeeded: z.ZodBoolean;
5
+ thoughtNumber: z.ZodNumber;
6
+ totalThoughts: z.ZodNumber;
7
+ isRevision: z.ZodOptional<z.ZodBoolean>;
8
+ revisesThought: z.ZodOptional<z.ZodNumber>;
9
+ branchFromThought: z.ZodOptional<z.ZodNumber>;
10
+ branchId: z.ZodOptional<z.ZodString>;
11
+ needsMoreThoughts: z.ZodOptional<z.ZodBoolean>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ thought: string;
14
+ nextThoughtNeeded: boolean;
15
+ thoughtNumber: number;
16
+ totalThoughts: number;
17
+ isRevision?: boolean | undefined;
18
+ revisesThought?: number | undefined;
19
+ branchFromThought?: number | undefined;
20
+ branchId?: string | undefined;
21
+ needsMoreThoughts?: boolean | undefined;
22
+ }, {
23
+ thought: string;
24
+ nextThoughtNeeded: boolean;
25
+ thoughtNumber: number;
26
+ totalThoughts: number;
27
+ isRevision?: boolean | undefined;
28
+ revisesThought?: number | undefined;
29
+ branchFromThought?: number | undefined;
30
+ branchId?: string | undefined;
31
+ needsMoreThoughts?: boolean | undefined;
32
+ }>, {
33
+ thought: string;
34
+ nextThoughtNeeded: boolean;
35
+ thoughtNumber: number;
36
+ totalThoughts: number;
37
+ isRevision?: boolean | undefined;
38
+ revisesThought?: number | undefined;
39
+ branchFromThought?: number | undefined;
40
+ branchId?: string | undefined;
41
+ needsMoreThoughts?: boolean | undefined;
42
+ }, {
43
+ thought: string;
44
+ nextThoughtNeeded: boolean;
45
+ thoughtNumber: number;
46
+ totalThoughts: number;
47
+ isRevision?: boolean | undefined;
48
+ revisesThought?: number | undefined;
49
+ branchFromThought?: number | undefined;
50
+ branchId?: string | undefined;
51
+ needsMoreThoughts?: boolean | undefined;
52
+ }, string>;
@@ -0,0 +1,69 @@
1
+ import { tool } from "@langchain/core/tools";
2
+ import { z } from "zod";
3
+ const schema = z.object({
4
+ thought: z.string().describe("Your current thinking step"),
5
+ nextThoughtNeeded: z.boolean().describe("Whether another thought step is needed"),
6
+ thoughtNumber: z.number().min(1).describe("Current thought number"),
7
+ totalThoughts: z.number().min(1).describe("Estimated total thoughts needed"),
8
+ isRevision: z.boolean().optional().describe("Whether this revises previous thinking"),
9
+ revisesThought: z.number().min(1).optional().describe("Which thought is being reconsidered"),
10
+ branchFromThought: z.number().min(1).optional().describe("Branching point thought number"),
11
+ branchId: z.string().optional().describe("Branch identifier"),
12
+ needsMoreThoughts: z.boolean().optional().describe("If more thoughts are needed"),
13
+ });
14
+ // 存储思考历史
15
+ const thoughtHistory = [];
16
+ const branches = {};
17
+ export const SequentialThinkingTool = tool(async (args) => {
18
+ try {
19
+ if (args.thoughtNumber > args.totalThoughts) {
20
+ args.totalThoughts = args.thoughtNumber;
21
+ }
22
+ thoughtHistory.push(args);
23
+ if (args.branchFromThought && args.branchId) {
24
+ if (!branches[args.branchId]) {
25
+ branches[args.branchId] = [];
26
+ }
27
+ branches[args.branchId].push(args);
28
+ }
29
+ return JSON.stringify({
30
+ thoughtNumber: args.thoughtNumber,
31
+ totalThoughts: args.totalThoughts,
32
+ nextThoughtNeeded: args.nextThoughtNeeded,
33
+ branches: Object.keys(branches),
34
+ thoughtHistoryLength: thoughtHistory.length,
35
+ }, null, 2);
36
+ }
37
+ catch (error) {
38
+ return JSON.stringify({
39
+ error: error instanceof Error ? error.message : String(error),
40
+ status: "failed",
41
+ }, null, 2);
42
+ }
43
+ }, {
44
+ name: "sequential-thinking",
45
+ description: `A detailed tool for dynamic and reflective problem-solving through thoughts.
46
+ This tool helps analyze problems through a flexible thinking process that can adapt and evolve.
47
+ Each thought can build on, question, or revise previous insights as understanding deepens.
48
+
49
+ When to use this tool:
50
+ - Breaking down complex problems into steps
51
+ - Planning and design with room for revision
52
+ - Analysis that might need course correction
53
+ - Problems where the full scope might not be clear initially
54
+ - Problems that require a multi-step solution
55
+ - Tasks that need to maintain context over multiple steps
56
+ - Situations where irrelevant information needs to be filtered out
57
+
58
+ Key features:
59
+ - You can adjust total_thoughts up or down as you progress
60
+ - You can question or revise previous thoughts
61
+ - You can add more thoughts even after reaching what seemed like the end
62
+ - You can express uncertainty and explore alternative approaches
63
+ - Not every thought needs to build linearly - you can branch or backtrack
64
+ - Generates a solution hypothesis
65
+ - Verifies the hypothesis based on the Chain of Thought steps
66
+ - Repeats the process until satisfied
67
+ - Provides a correct answer`,
68
+ schema,
69
+ });
@@ -0,0 +1,3 @@
1
+ import { BaseMessage, HumanMessage } from "@langchain/core/messages";
2
+ export declare const getTextMessageContent: (message: BaseMessage) => string;
3
+ export declare function getLastHumanMessage(messages: BaseMessage[]): HumanMessage | undefined;
@@ -0,0 +1,24 @@
1
+ import { isHumanMessage } from "@langchain/core/messages";
2
+ export const getTextMessageContent = (message) => {
3
+ if (typeof message.content === "string") {
4
+ return message.content;
5
+ }
6
+ else {
7
+ return message.content
8
+ .filter((i) => i.type === "text")
9
+ .map((i) => i.text)
10
+ .join("\n");
11
+ }
12
+ };
13
+ export function getLastHumanMessage(messages) {
14
+ // 从后往前遍历消息列表
15
+ for (let i = messages.length - 1; i >= 0; i--) {
16
+ const message = messages[i];
17
+ // 检查消息是否是 HumanMessage 的实例
18
+ if (isHumanMessage(message)) {
19
+ return message;
20
+ }
21
+ }
22
+ // 如果没有找到 HumanMessage,则返回 undefined
23
+ return undefined;
24
+ }
@@ -47,6 +47,7 @@ export declare const createChatStore: (initClientName: string, config: LangGraph
47
47
  currentNodeName: import("nanostores").PreinitializedWritableAtom<string> & object;
48
48
  };
49
49
  mutations: {
50
+ isFELocking(): boolean | undefined;
50
51
  initClient: () => Promise<LangGraphClient>;
51
52
  sendMessage: (message?: Message[], extraData?: SendMessageOptions) => Promise<void>;
52
53
  stopGeneration: () => void;
@@ -215,6 +215,10 @@ export const createChatStore = (initClientName, config, context = {}) => {
215
215
  currentNodeName,
216
216
  },
217
217
  mutations: {
218
+ isFELocking() {
219
+ var _a;
220
+ return (_a = client.get()) === null || _a === void 0 ? void 0 : _a.isFELocking(renderMessages.get());
221
+ },
218
222
  initClient,
219
223
  sendMessage,
220
224
  stopGeneration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langgraph-js/sdk",
3
- "version": "1.6.4",
3
+ "version": "1.7.0",
4
4
  "description": "The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",