@langgraph-js/sdk 4.3.5 → 4.3.7

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.
@@ -390,7 +390,7 @@ export class LangGraphClient extends EventEmitter {
390
390
  additional_kwargs: {},
391
391
  };
392
392
  // json 校验
393
- return this.callFETool(toolMessage, tool.args);
393
+ return this.callFETool(toolMessage, tool.args).catch((e) => console.warn(e));
394
394
  });
395
395
  console.log("batch call tools", result.length);
396
396
  // 只有当卡住流程时,才改变状态为 interrupted
@@ -70,6 +70,7 @@ interface ChatProviderProps {
70
70
  apiUrl?: string;
71
71
  defaultHeaders?: Record<string, string>;
72
72
  withCredentials?: boolean;
73
+ fetch?: typeof fetch;
73
74
  showHistory?: boolean;
74
75
  showGraph?: boolean;
75
76
  fallbackToAvailableAssistants?: boolean;
@@ -9,7 +9,7 @@ export const useChat = () => {
9
9
  }
10
10
  return context;
11
11
  };
12
- export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://localhost:8123", defaultHeaders, withCredentials = false, showHistory = false, showGraph = false, fallbackToAvailableAssistants = false, autoRestoreLastSession = false, onInitError, client, legacyMode = false, }) => {
12
+ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://localhost:8123", defaultHeaders, withCredentials = false, fetch, showHistory = false, showGraph = false, fallbackToAvailableAssistants = false, autoRestoreLastSession = false, onInitError, client, legacyMode = false, }) => {
13
13
  // 使用 useMemo 稳定 defaultHeaders 的引用
14
14
  const stableHeaders = useMemo(() => defaultHeaders || {}, [defaultHeaders]);
15
15
  // 使用 useRef 保存 onInitError 的最新引用
@@ -18,12 +18,13 @@ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://loc
18
18
  onInitErrorRef.current = onInitError;
19
19
  }, [onInitError]);
