@langgraph-js/sdk 1.7.5 → 1.7.9
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/LICENSE +201 -201
- package/README.md +163 -163
- package/dist/LangGraphClient.d.ts +0 -1
- package/dist/LangGraphClient.js +9 -5
- package/dist/ToolManager.d.ts +1 -1
- package/dist/ToolManager.js +2 -1
- package/dist/tool/ToolUI.d.ts +5 -6
- package/dist/tool/ToolUI.js +0 -12
- package/dist/tool/createTool.d.ts +7 -3
- package/dist/ui-store/createChatStore.js +0 -3
- package/package.json +1 -2
- package/src/LangGraphClient.ts +656 -655
- package/src/SpendTime.ts +60 -60
- package/src/ToolManager.ts +132 -131
- package/src/index.ts +5 -5
- package/src/tool/ToolUI.ts +41 -51
- package/src/tool/copilotkit-actions.ts +72 -72
- package/src/tool/createTool.ts +104 -102
- package/src/tool/index.ts +3 -3
- package/src/tool/utils.ts +158 -158
- package/src/ui-store/UnionStore.ts +29 -29
- package/src/ui-store/createChatStore.ts +295 -298
- package/src/ui-store/index.ts +2 -2
- package/src/ui-store/rafDebounce.ts +29 -29
- package/test/testResponse.json +5418 -5418
- package/tsconfig.json +112 -112
- package/.env +0 -0
- package/.turbo/turbo-build.log +0 -5
- package/dist/server/createState.d.ts +0 -13
- package/dist/server/createState.js +0 -20
- package/dist/server/feTools.d.ts +0 -16
- package/dist/server/feTools.js +0 -37
- package/dist/server/index.d.ts +0 -3
- package/dist/server/index.js +0 -3
- package/dist/server/interrupt/index.d.ts +0 -23
- package/dist/server/interrupt/index.js +0 -36
- package/dist/server/swarm/handoff.d.ts +0 -11
- package/dist/server/swarm/handoff.js +0 -84
- package/dist/server/swarm/keepState.d.ts +0 -6
- package/dist/server/swarm/keepState.js +0 -21
- package/dist/server/tools/index.d.ts +0 -1
- package/dist/server/tools/index.js +0 -1
- package/dist/server/tools/sequential-thinking.d.ts +0 -52
- package/dist/server/tools/sequential-thinking.js +0 -69
- package/dist/server/utils.d.ts +0 -3
- package/dist/server/utils.js +0 -24
package/README.md
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
# @langgraph-js/sdk
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
> The missing UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
|
|
7
|
-
|
|
8
|
-
## Why @langgraph-js/sdk?
|
|
9
|
-
|
|
10
|
-
Building AI agent applications is complex, especially when you need to bridge the gap between LangGraph agents and interactive user interfaces. This SDK solves the critical challenges of frontend integration:
|
|
11
|
-
|
|
12
|
-
- **Provides a complete UI integration layer** - no more complex custom code to handle tools, streaming, and state management
|
|
13
|
-
- **Simplifies human-in-the-loop interactions** - easily incorporate user feedback within agent workflows
|
|
14
|
-
- **Handles edge cases automatically** - interruptions, errors, token management and more
|
|
15
|
-
- **Offers a rich set of UI components** - ready-to-use elements to display agent interactions
|
|
16
|
-
|
|
17
|
-
[DOCS](https://langgraph-js.netlify.app)
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
# Using npm
|
|
23
|
-
npm install @langgraph-js/sdk
|
|
24
|
-
|
|
25
|
-
# Using yarn
|
|
26
|
-
yarn add @langgraph-js/sdk
|
|
27
|
-
|
|
28
|
-
# Using pnpm
|
|
29
|
-
pnpm add @langgraph-js/sdk
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Key Features
|
|
33
|
-
|
|
34
|
-
### Generative UI
|
|
35
|
-
|
|
36
|
-
- ✅ Custom Tool Messages
|
|
37
|
-
- ✅ Token Counter
|
|
38
|
-
- ✅ Stop Graph Progress
|
|
39
|
-
- ✅ Interrupt Handling
|
|
40
|
-
- ✅ Error Handling
|
|
41
|
-
- ✅ Spend Time Tracking
|
|
42
|
-
- ✅ Time Persistence
|
|
43
|
-
|
|
44
|
-
### Frontend Actions
|
|
45
|
-
|
|
46
|
-
- ✅ Definition of Union Tools
|
|
47
|
-
- ✅ Frontend Functions As Tools
|
|
48
|
-
- ✅ Human-in-the-Loop Interaction
|
|
49
|
-
- ✅ Interrupt Mode
|
|
50
|
-
|
|
51
|
-
### Authorization
|
|
52
|
-
|
|
53
|
-
- ✅ Cookie-Based Authentication
|
|
54
|
-
- ✅ Custom Token Authentication
|
|
55
|
-
|
|
56
|
-
### Persistence
|
|
57
|
-
|
|
58
|
-
- ✅ Read History from LangGraph
|
|
59
|
-
|
|
60
|
-
## Advanced Usage
|
|
61
|
-
|
|
62
|
-
### Creating a Chat Store
|
|
63
|
-
|
|
64
|
-
You can easily create a reactive store for your LangGraph client:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { createChatStore } from "@langgraph-js/sdk";
|
|
68
|
-
|
|
69
|
-
export const globalChatStore = createChatStore(
|
|
70
|
-
"agent",
|
|
71
|
-
{
|
|
72
|
-
// Custom LangGraph backend interaction
|
|
73
|
-
apiUrl: "http://localhost:8123",
|
|
74
|
-
// Custom headers for authentication
|
|
75
|
-
defaultHeaders: JSON.parse(localStorage.getItem("code") || "{}"),
|
|
76
|
-
callerOptions: {
|
|
77
|
-
// Example for including cookies
|
|
78
|
-
// fetch(url: string, options: RequestInit) {
|
|
79
|
-
// options.credentials = "include";
|
|
80
|
-
// return fetch(url, options);
|
|
81
|
-
// },
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
onInit(client) {
|
|
86
|
-
client.tools.bindTools([]);
|
|
87
|
-
},
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### React Integration
|
|
93
|
-
|
|
94
|
-
First, install the nanostores React integration:
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
pnpm i @nanostores/react
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Then create a context provider for your chat:
|
|
101
|
-
|
|
102
|
-
```tsx
|
|
103
|
-
import React, { createContext, useContext, useEffect } from "react";
|
|
104
|
-
import { globalChatStore } from "../store"; // Import your store
|
|
105
|
-
import { UnionStore, useUnionStore } from "@langgraph-js/sdk";
|
|
106
|
-
import { useStore } from "@nanostores/react";
|
|
107
|
-
|
|
108
|
-
type ChatContextType = UnionStore<typeof globalChatStore>;
|
|
109
|
-
|
|
110
|
-
const ChatContext = createContext<ChatContextType | undefined>(undefined);
|
|
111
|
-
|
|
112
|
-
export const useChat = () => {
|
|
113
|
-
const context = useContext(ChatContext);
|
|
114
|
-
if (!context) {
|
|
115
|
-
throw new Error("useChat must be used within a ChatProvider");
|
|
116
|
-
}
|
|
117
|
-
return context;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export const ChatProvider = ({ children }) => {
|
|
121
|
-
// Use store to ensure React gets reactive state updates
|
|
122
|
-
const store = useUnionStore(globalChatStore, useStore);
|
|
123
|
-
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
// Initialize client
|
|
126
|
-
store.initClient().then(() => {
|
|
127
|
-
// Initialize conversation history
|
|
128
|
-
store.refreshHistoryList();
|
|
129
|
-
});
|
|
130
|
-
}, [store.currentAgent]);
|
|
131
|
-
|
|
132
|
-
return <ChatContext.Provider value={store}>{children}</ChatContext.Provider>;
|
|
133
|
-
};
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Use it in your components:
|
|
137
|
-
|
|
138
|
-
```tsx
|
|
139
|
-
export const MyChat = () => {
|
|
140
|
-
return (
|
|
141
|
-
<ChatProvider>
|
|
142
|
-
<ChatComp></ChatComp>
|
|
143
|
-
</ChatProvider>
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
function ChatComp() {
|
|
148
|
-
const chat = useChat();
|
|
149
|
-
// Use chat store methods and state here
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Documentation
|
|
154
|
-
|
|
155
|
-
For complete documentation, visit our [official docs](https://langgraph-js.netlify.app).
|
|
156
|
-
|
|
157
|
-
## Contributing
|
|
158
|
-
|
|
159
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
160
|
-
|
|
161
|
-
## License
|
|
162
|
-
|
|
163
|
-
This project is licensed under the Apache-2.0 License.
|
|
1
|
+
# @langgraph-js/sdk
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
> The missing UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
|
|
7
|
+
|
|
8
|
+
## Why @langgraph-js/sdk?
|
|
9
|
+
|
|
10
|
+
Building AI agent applications is complex, especially when you need to bridge the gap between LangGraph agents and interactive user interfaces. This SDK solves the critical challenges of frontend integration:
|
|
11
|
+
|
|
12
|
+
- **Provides a complete UI integration layer** - no more complex custom code to handle tools, streaming, and state management
|
|
13
|
+
- **Simplifies human-in-the-loop interactions** - easily incorporate user feedback within agent workflows
|
|
14
|
+
- **Handles edge cases automatically** - interruptions, errors, token management and more
|
|
15
|
+
- **Offers a rich set of UI components** - ready-to-use elements to display agent interactions
|
|
16
|
+
|
|
17
|
+
[DOCS](https://langgraph-js.netlify.app)
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using npm
|
|
23
|
+
npm install @langgraph-js/sdk
|
|
24
|
+
|
|
25
|
+
# Using yarn
|
|
26
|
+
yarn add @langgraph-js/sdk
|
|
27
|
+
|
|
28
|
+
# Using pnpm
|
|
29
|
+
pnpm add @langgraph-js/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Key Features
|
|
33
|
+
|
|
34
|
+
### Generative UI
|
|
35
|
+
|
|
36
|
+
- ✅ Custom Tool Messages
|
|
37
|
+
- ✅ Token Counter
|
|
38
|
+
- ✅ Stop Graph Progress
|
|
39
|
+
- ✅ Interrupt Handling
|
|
40
|
+
- ✅ Error Handling
|
|
41
|
+
- ✅ Spend Time Tracking
|
|
42
|
+
- ✅ Time Persistence
|
|
43
|
+
|
|
44
|
+
### Frontend Actions
|
|
45
|
+
|
|
46
|
+
- ✅ Definition of Union Tools
|
|
47
|
+
- ✅ Frontend Functions As Tools
|
|
48
|
+
- ✅ Human-in-the-Loop Interaction
|
|
49
|
+
- ✅ Interrupt Mode
|
|
50
|
+
|
|
51
|
+
### Authorization
|
|
52
|
+
|
|
53
|
+
- ✅ Cookie-Based Authentication
|
|
54
|
+
- ✅ Custom Token Authentication
|
|
55
|
+
|
|
56
|
+
### Persistence
|
|
57
|
+
|
|
58
|
+
- ✅ Read History from LangGraph
|
|
59
|
+
|
|
60
|
+
## Advanced Usage
|
|
61
|
+
|
|
62
|
+
### Creating a Chat Store
|
|
63
|
+
|
|
64
|
+
You can easily create a reactive store for your LangGraph client:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { createChatStore } from "@langgraph-js/sdk";
|
|
68
|
+
|
|
69
|
+
export const globalChatStore = createChatStore(
|
|
70
|
+
"agent",
|
|
71
|
+
{
|
|
72
|
+
// Custom LangGraph backend interaction
|
|
73
|
+
apiUrl: "http://localhost:8123",
|
|
74
|
+
// Custom headers for authentication
|
|
75
|
+
defaultHeaders: JSON.parse(localStorage.getItem("code") || "{}"),
|
|
76
|
+
callerOptions: {
|
|
77
|
+
// Example for including cookies
|
|
78
|
+
// fetch(url: string, options: RequestInit) {
|
|
79
|
+
// options.credentials = "include";
|
|
80
|
+
// return fetch(url, options);
|
|
81
|
+
// },
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
onInit(client) {
|
|
86
|
+
client.tools.bindTools([]);
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### React Integration
|
|
93
|
+
|
|
94
|
+
First, install the nanostores React integration:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pnpm i @nanostores/react
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then create a context provider for your chat:
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import React, { createContext, useContext, useEffect } from "react";
|
|
104
|
+
import { globalChatStore } from "../store"; // Import your store
|
|
105
|
+
import { UnionStore, useUnionStore } from "@langgraph-js/sdk";
|
|
106
|
+
import { useStore } from "@nanostores/react";
|
|
107
|
+
|
|
108
|
+
type ChatContextType = UnionStore<typeof globalChatStore>;
|
|
109
|
+
|
|
110
|
+
const ChatContext = createContext<ChatContextType | undefined>(undefined);
|
|
111
|
+
|
|
112
|
+
export const useChat = () => {
|
|
113
|
+
const context = useContext(ChatContext);
|
|
114
|
+
if (!context) {
|
|
115
|
+
throw new Error("useChat must be used within a ChatProvider");
|
|
116
|
+
}
|
|
117
|
+
return context;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const ChatProvider = ({ children }) => {
|
|
121
|
+
// Use store to ensure React gets reactive state updates
|
|
122
|
+
const store = useUnionStore(globalChatStore, useStore);
|
|
123
|
+
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
// Initialize client
|
|
126
|
+
store.initClient().then(() => {
|
|
127
|
+
// Initialize conversation history
|
|
128
|
+
store.refreshHistoryList();
|
|
129
|
+
});
|
|
130
|
+
}, [store.currentAgent]);
|
|
131
|
+
|
|
132
|
+
return <ChatContext.Provider value={store}>{children}</ChatContext.Provider>;
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Use it in your components:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
export const MyChat = () => {
|
|
140
|
+
return (
|
|
141
|
+
<ChatProvider>
|
|
142
|
+
<ChatComp></ChatComp>
|
|
143
|
+
</ChatProvider>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function ChatComp() {
|
|
148
|
+
const chat = useChat();
|
|
149
|
+
// Use chat store methods and state here
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Documentation
|
|
154
|
+
|
|
155
|
+
For complete documentation, visit our [official docs](https://langgraph-js.netlify.app).
|
|
156
|
+
|
|
157
|
+
## Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
This project is licensed under the Apache-2.0 License.
|
package/dist/LangGraphClient.js
CHANGED
|
@@ -162,7 +162,7 @@ export class LangGraphClient extends Client {
|
|
|
162
162
|
const closedToolCallIds = new Set();
|
|
163
163
|
const result = [];
|
|
164
164
|
const inputMessages = this.combineGraphMessagesWithStreamingMessages();
|
|
165
|
-
|
|
165
|
+
console.log(inputMessages);
|
|
166
166
|
// 从后往前遍历,这样可以保证最新的消息在前面
|
|
167
167
|
for (let i = inputMessages.length - 1; i >= 0; i--) {
|
|
168
168
|
const message = this.cloneMessage(inputMessages[i]);
|
|
@@ -226,13 +226,17 @@ export class LangGraphClient extends Client {
|
|
|
226
226
|
let lastMessage = null;
|
|
227
227
|
for (const message of result) {
|
|
228
228
|
const createTime = ((_a = message.response_metadata) === null || _a === void 0 ? void 0 : _a.create_time) || "";
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
try {
|
|
230
|
+
// 用长度作为渲染 id,长度变了就要重新渲染
|
|
231
|
+
message.unique_id = message.id + JSON.stringify(message.content).length;
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
message.unique_id = message.id;
|
|
235
|
+
}
|
|
231
236
|
message.spend_time = new Date(createTime).getTime() - new Date(((_b = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.response_metadata) === null || _b === void 0 ? void 0 : _b.create_time) || createTime).getTime();
|
|
232
237
|
if (!message.usage_metadata && ((_c = message.response_metadata) === null || _c === void 0 ? void 0 : _c.usage)) {
|
|
233
238
|
const usage = message.response_metadata.usage;
|
|
234
239
|
message.usage_metadata = {
|
|
235
|
-
...usage,
|
|
236
240
|
input_tokens: usage.prompt_tokens,
|
|
237
241
|
output_tokens: usage.completion_tokens,
|
|
238
242
|
total_tokens: usage.total_tokens,
|
|
@@ -384,7 +388,7 @@ export class LangGraphClient extends Client {
|
|
|
384
388
|
...this.extraParams,
|
|
385
389
|
...(extraParams || {}),
|
|
386
390
|
messages: messagesToSend,
|
|
387
|
-
fe_tools: this.tools.toJSON(),
|
|
391
|
+
fe_tools: this.tools.toJSON(this.currentAssistant.graph_id),
|
|
388
392
|
},
|
|
389
393
|
streamMode: ["messages", "values"],
|
|
390
394
|
streamSubgraphs: true,
|
package/dist/ToolManager.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare class ToolManager {
|
|
|
52
52
|
* @zh 将所有工具转换为 JSON 定义格式。
|
|
53
53
|
* @en Converts all tools to JSON definition format.
|
|
54
54
|
*/
|
|
55
|
-
toJSON(remote?: boolean): {
|
|
55
|
+
toJSON(graphId: string, remote?: boolean): {
|
|
56
56
|
name: string;
|
|
57
57
|
description: string;
|
|
58
58
|
parameters: import("zod-to-json-schema").JsonSchema7Type & {
|
package/dist/ToolManager.js
CHANGED
|
@@ -76,9 +76,10 @@ export class ToolManager {
|
|
|
76
76
|
* @zh 将所有工具转换为 JSON 定义格式。
|
|
77
77
|
* @en Converts all tools to JSON definition format.
|
|
78
78
|
*/
|
|
79
|
-
toJSON(remote = true) {
|
|
79
|
+
toJSON(graphId, remote = true) {
|
|
80
80
|
return Array.from(this.tools.values())
|
|
81
81
|
.filter((i) => (remote ? !i.onlyRender : true))
|
|
82
|
+
.filter((i) => !i.allowGraph || i.allowGraph.includes(graphId))
|
|
82
83
|
.map((i) => createJSONDefineTool(i));
|
|
83
84
|
}
|
|
84
85
|
/**
|
package/dist/tool/ToolUI.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { RenderMessage } from "../LangGraphClient.js";
|
|
2
2
|
import { LangGraphClient } from "../LangGraphClient.js";
|
|
3
|
-
export declare class ToolRenderData<
|
|
3
|
+
export declare class ToolRenderData<D> {
|
|
4
4
|
message: RenderMessage;
|
|
5
5
|
client: LangGraphClient;
|
|
6
6
|
constructor(message: RenderMessage, client: LangGraphClient);
|
|
7
|
-
get state(): "idle" | "done"
|
|
8
|
-
get input():
|
|
7
|
+
get state(): "idle" | "done";
|
|
8
|
+
get input(): any;
|
|
9
9
|
get output(): string;
|
|
10
|
-
getJSONOutput():
|
|
10
|
+
getJSONOutput(): any;
|
|
11
11
|
/** 如果解析失败,则返回 null */
|
|
12
|
-
getJSONOutputSafe():
|
|
13
|
-
getInputRepaired(): I | null;
|
|
12
|
+
getJSONOutputSafe(): any;
|
|
14
13
|
response(data: D): void;
|
|
15
14
|
}
|
package/dist/tool/ToolUI.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { getMessageContent } from "../ui-store/createChatStore.js";
|
|
2
|
-
import { jsonrepair } from "jsonrepair";
|
|
3
2
|
export class ToolRenderData {
|
|
4
3
|
constructor(message, client) {
|
|
5
4
|
this.message = message;
|
|
@@ -10,9 +9,6 @@ export class ToolRenderData {
|
|
|
10
9
|
if (this.message.type === "tool" && ((_b = (_a = this.message) === null || _a === void 0 ? void 0 : _a.additional_kwargs) === null || _b === void 0 ? void 0 : _b.done)) {
|
|
11
10
|
return "done";
|
|
12
11
|
}
|
|
13
|
-
if (this.message.tool_input) {
|
|
14
|
-
return "loading";
|
|
15
|
-
}
|
|
16
12
|
return "idle";
|
|
17
13
|
}
|
|
18
14
|
get input() {
|
|
@@ -38,14 +34,6 @@ export class ToolRenderData {
|
|
|
38
34
|
return null;
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
|
-
getInputRepaired() {
|
|
42
|
-
try {
|
|
43
|
-
return JSON.parse(jsonrepair(this.message.tool_input || ""));
|
|
44
|
-
}
|
|
45
|
-
catch (e) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
37
|
response(data) {
|
|
50
38
|
this.client.doneFEToolWaiting(this.message.id, JSON.stringify(data));
|
|
51
39
|
}
|
|
@@ -11,10 +11,12 @@ export interface UnionTool<Args extends ZodRawShape, Child extends Object = Obje
|
|
|
11
11
|
execute: ToolCallback<Args>;
|
|
12
12
|
/** 工具执行成功后触发的附加消息 */
|
|
13
13
|
callbackMessage?: (result: CallToolResult) => Message[];
|
|
14
|
-
render?: <D>(tool: ToolRenderData<
|
|
14
|
+
render?: <D>(tool: ToolRenderData<D>) => Child;
|
|
15
15
|
onlyRender?: boolean;
|
|
16
16
|
/** 只允许指定的 agent 使用该工具,如果未指定,则所有 agent 都可以使用 */
|
|
17
17
|
allowAgent?: string[];
|
|
18
|
+
/** 只允许指定的 Graph 使用该工具 */
|
|
19
|
+
allowGraph?: string[];
|
|
18
20
|
}
|
|
19
21
|
export type ToolCallback<Args extends ZodRawShape> = (args: z.objectOutputType<Args, ZodTypeAny>, context?: any) => CallToolResult | Promise<CallToolResult>;
|
|
20
22
|
export type CallToolResult = string | {
|
|
@@ -54,10 +56,10 @@ export declare const createMCPTool: <Args extends ZodRawShape>(tool: UnionTool<A
|
|
|
54
56
|
}>))[];
|
|
55
57
|
export declare const createToolUI: <Args extends Parameter[] | [] = [], Child extends Object = {}>(tool: Action<Args> & {
|
|
56
58
|
allowAgent?: string[];
|
|
57
|
-
render?: (tool: ToolRenderData<any
|
|
59
|
+
render?: (tool: ToolRenderData<any>) => Child;
|
|
58
60
|
onlyRender?: boolean;
|
|
59
61
|
}) => {
|
|
60
|
-
render: ((tool: ToolRenderData<any
|
|
62
|
+
render: ((tool: ToolRenderData<any>) => Child) | undefined;
|
|
61
63
|
onlyRender: boolean | undefined;
|
|
62
64
|
name: string;
|
|
63
65
|
description: string;
|
|
@@ -69,4 +71,6 @@ export declare const createToolUI: <Args extends Parameter[] | [] = [], Child ex
|
|
|
69
71
|
callbackMessage?: (result: CallToolResult) => Message[];
|
|
70
72
|
/** 只允许指定的 agent 使用该工具,如果未指定,则所有 agent 都可以使用 */
|
|
71
73
|
allowAgent?: string[];
|
|
74
|
+
/** 只允许指定的 Graph 使用该工具 */
|
|
75
|
+
allowGraph?: string[];
|
|
72
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langgraph-js/sdk",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.9",
|
|
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",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@langchain/langgraph-sdk": "^0.0.77",
|
|
33
|
-
"jsonrepair": "^3.12.0",
|
|
34
33
|
"nanostores": "^1.0.1",
|
|
35
34
|
"zod": "^3.25.17",
|
|
36
35
|
"zod-to-json-schema": "^3.24.5"
|