Skip to content

Commit ec50f8c

Browse files
committed
[NEB-231] Show Image response in Nebula, minor refactor (#6964)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the chat functionality in the `nebula-app` by introducing support for image messages and refactoring the message history structure. It also adds new components for image handling and feedback actions. ### Detailed summary - Added `request_id` to action messages in `Chats.stories.tsx`. - Introduced `NebulaSessionHistoryMessage` type in `types.ts`. - Updated `history` in `SessionInfo` to use `NebulaSessionHistoryMessage`. - Implemented image message handling in `chat.ts`. - Refactored `promptNebula` to include `request_id`. - Created `NebulaImage` component for rendering images. - Added `MessageActions` component for user feedback. - Refactored `ChatPageContent` to utilize new message parsing logic. - Updated message rendering in `Chats` to support image types. - Removed redundant code for message handling in `ChatPageContent`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 3315a53 commit ec50f8c

File tree

7 files changed

+554
-291
lines changed

7 files changed

+554
-291
lines changed

apps/dashboard/src/app/nebula-app/(app)/api/chat.ts

+35
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ export async function promptNebula(params: {
9999
break;
100100
}
101101

102+
case "image": {
103+
const data = JSON.parse(event.data) as {
104+
data: {
105+
width: number;
106+
height: number;
107+
url: string;
108+
};
109+
request_id: string;
110+
};
111+
112+
params.handleStream({
113+
event: "image",
114+
data: data.data,
115+
request_id: data.request_id,
116+
});
117+
break;
118+
}
119+
102120
case "action": {
103121
const data = JSON.parse(event.data);
104122

@@ -109,6 +127,7 @@ export async function promptNebula(params: {
109127
event: "action",
110128
type: "sign_transaction",
111129
data: parsedTxData,
130+
request_id: data.request_id,
112131
});
113132
} catch (e) {
114133
console.error("failed to parse action data", e, { event });
@@ -122,6 +141,7 @@ export async function promptNebula(params: {
122141
event: "action",
123142
type: "sign_swap",
124143
data: swapData,
144+
request_id: data.request_id,
125145
});
126146
} catch (e) {
127147
console.error("failed to parse action data", e, { event });
@@ -197,11 +217,22 @@ type ChatStreamedResponse =
197217
event: "action";
198218
type: "sign_transaction";
199219
data: NebulaTxData;
220+
request_id: string;
200221
}
201222
| {
202223
event: "action";
203224
type: "sign_swap";
204225
data: NebulaSwapData;
226+
request_id: string;
227+
}
228+
| {
229+
event: "image";
230+
data: {
231+
width: number;
232+
height: number;
233+
url: string;
234+
};
235+
request_id: string;
205236
}
206237
| {
207238
event: "context";
@@ -225,6 +256,10 @@ type ChatStreamedEvent =
225256
event: "delta";
226257
data: string;
227258
}
259+
| {
260+
event: "image";
261+
data: string;
262+
}
228263
| {
229264
event: "action";
230265
type: "sign_transaction" | "sign_swap";

apps/dashboard/src/app/nebula-app/(app)/api/types.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ type SessionContextFilter = {
33
wallet_address: string | null;
44
};
55

6+
export type NebulaSessionHistoryMessage = {
7+
role: "user" | "assistant" | "action" | "image";
8+
content: string;
9+
timestamp: number;
10+
};
11+
612
export type SessionInfo = {
713
id: string;
814
account_id: string;
@@ -11,11 +17,7 @@ export type SessionInfo = {
1117
can_execute: boolean;
1218
created_at: string;
1319
deleted_at: string | null;
14-
history: Array<{
15-
role: "user" | "assistant" | "action";
16-
content: string;
17-
timestamp: number;
18-
}> | null;
20+
history: Array<NebulaSessionHistoryMessage> | null;
1921
updated_at: string;
2022
archived_at: string | null;
2123
title: string | null;

0 commit comments

Comments
 (0)