20
20
  const store = useMemo(() => {
21
+ const baseFetch = fetch || globalThis.fetch;
21
22
  const F = withCredentials
22
23
  ? (url, options) => {
23
24
  options.credentials = "include";
24
- return fetch(url, options);
25
+ return baseFetch(url, options);
25
26
  }
26
- : fetch;
27
+ : baseFetch;
27
28
  const config = {
28
29
  apiUrl,
29
30
  defaultHeaders: stableHeaders,
@@ -42,7 +43,7 @@ export const ChatProvider = ({ children, defaultAgent = "", apiUrl = "http://loc
42
43
  fallbackToAvailableAssistants,
43
44
  autoRestoreLastSession,
44
45
  });
45
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
46
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
46
47
  const unionStore = useUnionStore(store, useStore);
47
48
  // 使用 ref 标记是否已初始化
48
49
  const initializedRef = useRef(false);
@@ -70,6 +70,7 @@ interface ChatProviderProps {
70
70
  apiUrl?: string;
71
71
  defaultHeaders?: Record<string, string>;
72
72
  withCredentials?: boolean;
73
+ fetch?: typeof fetch;
73
74
  showHistory?: boolean;
74
75
  showGraph?: boolean;
75
76
  fallbackToAvailableAssistants?: boolean;
@@ -26,12 +26,15 @@ export const ChatProvider = (props) => {
26
26
  // 使用 createMemo 稳定 defaultHeaders 的引用
27
27
  const stableHeaders = createMemo(() => props.defaultHeaders || {});
28
28
  // 使用 createMemo 创建 fetch 函数
29
- const F = createMemo(() => props.withCredentials
30
- ? (url, options) => {
31
- options.credentials = "include";
32
- return fetch(url, options);
33
- }
34
- : fetch);
29
+ const F = createMemo(() => {
30
+ const baseFetch = props.fetch || globalThis.fetch;
31
+ return props.withCredentials
32
+ ? (url, options) => {
33
+ options.credentials = "include";
34
+ return baseFetch(url, options);
35
+ }
36
+ : baseFetch;
37
+ });
35
38
  const store = createMemo(() => {
36
39
  const config = {
37
40
  apiUrl: props.apiUrl || "http://localhost:8123",
@@ -29,6 +29,8 @@ export const getMessageContent = (content) => {
29
29
  return item.text;
30
30
  if (item.type === "image_url")
31
31
  return `[图片]`;
32
+ if (item.type === "tool_use")
33
+ return "";
32
34
  return JSON.stringify(item);
33
35
  })
34
36
  .join("");
@@ -30,6 +30,7 @@ export interface ChatProviderProps {
30
30
  apiUrl?: string;
31
31
  defaultHeaders?: Record<string, string>;
32
32
  withCredentials?: boolean;
33
+ fetch?: typeof fetch;
33
34
  showHistory?: boolean;
34
35
  showGraph?: boolean;
35
36
  fallbackToAvailableAssistants?: boolean;
@@ -129,6 +130,10 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
129
130
  type: PropType<boolean>;
130
131
  default: boolean;
131
132
  };
133
+ fetch: {
134
+ type: PropType<typeof fetch>;
135
+ default: undefined;
136
+ };
132
137
  showHistory: {
133
138
  type: PropType<boolean>;
134
139
  default: boolean;
@@ -164,6 +169,10 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
164
169
  type: PropType<boolean>;
165
170
  default: boolean;
166
171
  };
172
+ fetch: {
173
+ type: PropType<typeof fetch>;
174
+ default: undefined;
175
+ };
167
176
  showHistory: {
168
177
  type: PropType<boolean>;
169
178
  default: boolean;
@@ -187,6 +196,7 @@ export declare const ChatProvider: import("vue").DefineComponent<import("vue").E
187
196
  showHistory: boolean;
188
197
  defaultAgent: string;
189
198
  withCredentials: boolean;
199
+ fetch: typeof fetch;
190
200
  autoRestoreLastSession: boolean;
191
201
  onInitError: (error: any, currentAgent: string) => void;
192
202
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
@@ -32,12 +32,13 @@ export const useChat = () => {
32
32
  * @en Chat Provider Hook, used directly in setup
33
33
  */
34
34
  export const useChatProvider = (props) => {
35
+ const baseFetch = props.fetch || globalThis.fetch;
35
36
  const F = props.withCredentials
36
37
  ? (url, options) => {
37
38
  options.credentials = "include";
38
- return fetch(url, options);
39
+ return baseFetch(url, options);
39
40
  }
40
- : fetch;
41
+ : baseFetch;
41
42
  const store = createChatStore(props.defaultAgent || "", {
42
43
  apiUrl: props.apiUrl,
43
44
  defaultHeaders: props.defaultHeaders,
@@ -92,6 +93,10 @@ export const ChatProvider = defineComponent({
92
93
  type: Boolean,
93
94
  default: false,
94
95
  },
96
+ fetch: {
97
+ type: Function,
98
+ default: undefined,
99
+ },
95
100
  showHistory: {
96
101
  type: Boolean,
97
102
  default: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langgraph-js/sdk",
3
- "version": "4.3.5",
3
+ "version": "4.3.7",
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",
@@ -510,7 +510,7 @@ export class LangGraphClient<TStateType = unknown> extends EventEmitter<LangGrap
510
510
  additional_kwargs: {},
511
511
  };
512
512
  // json 校验
513
- return this.callFETool(toolMessage, tool.args);
513
+ return this.callFETool(toolMessage, tool.args).catch((e) => console.warn(e));
514
514
  });
515
515
  console.log("batch call tools", result.length);
516
516
  // 只有当卡住流程时,才改变状态为 interrupted
@@ -20,6 +20,7 @@ interface ChatProviderProps {
20
20
  apiUrl?: string;
21
21
  defaultHeaders?: Record<string, string>;
22
22
  withCredentials?: boolean;
23
+ fetch?: typeof fetch;
23
24
  showHistory?: boolean;
24
25
  showGraph?: boolean;
25
26
  fallbackToAvailableAssistants?: boolean;
@@ -36,6 +37,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
36
37
  apiUrl = "http://localhost:8123",
37
38
  defaultHeaders,
38
39
  withCredentials = false,
40
+ fetch,
39
41
  showHistory = false,
40
42
  showGraph = false,
41
43
  fallbackToAvailableAssistants = false,
@@ -54,12 +56,13 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
54
56
  }, [onInitError]);
55
57
 
56
58
  const store = useMemo(() => {
59
+ const baseFetch = fetch || globalThis.fetch;
57
60
  const F = withCredentials
58
61
  ? (url: string, options: RequestInit) => {
59
62
  options.credentials = "include";
60
- return fetch(url, options);
63
+ return baseFetch(url, options);
61
64
  }
62
- : fetch;
65
+ : baseFetch;
63
66
 
64
67
  const config = {
65
68
  apiUrl,
@@ -78,7 +81,7 @@ export const ChatProvider: React.FC<ChatProviderProps> = ({
78
81
  fallbackToAvailableAssistants,
79
82
  autoRestoreLastSession,
80
83
  });
81
- }, [defaultAgent, apiUrl, stableHeaders, withCredentials, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
84
+ }, [defaultAgent, apiUrl, stableHeaders, withCredentials, fetch, showHistory, showGraph, fallbackToAvailableAssistants, autoRestoreLastSession]);
82
85
 
83
86
  const unionStore = useUnionStore(store, useStore);
84
87
 
@@ -20,6 +20,7 @@ interface ChatProviderProps {
20
20
  apiUrl?: string;
21
21
  defaultHeaders?: Record<string, string>;
22
22
  withCredentials?: boolean;
23
+ fetch?: typeof fetch;
23
24
  showHistory?: boolean;
24
25
  showGraph?: boolean;
25
26
  fallbackToAvailableAssistants?: boolean;
@@ -62,14 +63,15 @@ export const ChatProvider = (props: ChatProviderProps) => {
62
63
  const stableHeaders = createMemo(() => props.defaultHeaders || {});
63
64
 
64
65
  // 使用 createMemo 创建 fetch 函数
65
- const F = createMemo(() =>
66
- props.withCredentials
66
+ const F = createMemo(() => {
67
+ const baseFetch = props.fetch || globalThis.fetch;
68
+ return props.withCredentials
67
69
  ? (url: string, options: RequestInit) => {
68
70
  options.credentials = "include";
69
- return fetch(url, options);
71
+ return baseFetch(url, options);
70
72
  }
71
- : fetch
72
- );
73
+ : baseFetch;
74
+ });
73
75
 
74
76
  const store = createMemo(() => {
75
77
  const config = {
@@ -33,6 +33,7 @@ export const getMessageContent = (content: any) => {
33
33
  if (typeof item === "string") return item;
34
34
  if (item.type === "text") return item.text;
35
35
  if (item.type === "image_url") return `[图片]`;
36
+ if (item.type === "tool_use") return "";
36
37
  return JSON.stringify(item);
37
38
  })
38
39
  .join("");
@@ -52,6 +52,7 @@ export interface ChatProviderProps {
52
52
  apiUrl?: string;
53
53
  defaultHeaders?: Record<string, string>;
54
54
  withCredentials?: boolean;
55
+ fetch?: typeof fetch;
55
56
  showHistory?: boolean;
56
57
  showGraph?: boolean;
57
58
  fallbackToAvailableAssistants?: boolean;
@@ -67,12 +68,13 @@ export interface ChatProviderProps {
67
68
  * @en Chat Provider Hook, used directly in setup
68
69
  */
69
70
  export const useChatProvider = (props: ChatProviderProps) => {
71
+ const baseFetch = props.fetch || globalThis.fetch;
70
72
  const F = props.withCredentials
71
73
  ? (url: string, options: RequestInit) => {
72
74
  options.credentials = "include";
73
- return fetch(url, options);
75
+ return baseFetch(url, options);
74
76
  }
75
- : fetch;
77
+ : baseFetch;
76
78
 
77
79
  const store = createChatStore(
78
80
  props.defaultAgent || "",
@@ -137,6 +139,10 @@ export const ChatProvider = defineComponent({
137
139
  type: Boolean as PropType<boolean>,
138
140
  default: false,
139
141
  },
142
+ fetch: {
143
+ type: Function as PropType<typeof fetch>,
144
+ default: undefined,
145
+ },
140
146
  showHistory: {
141
147
  type: Boolean as PropType<boolean>,
142
148
  default: false,