@langgraph-js/sdk 3.7.1 → 3.8.1

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.
@@ -22,6 +22,9 @@ export interface UnionTool<Args extends ZodRawShape, Child extends Object = Obje
22
22
  isPureParams?: boolean;
23
23
  }
24
24
  export type ToolCallback<Args extends ZodRawShape> = (args: z.infer<z.ZodObject<Args>>, context?: any) => CallToolResult | Promise<CallToolResult>;
25
+ /**
26
+ * HumanInTheLoop 的标准回复格式
27
+ */
25
28
  export type InterruptResponse = {
26
29
  decisions: ({
27
30
  type: "approve";
@@ -33,7 +36,7 @@ export type InterruptResponse = {
33
36
  };
34
37
  } | {
35
38
  type: "reject";
36
- message: string;
39
+ message?: string;
37
40
  })[];
38
41
  };
39
42
  export type CallToolResult = string | {
@@ -170,10 +173,10 @@ export declare const createMCPTool: <Args extends ZodRawShape>(tool: UnionTool<A
170
173
  }[];
171
174
  isError?: undefined;
172
175
  } | {
173
- content: {
176
+ content: InterruptResponse | {
174
177
  type: "text";
175
178
  text: string;
176
- }[] | InterruptResponse | undefined;
179
+ }[] | undefined;
177
180
  isError?: undefined;
178
181
  } | {
179
182
  content: {
@@ -2,109 +2,76 @@ import { LangGraphClient, LangGraphClientConfig, RenderMessage, SendMessageOptio
2
2
  import { AssistantGraph, Message, Thread } from "@langchain/langgraph-sdk";
3
3
  import { UnionTool } from "../tool/createTool.js";
4
4
  import { RevertChatToOptions } from "../time-travel/index.js";
5
- /**
6
- * @zh 格式化日期对象为时间字符串。
7
- * @en Formats a Date object into a time string.
8
- */
5
+ import { History, SessionInfo } from "../History.js";
9
6
  export declare const formatTime: (date: Date) => string;
10
- /**
11
- * @zh 格式化数字为带千位分隔符的字符串。
12
- * @en Formats a number into a string with thousand separators.
13
- */
14
7
  export declare const formatTokens: (tokens: number) => string;
15
- /**
16
- * @zh 获取消息内容的文本表示,处理不同类型的消息内容。
17
- * @en Gets the text representation of message content, handling different types of message content.
18
- */
19
8
  export declare const getMessageContent: (content: any) => string;
20
- /**
21
- * @zh 获取历史记录中 Thread 内容的文本表示。
22
- * @en Gets the text representation of Thread content in history.
23
- */
24
9
  export declare const getHistoryContent: (thread: Thread) => string | any[];
25
- /**
26
- * @zh 创建一个用于聊天界面的状态管理器 (store)。
27
- * @en Creates a state manager (store) for the chat interface.
28
- */
29
- export declare const createChatStore: (initClientName: string, config: Partial<LangGraphClientConfig>, context?: {
10
+ interface ChatStoreContext {
30
11
  showHistory?: boolean;
31
12
  showGraph?: boolean;
32
13
  fallbackToAvailableAssistants?: boolean;
33
14
  onInit?: (client: LangGraphClient) => void;
34
- }) => {
15
+ /** 初始化时是否自动激活最近的历史会话(默认 false,创建新会话) */
16
+ autoRestoreLastSession?: boolean;
17
+ }
18
+ export declare const createChatStore: (initClientName: string, config: Partial<LangGraphClientConfig>, context?: ChatStoreContext) => {
35
19
  data: {
36
20
  artifacts: import("nanostores").PreinitializedWritableAtom<import("../artifacts/index.js").ComposedArtifact[]> & object;
37
21
  currentArtifactId: import("nanostores").PreinitializedWritableAtom<[string, string] | null> & object;
38
22
  showArtifact: import("nanostores").PreinitializedWritableAtom<boolean> & object;
39
23
  client: import("nanostores").PreinitializedWritableAtom<LangGraphClient<unknown> | null> & object;
24
+ history: import("nanostores").PreinitializedWritableAtom<History | null> & object;
25
+ sessions: import("nanostores").PreinitializedWritableAtom<SessionInfo[]> & object;
40
26
  renderMessages: import("nanostores").PreinitializedWritableAtom<RenderMessage[]> & object;
41
27
  userInput: import("nanostores").PreinitializedWritableAtom<string> & object;
42
28
  loading: import("nanostores").PreinitializedWritableAtom<boolean> & object;
43
29
  inChatError: import("nanostores").PreinitializedWritableAtom<string | null> & object;
44
30
  currentAgent: import("nanostores").PreinitializedWritableAtom<string> & object;
31
+ currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
32
+ currentNodeName: import("nanostores").PreinitializedWritableAtom<string> & object;
33
+ tools: import("nanostores").PreinitializedWritableAtom<UnionTool<any, Object, any>[]> & object;
45
34
  collapsedTools: import("nanostores").PreinitializedWritableAtom<string[]> & object;
35
+ showGraph: import("nanostores").PreinitializedWritableAtom<boolean> & object;
36
+ graphVisualize: import("nanostores").PreinitializedWritableAtom<AssistantGraph | null> & object;
46
37
  showHistory: import("nanostores").PreinitializedWritableAtom<boolean> & object;
47
38
  historyList: import("nanostores").PreinitializedWritableAtom<Thread<{
48
39
  messages: Message[];
49
40
  }>[]> & object;
50
- currentChatId: import("nanostores").PreinitializedWritableAtom<string | null> & object;
51
- showGraph: import("nanostores").PreinitializedWritableAtom<boolean> & object;
52
- graphVisualize: import("nanostores").PreinitializedWritableAtom<AssistantGraph | null> & object;
53
- currentNodeName: import("nanostores").PreinitializedWritableAtom<string> & object;
54
- tools: import("nanostores").PreinitializedWritableAtom<UnionTool<any, Object, any>[]> & object;
55
41
  };
56
42
  mutations: {
57
43
  setCurrentArtifactById: (id: string, tool_id: string) => void;
58
44
  setShowArtifact: (show: boolean) => void;
59
- refreshTools: () => Promise<void>;
60
- setTools(new_tools: UnionTool<any>[]): void;
61
- isFELocking(): boolean | undefined;
62
- getClient(): LangGraphClient<unknown> | null;
63
- initClient: () => Promise<LangGraphClient<unknown>>;
45
+ initClient: () => Promise<History>;
46
+ getClient: () => LangGraphClient<unknown> | null;
47
+ getHistory: () => History | null;
48
+ activateSession: (sessionId: string) => Promise<void>;
49
+ createNewSession: () => Promise<void>;
50
+ refreshSessionList: () => Promise<void>;
51
+ refreshHistoryList: () => Promise<void>;
64
52
  sendMessage: (message?: Message[], extraData?: SendMessageOptions, withoutCheck?: boolean) => Promise<void>;
65
53
  stopGeneration: () => void;
54
+ setUserInput: (input: string) => void;
55
+ revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions & RevertChatToOptions): Promise<void>;
56
+ refreshTools: () => Promise<void>;
57
+ setTools(new_tools: UnionTool<any>[]): void;
66
58
  toggleToolCollapse: (toolId: string) => void;
59
+ getToolUIRender: (tool_name: string) => ((message: RenderMessage) => Object) | null;
60
+ isFELocking: () => boolean | undefined;
67
61
  toggleHistoryVisible: () => void;
68
- refreshHistoryList: () => Promise<void>;
62
+ toggleGraphVisible(): void;
63
+ refreshGraph: () => Promise<void>;
64
+ setCurrentAgent(agent: string): Promise<History>;
69
65
  addToHistory: (thread: Thread<{
70
66
  messages: Message[];
71
67
  }>) => void;
72
- /**
73
- * @zh 回滚到指定的消息。
74
- * @en Reverts to the specified message.
75
- */
76
- revertChatTo(messageId: string, resend?: boolean, sendOptions?: SendMessageOptions & RevertChatToOptions): Promise<void>;
77
- /**
78
- * @zh 设置用户输入内容。
79
- * @en Sets the user input content.
80
- */
81
- setUserInput(input: string): void;
82
- /**
83
- * @zh 设置当前的 Agent 并重新初始化客户端。
84
- * @en Sets the current Agent and reinitializes the client.
85
- */
86
- setCurrentAgent(agent: string): Promise<void>;
87
- toggleGraphVisible(): void;
88
- refreshGraph: () => Promise<void>;
89
- /**
90
- * @zh 创建一个新的聊天会话。
91
- * @en Creates a new chat session.
92
- */
93
- createNewChat(): void;
94
- /**
95
- * @zh 切换到指定的历史聊天会话。
96
- * @en Switches to the specified historical chat session.
97
- */
98
- toHistoryChat(thread: Thread<{
68
+ createNewChat: () => Promise<void>;
69
+ toHistoryChat: (thread: Thread<{
99
70
  messages: Message[];
100
- }>): Promise<Thread<unknown> | undefined>;
101
- /**
102
- * @zh 删除指定的历史聊天会话。
103
- * @en Deletes the specified historical chat session.
104
- */
71
+ }>) => Promise<void>;
105
72
  deleteHistoryChat(thread: Thread<{
106
73
  messages: Message[];
107
74
  }>): Promise<void>;
108
- getToolUIRender: (tool_name: string) => ((message: RenderMessage) => Object) | null;
109
75
  };
110
76
  };
77
+ export {};