Skip to content

Commit 5c6b2e1

Browse files
better handling ai messages
1 parent 341f49f commit 5c6b2e1

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

examples/nextjs-ai-chatbot/components/messages.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { useApp } from "@/contexts/app";
77
import { useEffect, useRef } from "react";
88
import { useParams } from "next/navigation";
99
import Image from "next/image";
10-
import { GetToolOutput } from "@/utils/helpers";
1110
import ToolsOutput from "./tools";
1211

1312
export default function Messages() {

examples/nextjs-ai-chatbot/contexts/app.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function AppProviderInner({ children }: { children: ReactNode }) {
112112
.then((data) => {
113113
const messages = data.map((message: any) => ({
114114
id: message.id,
115-
role: message.user.id === "ai-bot" ? "assistant" : "user",
115+
role:
116+
message.user.id === "ai-bot" ||
117+
message.message_type === "agent_response"
118+
? "assistant"
119+
: "user",
116120
parts: [
117121
{
118122
type: "text",

packages/node-sdk/src/ai-sdk-helpers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export class AISDKStreamStorage {
8686
await this.streamStorage.sendMessage(channelId, {
8787
text,
8888
userId: this.streamStorage.getBotUserId(),
89+
metadata: {
90+
message_type: "agent_response",
91+
},
8992
});
9093
}
9194
}
@@ -106,6 +109,9 @@ export class AISDKStreamStorage {
106109
toolOutput
107110
)}\n\`\`\``,
108111
userId: this.streamStorage.getBotUserId(),
112+
metadata: {
113+
message_type: "agent_response",
114+
},
109115
});
110116
}
111117
}

0 commit comments

Comments
 (0)