File size: 2,089 Bytes
63522a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
const PREVIEW_SENDING_TEXT = "can you review the readme";
const PREVIEW_SENDING_MULTILINE_TEXT =
"can you review the readme and then update the contributing guide " +
"to match, making sure the setup steps and scripts are consistent " +
"across both files";
const PREVIEW_ERROR_TEXT =
"here's a long message. here's a long message. here's a long message. " +
"here's a long message. here's a long message. here's a long message.";
export function seedPendingChatPreview(conversationId: string): void {
const store = useOptimisticUserMessageStore.getState();
store.clearPendingMessages();
store.enqueuePendingMessage({
conversationId,
text: PREVIEW_SENDING_TEXT,
});
store.enqueuePendingMessage({
conversationId,
text: PREVIEW_SENDING_MULTILINE_TEXT,
});
const errorId = store.enqueuePendingMessage({
conversationId,
text: PREVIEW_ERROR_TEXT,
});
store.markPendingMessageError(errorId, "Failed to send message");
}
export function installPendingChatPreview(): void {
(
window as Window &
typeof globalThis & {
__OH_SEED_PENDING_PREVIEW__?: typeof seedPendingChatPreview;
__OH_CLEAR_PENDING_PREVIEW__?: () => void;
}
).__OH_SEED_PENDING_PREVIEW__ = seedPendingChatPreview;
(
window as Window &
typeof globalThis & {
__OH_CLEAR_PENDING_PREVIEW__?: () => void;
}
).__OH_CLEAR_PENDING_PREVIEW__ = () => {
useOptimisticUserMessageStore.getState().clearPendingMessages();
};
const params = new URLSearchParams(window.location.search);
const preview = params.get("previewPendingChat");
if (!preview) {
return;
}
const conversationId = preview === "true" ? "1" : preview;
const targetPath = `/conversations/${conversationId}`;
if (!window.location.pathname.startsWith(targetPath)) {
window.location.assign(
`${targetPath}?previewPendingChat=${encodeURIComponent(conversationId)}`,
);
return;
}
seedPendingChatPreview(conversationId);
}
|