@kibadist/agentui-ai 0.2.2 → 0.2.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/README.md +40 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm install @kibadist/agentui-ai ai zod
|
|
|
16
16
|
import { openai } from "@ai-sdk/openai";
|
|
17
17
|
import { runAgentLoop } from "@kibadist/agentui-ai";
|
|
18
18
|
|
|
19
|
-
await runAgentLoop({
|
|
19
|
+
const { text, responseMessages } = await runAgentLoop({
|
|
20
20
|
model: openai("gpt-4o"),
|
|
21
21
|
system: "You are a helpful assistant. Use emit_ui_event to render UI.",
|
|
22
22
|
prompt: "Show me a summary of recent sales",
|
|
@@ -28,6 +28,40 @@ await runAgentLoop({
|
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
## Multi-turn conversations
|
|
32
|
+
|
|
33
|
+
Pass `messages` instead of `prompt` to continue a conversation. Use `responseMessages` from the previous turn to build the history.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import type { ModelMessage } from "ai";
|
|
37
|
+
|
|
38
|
+
const history: ModelMessage[] = [];
|
|
39
|
+
|
|
40
|
+
// First turn
|
|
41
|
+
const turn1 = await runAgentLoop({
|
|
42
|
+
model: openai("gpt-4o"),
|
|
43
|
+
system: "You are a helpful assistant.",
|
|
44
|
+
prompt: "Show me recent sales",
|
|
45
|
+
allowedTypes: ["data-table"],
|
|
46
|
+
sessionId: "session-123",
|
|
47
|
+
onUIEvent: (event) => console.log(event),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
history.push({ role: "user", content: "Show me recent sales" }, ...turn1.responseMessages);
|
|
51
|
+
|
|
52
|
+
// Follow-up turn
|
|
53
|
+
history.push({ role: "user", content: "Now filter by region" });
|
|
54
|
+
|
|
55
|
+
const turn2 = await runAgentLoop({
|
|
56
|
+
model: openai("gpt-4o"),
|
|
57
|
+
system: "You are a helpful assistant.",
|
|
58
|
+
messages: history,
|
|
59
|
+
allowedTypes: ["data-table"],
|
|
60
|
+
sessionId: "session-123",
|
|
61
|
+
onUIEvent: (event) => console.log(event),
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
31
65
|
## Using different providers
|
|
32
66
|
|
|
33
67
|
```ts
|
|
@@ -53,7 +87,7 @@ const model = deepseek("deepseek-chat");
|
|
|
53
87
|
|
|
54
88
|
`runAgentLoop` creates an `emit_ui_event` tool whose Zod schema constrains the agent to only emit your registered component types. It calls the AI SDK's `generateText` with multi-step tool calling — no manual loop, no JSON.parse, no message management.
|
|
55
89
|
|
|
56
|
-
The tool uses a
|
|
90
|
+
The tool uses a flat Zod object schema so the model receives a precise schema for each operation (append, replace, remove, toast, navigate).
|
|
57
91
|
|
|
58
92
|
## Using the tool directly
|
|
59
93
|
|
|
@@ -86,7 +120,8 @@ const { text } = await generateText({
|
|
|
86
120
|
|---|---|---|---|
|
|
87
121
|
| `model` | `LanguageModel` | required | Any AI SDK model instance |
|
|
88
122
|
| `system` | `string` | required | Agent instructions |
|
|
89
|
-
| `prompt` | `string` |
|
|
123
|
+
| `prompt` | `string` | — | Single user prompt (first turn). Ignored when `messages` is provided |
|
|
124
|
+
| `messages` | `ModelMessage[]` | — | Full conversation history (multi-turn). Takes precedence over `prompt` |
|
|
90
125
|
| `allowedTypes` | `string[]` | required | Component types the agent can emit |
|
|
91
126
|
| `sessionId` | `string` | required | Session ID injected into events |
|
|
92
127
|
| `onUIEvent` | `(event: UIEvent) => void` | required | Callback for each emitted UIEvent |
|
|
@@ -149,6 +184,8 @@ await runAgentLoop({
|
|
|
149
184
|
| `createUIEmitterTool` | function | Generate the `emit_ui_event` AI SDK tool |
|
|
150
185
|
| `UI_EMITTER_TOOL_NAME` | constant | `"emit_ui_event"` |
|
|
151
186
|
| `RunAgentLoopOptions` | interface | Options for `runAgentLoop` |
|
|
187
|
+
| `RunAgentLoopResult` | interface | Return type of `runAgentLoop` (`text`, `responseMessages`) |
|
|
188
|
+
| `ResponseMessage` | type | `AssistantModelMessage \| ToolModelMessage` |
|
|
152
189
|
| `CreateUIEmitterToolOptions` | interface | Options for `createUIEmitterTool` |
|
|
153
190
|
|
|
154
191
|
## License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kibadist/agentui-ai",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "AgentUI adapter for Vercel AI SDK — works with any provider (OpenAI, Anthropic, Google, etc.)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@kibadist/agentui-protocol": "0.
|
|
30
|
-
"@kibadist/agentui-validate": "0.
|
|
29
|
+
"@kibadist/agentui-protocol": "0.2.2",
|
|
30
|
+
"@kibadist/agentui-validate": "0.2.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"ai": "^6.0.0",
|