@langgraph-js/sdk 3.8.1 → 3.8.3

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/dist/History.d.ts CHANGED
@@ -111,5 +111,7 @@ export declare class History {
111
111
  * @zh 初始化 History(必须先调用)
112
112
  * @en Initializes History (must be called first)
113
113
  */
114
- init(agentName?: string): Promise<import("@langchain/langgraph-sdk").Assistant | undefined>;
114
+ init(agentName?: string, config?: {
115
+ fallbackToAvailableAssistants?: boolean;
116
+ }): Promise<import("@langchain/langgraph-sdk").Assistant | undefined>;
115
117
  }
package/dist/History.js CHANGED
@@ -220,7 +220,7 @@ export class History {
220
220
  * @zh 初始化 History(必须先调用)
221
221
  * @en Initializes History (must be called first)
222
222
  */
223
- async init(agentName) {
224
- return this.virtualClient.initAssistant(agentName);
223
+ async init(agentName, config) {
224
+ return this.virtualClient.initAssistant(agentName, config);
225
225
  }
226
226
  }
@@ -54,7 +54,7 @@ export type InterruptData = {
54
54
  }[];
55
55
  reviewConfigs: {
56
56
  actionName: string;
57
- allowedDecisions: ("approve" | "edit" | "reject")[];
57
+ allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
58
58
  }[];
59
59
  };
60
60
  }[];
@@ -145,10 +145,7 @@ export declare class LangGraphClient<TStateType = unknown> extends EventEmitter<
145
145
  /** 代理 assistants 属性到内部 client */
146
146
  get assistants(): {
147
147
  search(query?: {
148
- graphId? /**
149
- * The maximum number of concurrent calls that can be made.
150
- * Defaults to `Infinity`, which means no limit.
151
- */: string;
148
+ graphId?: string;
152
149
  metadata?: import("@langchain/langgraph-sdk").Metadata;
153
150
  limit?: number;
154
151
  offset?: number;
@@ -80,6 +80,7 @@ export declare class MessageProcessor {
80
80
  messages: RenderMessage[];
81
81
  }>;
82
82
  }, messagesMetadata?: Record<string, any>): RenderMessage[];
83
+ private beforeFold;
83
84
  /**
84
85
  * @zh 统一的消息处理入口,按顺序执行所有处理步骤
85
86
  * @en Unified message processing entry point, executing all processing steps in order
@@ -264,21 +264,25 @@ export class MessageProcessor {
264
264
  if (rootMessage.type === "tool" && childrenMap.has(rootMessage.tool_call_id)) {
265
265
  rootMessage.sub_messages.unshift(...childrenMap.get(rootMessage.tool_call_id));
266
266
  // 根据 id 去重
267
- rootMessage.sub_messages = rootMessage.sub_messages.filter((i, index, self) => self.findIndex((t) => t.id === i.id) === index);
267
+ const sub_messages = rootMessage.sub_messages.filter((i, index, self) => self.findIndex((t) => t.id === i.id) === index);
268
+ rootMessage.sub_messages = this.beforeFold(sub_messages);
268
269
  }
269
270
  }
270
271
  return rootMessages;
271
272
  }
273
+ beforeFold(messages) {
274
+ // 1. 组合工具消息
275
+ const composedMessages = this.composeToolMessages(messages);
276
+ // 2. 附加信息
277
+ const messagesWithInfo = this.attachInfoForMessage(composedMessages);
278
+ return messagesWithInfo;
279
+ }
272
280
  /**
273
281
  * @zh 统一的消息处理入口,按顺序执行所有处理步骤
274
282
  * @en Unified message processing entry point, executing all processing steps in order
275
283
  */
276
284
  processMessages(messages, graphState, messagesMetadata) {
277
- // 1. 组合工具消息
278
- const composedMessages = this.composeToolMessages(messages);
279
- // 2. 附加信息
280
- const messagesWithInfo = this.attachInfoForMessage(composedMessages);
281
285
  // 3. 折叠树状消息(如果提供了 messagesMetadata)
282
- return this.foldTreeMessages(messagesWithInfo, graphState, messagesMetadata);
286
+ return this.foldTreeMessages(this.beforeFold(messages), graphState, messagesMetadata);
283
287
  }
284
288
  }
@@ -24,13 +24,13 @@ export declare class ToolRenderData<I, D> {
24
24
  }[];
25
25
  reviewConfigs: {
26
26
  actionName: string;
27
- allowedDecisions: ("approve" | "edit" | "reject")[];
27
+ allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
28
28
  }[];
