+ )
+}
+
+interface ConversationItemContentProps {
+ content: RealtimeConversationItemContent
+ doScrollIntoView: boolean
+}
+
+const ConversationItemContent = ({
+ content,
+}: ConversationItemContentProps): ReactNode => {
+ if (!["text", "input_text", "input_audio"].includes(content.type)) {
+ // NOTE: we find content.type="audio" coming in here in logging though it is not in the types!
+ if ((content.type as string) !== "audio") {
+ log.warn(
+ `Unexpected type for RealtimeConversationItemContent '${content.type}'. Will not be rendered: %o`,
+ content
+ )
+ }
+ return null
+ }
+
+ return (
+
+ {conversation !== undefined
+ ? "Conversation data not yet available. Start a session and talk and they should appear."
+ : "Conversations not available in this SDK"}
+
+ )}
-
)
}
diff --git a/apps/browser-example/src/pages/WebRTCExample.tsx b/apps/browser-example/src/pages/WebRTCExample.tsx
index 9c598d1..b704a7a 100644
--- a/apps/browser-example/src/pages/WebRTCExample.tsx
+++ b/apps/browser-example/src/pages/WebRTCExample.tsx
@@ -94,6 +94,7 @@ export function WebRTCExample({
stopSession={stopSession}
sessionStatus={sessionStatus}
events={events}
+ conversation={conversation}
/>
)
From f73008e64c8d2168c76a7c70b1bb0c83980c4f7a Mon Sep 17 00:00:00 2001
From: Scott Willeke
Date: Thu, 20 Feb 2025 19:40:43 -0800
Subject: [PATCH 3/3] chore: some cleanup and comments
---
apps/browser-example/src/components/simpleConversation.ts | 6 ++++++
apps/browser-example/src/pages/WebRTCExample.tsx | 2 --
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/apps/browser-example/src/components/simpleConversation.ts b/apps/browser-example/src/components/simpleConversation.ts
index f30f07c..120f66f 100644
--- a/apps/browser-example/src/components/simpleConversation.ts
+++ b/apps/browser-example/src/components/simpleConversation.ts
@@ -11,6 +11,9 @@ type DefinedRealtimeConversationItemType = NonNullable<
RealtimeConversationItem["type"]
>
+/**
+ * A simplified form of @see RealtimeConversationItem for rendering.
+ */
export type RealtimeConversationItemSimple = Pick<
RealtimeConversationItem,
"id"
@@ -20,6 +23,9 @@ export type RealtimeConversationItemSimple = Pick<
content: RealtimeConversationItemContent[]
}
+/**
+ * Simplifies the @see RealtimeConversationItem for rendering purposes. Mostly removes the possibility of `undefined` values in places where they are unlikely (impossible) at render time.
+ */
export function simplifyItem(
item: RealtimeConversationItem
): RealtimeConversationItemSimple {
diff --git a/apps/browser-example/src/pages/WebRTCExample.tsx b/apps/browser-example/src/pages/WebRTCExample.tsx
index b704a7a..b427100 100644
--- a/apps/browser-example/src/pages/WebRTCExample.tsx
+++ b/apps/browser-example/src/pages/WebRTCExample.tsx
@@ -52,12 +52,10 @@ export function WebRTCExample({
setClient(client)
client.addEventListener("serverEvent", (event) => {
- console.debug("serverEvent event:", event)
setEvents((events) => [...events, event.event])
})
client.addEventListener("conversationChanged", (event) => {
- console.debug("conversationChanged event:", event.conversation)
setConversation(event.conversation)
})