mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-23 02:16:08 +00:00
39 lines
960 B
TypeScript
39 lines
960 B
TypeScript
// Client messages match the format used by the Nut protocol.
|
|
|
|
type MessageRole = 'user' | 'assistant';
|
|
|
|
interface MessageBase {
|
|
id: string;
|
|
role: MessageRole;
|
|
repositoryId?: string;
|
|
}
|
|
|
|
interface MessageText extends MessageBase {
|
|
type: 'text';
|
|
content: string;
|
|
}
|
|
|
|
interface MessageImage extends MessageBase {
|
|
type: 'image';
|
|
dataURL: string;
|
|
}
|
|
|
|
export type Message = MessageText | MessageImage;
|
|
|
|
// Get the repositoryId before any changes in the message at the given index.
|
|
export function getPreviousRepositoryId(messages: Message[], index: number): string | undefined {
|
|
for (let i = index - 1; i >= 0; i--) {
|
|
const message = messages[i];
|
|
|
|
if (message.repositoryId) {
|
|
return message.repositoryId;
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
// Get the repositoryId after applying some messages.
|
|
export function getMessagesRepositoryId(messages: Message[]): string | undefined {
|
|
return getPreviousRepositoryId(messages, messages.length);
|
|
}
|