29
29
  };
30
30
  };
31
31
  reviewConfig: {
32
32
  actionName: string;
33
- allowedDecisions: ("approve" | "edit" | "reject")[];
33
+ allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
34
34
  };
35
35
  actionRequest: {
36
36
  name: string;
@@ -93,7 +93,7 @@ export const createChatStore = (initClientName, config, context = {}) => {
93
93
  ...config,
94
94
  client: config.client ?? (await createLangGraphServerClient(config)),
95
95
  });
96
- await historyManager.init(currentAgent.get());
96
+ await historyManager.init(currentAgent.get(), { fallbackToAvailableAssistants: context.fallbackToAvailableAssistants });
97
97
  history.set(historyManager);
98
98
  // 同步远程会话列表
99
99
  await refreshSessionList();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langgraph-js/sdk",
3
- "version": "3.8.1",
3
+ "version": "3.8.3",
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",
package/src/History.ts CHANGED
@@ -288,7 +288,7 @@ export class History {
288
288
  * @zh 初始化 History(必须先调用)
289
289
  * @en Initializes History (must be called first)
290
290
  */
291
- async init(agentName?: string) {
292
- return this.virtualClient.initAssistant(agentName);
291
+ async init(agentName?: string, config?: { fallbackToAvailableAssistants?: boolean }) {
292
+ return this.virtualClient.initAssistant(agentName, config);
293
293
  }
294
294
  }
@@ -55,7 +55,7 @@ export type InterruptData = {
55
55
  }[];
56
56
  reviewConfigs: {
57
57
  actionName: string;
58
- allowedDecisions: ("approve" | "edit" | "reject")[];
58
+ allowedDecisions: ("approve" | "edit" | "reject" | "respond")[];
59
59
  }[];
60
60
  };
61
61
  }[];
@@ -307,23 +307,26 @@ export class MessageProcessor {
307
307
  if (rootMessage.type === "tool" && childrenMap.has(rootMessage.tool_call_id)) {
308
308
  rootMessage.sub_messages.unshift(...childrenMap.get(rootMessage.tool_call_id)!);
309
309
  // 根据 id 去重
310
- rootMessage.sub_messages = rootMessage.sub_messages.filter((i, index, self) => self.findIndex((t) => t.id === i.id) === index);
310
+ const sub_messages = rootMessage.sub_messages.filter((i, index, self) => self.findIndex((t) => t.id === i.id) === index);
311
+ rootMessage.sub_messages = this.beforeFold(sub_messages);
311
312
  }
312
313
  }
313
314
  return rootMessages;
314
315
  }
315
- /**
316
- * @zh 统一的消息处理入口,按顺序执行所有处理步骤
317
- * @en Unified message processing entry point, executing all processing steps in order
318
- */
319
- processMessages(messages: RenderMessage[], graphState?: any, messagesMetadata?: Record<string, any>): RenderMessage[] {
316
+ private beforeFold(messages: RenderMessage[]) {
320
317
  // 1. 组合工具消息
321
318
  const composedMessages = this.composeToolMessages(messages);
322
319
 
323
320
  // 2. 附加信息
324
321
  const messagesWithInfo = this.attachInfoForMessage(composedMessages);
325
-
322
+ return messagesWithInfo;
323
+ }
324
+ /**
325
+ * @zh 统一的消息处理入口,按顺序执行所有处理步骤
326
+ * @en Unified message processing entry point, executing all processing steps in order
327
+ */
328
+ processMessages(messages: RenderMessage[], graphState?: any, messagesMetadata?: Record<string, any>): RenderMessage[] {
326
329
  // 3. 折叠树状消息(如果提供了 messagesMetadata)
327
- return this.foldTreeMessages(messagesWithInfo, graphState, messagesMetadata);
330
+ return this.foldTreeMessages(this.beforeFold(messages), graphState, messagesMetadata);
328
331
  }
329
332
  }
@@ -124,7 +124,7 @@ export const createChatStore = (initClientName: string, config: Partial<LangGrap
124
124
  ...config,
125
125
  client: config.client ?? (await createLangGraphServerClient(config as LangGraphClientConfig)),
126
126
  });
127
- await historyManager.init(currentAgent.get());
127
+ await historyManager.init(currentAgent.get(), { fallbackToAvailableAssistants: context.fallbackToAvailableAssistants });
128
128
  history.set(historyManager);
129
129
 
130
130
  // 同步远程会话列表