@convai/web-sdk 1.9.0-beta.0 → 1.9.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -43
- package/dist/core/AudioManager.d.ts +0 -1
- package/dist/core/AudioManager.js +0 -1
- package/dist/core/BlendshapeQueue.d.ts +0 -1
- package/dist/core/BlendshapeQueue.js +20 -6
- package/dist/core/CharacterRoster.d.ts +0 -1
- package/dist/core/CharacterRoster.js +0 -1
- package/dist/core/CharacterVersionManager.d.ts +0 -1
- package/dist/core/CharacterVersionManager.js +0 -1
- package/dist/core/ConnectionStateHandler.d.ts +0 -1
- package/dist/core/ConnectionStateHandler.js +5 -2
- package/dist/core/ConvaiClient.d.ts +66 -3
- package/dist/core/ConvaiClient.js +253 -20
- package/dist/core/ConvaiRoomError.d.ts +0 -1
- package/dist/core/ConvaiRoomError.js +20 -2
- package/dist/core/EventEmitter.d.ts +0 -1
- package/dist/core/EventEmitter.js +0 -1
- package/dist/core/MemoryManager.d.ts +0 -1
- package/dist/core/MemoryManager.js +0 -1
- package/dist/core/MessageHandler.d.ts +5 -3
- package/dist/core/MessageHandler.js +125 -47
- package/dist/core/SSESession.d.ts +13 -9
- package/dist/core/SSESession.js +240 -13
- package/dist/core/ScreenShareManager.d.ts +0 -1
- package/dist/core/ScreenShareManager.js +0 -1
- package/dist/core/VideoManager.d.ts +0 -1
- package/dist/core/VideoManager.js +0 -1
- package/dist/core/characterInfo.d.ts +45 -0
- package/dist/core/characterInfo.js +55 -0
- package/dist/core/characterReference.d.ts +0 -1
- package/dist/core/characterReference.js +0 -1
- package/dist/core/connectRequest.d.ts +0 -1
- package/dist/core/connectRequest.js +0 -1
- package/dist/core/contextUpdateRequest.d.ts +0 -1
- package/dist/core/contextUpdateRequest.js +0 -1
- package/dist/core/index.d.ts +6 -1
- package/dist/core/index.js +20 -1
- package/dist/core/logicalTurn.d.ts +0 -1
- package/dist/core/logicalTurn.js +0 -1
- package/dist/core/modelOutput.d.ts +0 -1
- package/dist/core/modelOutput.js +0 -1
- package/dist/core/publishedChat.d.ts +0 -1
- package/dist/core/publishedChat.js +0 -1
- package/dist/core/rosterRequest.d.ts +0 -1
- package/dist/core/rosterRequest.js +0 -1
- package/dist/core/rtviEnvelope.d.ts +5 -0
- package/dist/core/rtviEnvelope.js +9 -0
- package/dist/core/types.d.ts +241 -17
- package/dist/core/types.js +0 -1
- package/dist/core/videoSourceState.d.ts +0 -1
- package/dist/core/videoSourceState.js +0 -1
- package/dist/core/visionRequest.d.ts +0 -1
- package/dist/core/visionRequest.js +0 -1
- package/dist/embed/index.d.ts +20 -3
- package/dist/embed/index.js +20 -3
- package/dist/embed/publicationApi.d.ts +0 -1
- package/dist/embed/publicationApi.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lipsync-helpers/arkitOrder61.d.ts +0 -1
- package/dist/lipsync-helpers/arkitOrder61.js +5 -3
- package/dist/lipsync-helpers/createBlendshapeQueue.d.ts +0 -1
- package/dist/lipsync-helpers/createBlendshapeQueue.js +7 -1
- package/dist/lipsync-helpers/declarativeMapping.d.ts +2 -1
- package/dist/lipsync-helpers/declarativeMapping.js +72 -146
- package/dist/lipsync-helpers/index.d.ts +0 -1
- package/dist/lipsync-helpers/index.js +0 -1
- package/dist/lipsync-helpers/mappingTypes.d.ts +6 -5
- package/dist/lipsync-helpers/mappingTypes.js +0 -1
- package/dist/lipsync-helpers/metahumanOrder251.d.ts +0 -1
- package/dist/lipsync-helpers/metahumanOrder251.js +8 -9
- package/dist/lipsync-helpers/mhaLimitDrivers.d.ts +0 -1
- package/dist/lipsync-helpers/mhaLimitDrivers.js +0 -1
- package/dist/lipsync-helpers/naturalness/processor.d.ts +0 -1
- package/dist/lipsync-helpers/naturalness/processor.js +6 -4
- package/dist/lipsync-helpers/naturalness/profiles/mha.d.ts +0 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.js +0 -1
- package/dist/lipsync-helpers/naturalness/types.d.ts +0 -1
- package/dist/lipsync-helpers/naturalness/types.js +0 -1
- package/dist/lipsync-helpers/presetMappers.d.ts +0 -1
- package/dist/lipsync-helpers/presetMappers.js +0 -1
- package/dist/react/components/ConvaiWidget.d.ts +9 -1
- package/dist/react/components/ConvaiWidget.js +23 -28
- package/dist/react/components/index.d.ts +0 -1
- package/dist/react/components/index.js +0 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js +0 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js +0 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts +4 -2
- package/dist/react/components/rtc-widget/components/ConviMessage.js +2 -3
- package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/FloatingVideo.js +1 -3
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts +21 -4
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js +114 -131
- package/dist/react/components/rtc-widget/components/MessageBubble.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/MessageBubble.js +0 -1
- package/dist/react/components/rtc-widget/components/MessageList.d.ts +4 -2
- package/dist/react/components/rtc-widget/components/MessageList.js +2 -3
- package/dist/react/components/rtc-widget/components/SiteCard.d.ts +14 -0
- package/dist/react/components/rtc-widget/components/SiteCard.js +34 -0
- package/dist/react/components/rtc-widget/components/UserMessage.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js +1 -2
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js +1 -3
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js +1 -3
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js +1 -4
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/index.js +0 -1
- package/dist/react/components/rtc-widget/components/index.d.ts +0 -1
- package/dist/react/components/rtc-widget/components/index.js +0 -1
- package/dist/react/components/rtc-widget/index.d.ts +0 -1
- package/dist/react/components/rtc-widget/index.js +0 -1
- package/dist/react/components/rtc-widget/styles/framerConfig.d.ts +0 -1
- package/dist/react/components/rtc-widget/styles/framerConfig.js +0 -1
- package/dist/react/components/rtc-widget/styles/icons.d.ts +0 -1
- package/dist/react/components/rtc-widget/styles/icons.js +0 -1
- package/dist/react/components/rtc-widget/styles/index.d.ts +0 -1
- package/dist/react/components/rtc-widget/styles/index.js +0 -1
- package/dist/react/components/rtc-widget/styles/styledComponents.d.ts +0 -1
- package/dist/react/components/rtc-widget/styles/styledComponents.js +0 -1
- package/dist/react/components/rtc-widget/styles/theme.d.ts +0 -1
- package/dist/react/components/rtc-widget/styles/theme.js +0 -1
- package/dist/react/components/rtc-widget/types/index.d.ts +0 -1
- package/dist/react/components/rtc-widget/types/index.js +0 -1
- package/dist/react/hooks/index.d.ts +0 -1
- package/dist/react/hooks/index.js +0 -1
- package/dist/react/hooks/useCharacterInfo.d.ts +12 -11
- package/dist/react/hooks/useCharacterInfo.js +49 -50
- package/dist/react/hooks/useConvaiClient.d.ts +0 -1
- package/dist/react/hooks/useConvaiClient.js +8 -5
- package/dist/react/hooks/useLocalCameraTrack.d.ts +0 -1
- package/dist/react/hooks/useLocalCameraTrack.js +0 -1
- package/dist/react/icons.d.ts +37 -0
- package/dist/react/icons.js +53 -0
- package/dist/react/index.d.ts +4 -1
- package/dist/react/index.js +2 -1
- package/dist/utils/inlineMarkdown.d.ts +0 -1
- package/dist/utils/inlineMarkdown.js +0 -1
- package/dist/utils/lightbox.d.ts +15 -0
- package/dist/utils/lightbox.js +94 -0
- package/dist/utils/linkPresentation.d.ts +75 -0
- package/dist/utils/linkPresentation.js +414 -0
- package/dist/utils/linkPreview.d.ts +45 -0
- package/dist/utils/linkPreview.js +71 -0
- package/dist/utils/logger.d.ts +0 -1
- package/dist/utils/logger.js +0 -1
- package/dist/vanilla/AudioRenderer.d.ts +0 -1
- package/dist/vanilla/AudioRenderer.js +0 -1
- package/dist/vanilla/ConvaiWidget.d.ts +0 -1
- package/dist/vanilla/ConvaiWidget.js +302 -226
- package/dist/vanilla/WebSocketSession.d.ts +0 -1
- package/dist/vanilla/WebSocketSession.js +0 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts +0 -1
- package/dist/vanilla/WidgetEventSubscriptions.js +0 -1
- package/dist/vanilla/icons.d.ts +0 -1
- package/dist/vanilla/icons.js +0 -1
- package/dist/vanilla/index.d.ts +4 -1
- package/dist/vanilla/index.js +2 -1
- package/dist/vanilla/styles.d.ts +0 -1
- package/dist/vanilla/styles.js +9 -1
- package/dist/vanilla/types.d.ts +9 -1
- package/dist/vanilla/types.js +0 -1
- package/dist/vanilla/websocket.d.ts +0 -1
- package/dist/vanilla/websocket.js +0 -1
- package/dist/version.d.ts +1 -2
- package/dist/version.js +1 -2
- package/package.json +23 -28
- package/dist/core/AudioManager.d.ts.map +0 -1
- package/dist/core/AudioManager.js.map +0 -1
- package/dist/core/BlendshapeQueue.d.ts.map +0 -1
- package/dist/core/BlendshapeQueue.js.map +0 -1
- package/dist/core/CharacterRoster.d.ts.map +0 -1
- package/dist/core/CharacterRoster.js.map +0 -1
- package/dist/core/CharacterVersionManager.d.ts.map +0 -1
- package/dist/core/CharacterVersionManager.js.map +0 -1
- package/dist/core/ConnectionStateHandler.d.ts.map +0 -1
- package/dist/core/ConnectionStateHandler.js.map +0 -1
- package/dist/core/ConvaiClient.d.ts.map +0 -1
- package/dist/core/ConvaiClient.js.map +0 -1
- package/dist/core/ConvaiRoomError.d.ts.map +0 -1
- package/dist/core/ConvaiRoomError.js.map +0 -1
- package/dist/core/EventEmitter.d.ts.map +0 -1
- package/dist/core/EventEmitter.js.map +0 -1
- package/dist/core/MemoryManager.d.ts.map +0 -1
- package/dist/core/MemoryManager.js.map +0 -1
- package/dist/core/MessageHandler.d.ts.map +0 -1
- package/dist/core/MessageHandler.js.map +0 -1
- package/dist/core/SSESession.d.ts.map +0 -1
- package/dist/core/SSESession.js.map +0 -1
- package/dist/core/ScreenShareManager.d.ts.map +0 -1
- package/dist/core/ScreenShareManager.js.map +0 -1
- package/dist/core/VideoManager.d.ts.map +0 -1
- package/dist/core/VideoManager.js.map +0 -1
- package/dist/core/characterReference.d.ts.map +0 -1
- package/dist/core/characterReference.js.map +0 -1
- package/dist/core/connectRequest.d.ts.map +0 -1
- package/dist/core/connectRequest.js.map +0 -1
- package/dist/core/contextUpdateRequest.d.ts.map +0 -1
- package/dist/core/contextUpdateRequest.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/logicalTurn.d.ts.map +0 -1
- package/dist/core/logicalTurn.js.map +0 -1
- package/dist/core/modelOutput.d.ts.map +0 -1
- package/dist/core/modelOutput.js.map +0 -1
- package/dist/core/publishedChat.d.ts.map +0 -1
- package/dist/core/publishedChat.js.map +0 -1
- package/dist/core/rosterRequest.d.ts.map +0 -1
- package/dist/core/rosterRequest.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/videoSourceState.d.ts.map +0 -1
- package/dist/core/videoSourceState.js.map +0 -1
- package/dist/core/visionRequest.d.ts.map +0 -1
- package/dist/core/visionRequest.js.map +0 -1
- package/dist/embed/ConvaiChatElement.d.ts +0 -103
- package/dist/embed/ConvaiChatElement.d.ts.map +0 -1
- package/dist/embed/ConvaiChatElement.js +0 -679
- package/dist/embed/ConvaiChatElement.js.map +0 -1
- package/dist/embed/browser.d.ts +0 -3
- package/dist/embed/browser.d.ts.map +0 -1
- package/dist/embed/browser.js +0 -5
- package/dist/embed/browser.js.map +0 -1
- package/dist/embed/chat-embed-v1.js +0 -200
- package/dist/embed/chat-embed-v1.js.map +0 -7
- package/dist/embed/index.d.ts.map +0 -1
- package/dist/embed/index.js.map +0 -1
- package/dist/embed/publicationApi.d.ts.map +0 -1
- package/dist/embed/publicationApi.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lipsync-helpers/arkitOrder61.d.ts.map +0 -1
- package/dist/lipsync-helpers/arkitOrder61.js.map +0 -1
- package/dist/lipsync-helpers/createBlendshapeQueue.d.ts.map +0 -1
- package/dist/lipsync-helpers/createBlendshapeQueue.js.map +0 -1
- package/dist/lipsync-helpers/declarativeMapping.d.ts.map +0 -1
- package/dist/lipsync-helpers/declarativeMapping.js.map +0 -1
- package/dist/lipsync-helpers/index.d.ts.map +0 -1
- package/dist/lipsync-helpers/index.js.map +0 -1
- package/dist/lipsync-helpers/mappingTypes.d.ts.map +0 -1
- package/dist/lipsync-helpers/mappingTypes.js.map +0 -1
- package/dist/lipsync-helpers/metahumanOrder251.d.ts.map +0 -1
- package/dist/lipsync-helpers/metahumanOrder251.js.map +0 -1
- package/dist/lipsync-helpers/mhaLimitDrivers.d.ts.map +0 -1
- package/dist/lipsync-helpers/mhaLimitDrivers.js.map +0 -1
- package/dist/lipsync-helpers/naturalness/processor.d.ts.map +0 -1
- package/dist/lipsync-helpers/naturalness/processor.js.map +0 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.d.ts.map +0 -1
- package/dist/lipsync-helpers/naturalness/profiles/mha.js.map +0 -1
- package/dist/lipsync-helpers/naturalness/types.d.ts.map +0 -1
- package/dist/lipsync-helpers/naturalness/types.js.map +0 -1
- package/dist/lipsync-helpers/presetMappers.d.ts.map +0 -1
- package/dist/lipsync-helpers/presetMappers.js.map +0 -1
- package/dist/react/components/ConvaiWidget.d.ts.map +0 -1
- package/dist/react/components/ConvaiWidget.js.map +0 -1
- package/dist/react/components/index.d.ts.map +0 -1
- package/dist/react/components/index.js.map +0 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/AudioSettingsPanel.js.map +0 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/AudioVisualizer.js.map +0 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/ConviMessage.js.map +0 -1
- package/dist/react/components/rtc-widget/components/FloatingVideo.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/FloatingVideo.js.map +0 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/MarkdownRenderer.js.map +0 -1
- package/dist/react/components/rtc-widget/components/MessageBubble.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/MessageBubble.js.map +0 -1
- package/dist/react/components/rtc-widget/components/MessageList.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/MessageList.js.map +0 -1
- package/dist/react/components/rtc-widget/components/UserMessage.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/UserMessage.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviButton.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviFooter.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/ConviHeader.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/SettingsTray.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/VoiceModeOverlay.js.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/index.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/conviComponents/index.js.map +0 -1
- package/dist/react/components/rtc-widget/components/index.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/components/index.js.map +0 -1
- package/dist/react/components/rtc-widget/index.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/index.js.map +0 -1
- package/dist/react/components/rtc-widget/styles/framerConfig.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/styles/framerConfig.js.map +0 -1
- package/dist/react/components/rtc-widget/styles/icons.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/styles/icons.js.map +0 -1
- package/dist/react/components/rtc-widget/styles/index.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/styles/index.js.map +0 -1
- package/dist/react/components/rtc-widget/styles/styledComponents.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/styles/styledComponents.js.map +0 -1
- package/dist/react/components/rtc-widget/styles/theme.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/styles/theme.js.map +0 -1
- package/dist/react/components/rtc-widget/types/index.d.ts.map +0 -1
- package/dist/react/components/rtc-widget/types/index.js.map +0 -1
- package/dist/react/hooks/index.d.ts.map +0 -1
- package/dist/react/hooks/index.js.map +0 -1
- package/dist/react/hooks/useCharacterInfo.d.ts.map +0 -1
- package/dist/react/hooks/useCharacterInfo.js.map +0 -1
- package/dist/react/hooks/useConvaiClient.d.ts.map +0 -1
- package/dist/react/hooks/useConvaiClient.js.map +0 -1
- package/dist/react/hooks/useLocalCameraTrack.d.ts.map +0 -1
- package/dist/react/hooks/useLocalCameraTrack.js.map +0 -1
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js.map +0 -1
- package/dist/utils/inlineMarkdown.d.ts.map +0 -1
- package/dist/utils/inlineMarkdown.js.map +0 -1
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/vanilla/AudioRenderer.d.ts.map +0 -1
- package/dist/vanilla/AudioRenderer.js.map +0 -1
- package/dist/vanilla/ConvaiWidget.d.ts.map +0 -1
- package/dist/vanilla/ConvaiWidget.js.map +0 -1
- package/dist/vanilla/WebSocketSession.d.ts.map +0 -1
- package/dist/vanilla/WebSocketSession.js.map +0 -1
- package/dist/vanilla/WidgetEventSubscriptions.d.ts.map +0 -1
- package/dist/vanilla/WidgetEventSubscriptions.js.map +0 -1
- package/dist/vanilla/icons.d.ts.map +0 -1
- package/dist/vanilla/icons.js.map +0 -1
- package/dist/vanilla/index.d.ts.map +0 -1
- package/dist/vanilla/index.js.map +0 -1
- package/dist/vanilla/styles.d.ts.map +0 -1
- package/dist/vanilla/styles.js.map +0 -1
- package/dist/vanilla/types.d.ts.map +0 -1
- package/dist/vanilla/types.js.map +0 -1
- package/dist/vanilla/websocket.d.ts.map +0 -1
- package/dist/vanilla/websocket.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
package/dist/core/SSESession.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { buildActionConnectConfig, buildEmotionConnectConfig, serializeProtocolCapabilities, } from "./connectRequest.js";
|
|
2
|
+
import { extractModelOutputPayload } from "./modelOutput.js";
|
|
3
|
+
import { unwrapRTVIEvent } from "./rtviEnvelope.js";
|
|
4
|
+
import { isValidLogicalTurnId } from "./logicalTurn.js";
|
|
2
5
|
/** Text-only interaction transport. One POST/SSE stream is used per message. */
|
|
3
6
|
export class SSESession {
|
|
4
7
|
constructor(options) {
|
|
@@ -12,6 +15,9 @@ export class SSESession {
|
|
|
12
15
|
this.botLlmTextFlushTimer = null;
|
|
13
16
|
this.pendingMessages = [];
|
|
14
17
|
this.interruptGeneration = 0;
|
|
18
|
+
this.activeRespondModes = options.respondModes && {
|
|
19
|
+
...options.respondModes,
|
|
20
|
+
};
|
|
15
21
|
}
|
|
16
22
|
get isConnected() {
|
|
17
23
|
return this.connected;
|
|
@@ -30,6 +36,8 @@ export class SSESession {
|
|
|
30
36
|
// finishes or its credential provider yields. Later live selections belong
|
|
31
37
|
// to a later turn and must not rewrite this turn's (possibly null) snapshot.
|
|
32
38
|
const stateOfMind = this.options.takeStateOfMind();
|
|
39
|
+
const ttsEnabled = this.options.ttsEnabled ?? false;
|
|
40
|
+
let requestMessages = messages;
|
|
33
41
|
this.queue = this.queue
|
|
34
42
|
.then(() => {
|
|
35
43
|
if (!this.connected || queuedAtGeneration !== this.interruptGeneration) {
|
|
@@ -39,14 +47,15 @@ export class SSESession {
|
|
|
39
47
|
this.pendingMessages = [];
|
|
40
48
|
const context = messages.filter((message) => message.type === "update-dynamic-info");
|
|
41
49
|
const rest = messages.filter((message) => message.type !== "update-dynamic-info");
|
|
42
|
-
|
|
43
|
-
return this.sendInteraction(requestMessages, stateOfMind).catch((error) => {
|
|
50
|
+
requestMessages = [...context, ...pending, ...rest];
|
|
51
|
+
return this.sendInteraction(requestMessages, stateOfMind, ttsEnabled).catch((error) => {
|
|
44
52
|
throw withSseRequestErrorContext(error, requestMessages, Boolean(this.options.credentialProvider));
|
|
45
53
|
});
|
|
46
54
|
})
|
|
47
55
|
.catch((error) => {
|
|
48
|
-
if (!isSseRequestCancellation(error))
|
|
49
|
-
this.options.onError(error);
|
|
56
|
+
if (!isSseRequestCancellation(error)) {
|
|
57
|
+
this.options.onError(error, sseRequestContext(requestMessages));
|
|
58
|
+
}
|
|
50
59
|
})
|
|
51
60
|
.finally(() => this.options.onResponseFinished?.());
|
|
52
61
|
}
|
|
@@ -57,6 +66,9 @@ export class SSESession {
|
|
|
57
66
|
getDynamicInfo() {
|
|
58
67
|
return this.options.dynamicInfo;
|
|
59
68
|
}
|
|
69
|
+
setTtsEnabled(enabled) {
|
|
70
|
+
this.options.ttsEnabled = enabled;
|
|
71
|
+
}
|
|
60
72
|
/** Carry a silent control update into the next stateless interaction request. */
|
|
61
73
|
queueMessage(type, data) {
|
|
62
74
|
this.pendingMessages.push({ type, data });
|
|
@@ -87,7 +99,7 @@ export class SSESession {
|
|
|
87
99
|
discardQueuedRequestState() {
|
|
88
100
|
this.pendingMessages = [];
|
|
89
101
|
}
|
|
90
|
-
async sendInteraction(messages, stateOfMind) {
|
|
102
|
+
async sendInteraction(messages, stateOfMind, ttsEnabled) {
|
|
91
103
|
const controller = new AbortController();
|
|
92
104
|
this.abortController = controller;
|
|
93
105
|
try {
|
|
@@ -116,6 +128,7 @@ export class SSESession {
|
|
|
116
128
|
},
|
|
117
129
|
body: JSON.stringify({
|
|
118
130
|
character_id: this.options.characterId,
|
|
131
|
+
tts_enabled: ttsEnabled,
|
|
119
132
|
...(connectAttemptId ? { connect_attempt_id: connectAttemptId } : {}),
|
|
120
133
|
...(stateOfMind ? { state_of_mind: stateOfMind } : {}),
|
|
121
134
|
...(characterSessionId && characterSessionId !== "-1"
|
|
@@ -151,8 +164,8 @@ export class SSESession {
|
|
|
151
164
|
...(this.options.sceneDescription && {
|
|
152
165
|
scene_description: this.options.sceneDescription,
|
|
153
166
|
}),
|
|
154
|
-
...(this.
|
|
155
|
-
respond_modes: serializeRespondModes(this.
|
|
167
|
+
...(this.activeRespondModes && {
|
|
168
|
+
respond_modes: serializeRespondModes(this.activeRespondModes),
|
|
156
169
|
}),
|
|
157
170
|
...(this.options.debug !== undefined
|
|
158
171
|
? { debug: this.options.debug }
|
|
@@ -247,6 +260,17 @@ export class SSESession {
|
|
|
247
260
|
let buffer = "";
|
|
248
261
|
let eventType = "message";
|
|
249
262
|
let eventData = [];
|
|
263
|
+
const request = sseRequestContext(messages);
|
|
264
|
+
const pendingTurnIds = new Set(request.logicalTurnIds);
|
|
265
|
+
const hasTrackedTurnIds = pendingTurnIds.size > 0;
|
|
266
|
+
const pendingAcknowledgements = new Set(messages.map((_message, index) => index));
|
|
267
|
+
// A negative server acknowledgement settles only its matching request
|
|
268
|
+
// message. Other response-producing messages carried in this batch still
|
|
269
|
+
// need a terminal (or an SSE error) before EOF can be successful.
|
|
270
|
+
const pendingResponseProducers = new Set(messages.flatMap((message, index) => this.messageStartsTurn(message) ? [index] : []));
|
|
271
|
+
let sawTerminal = false;
|
|
272
|
+
let sawTurnResponse = false;
|
|
273
|
+
let sawError = false;
|
|
250
274
|
const dispatch = () => {
|
|
251
275
|
if (signal.aborted) {
|
|
252
276
|
eventType = "message";
|
|
@@ -270,10 +294,20 @@ export class SSESession {
|
|
|
270
294
|
catch {
|
|
271
295
|
// SSE data is JSON for the interaction API; preserve malformed data for diagnostics.
|
|
272
296
|
}
|
|
297
|
+
this.options.onRawMessage?.({
|
|
298
|
+
transport: "sse",
|
|
299
|
+
byteLength: new TextEncoder().encode(dataText).byteLength,
|
|
300
|
+
message: structuredClone({ type: eventType, data }),
|
|
301
|
+
request: structuredClone(request),
|
|
302
|
+
});
|
|
303
|
+
// A raw listener may synchronously interrupt/disconnect this request.
|
|
304
|
+
if (signal.aborted)
|
|
305
|
+
return;
|
|
273
306
|
if (eventType === "bot-llm-text" &&
|
|
274
307
|
typeof data === "object" &&
|
|
275
308
|
data !== null &&
|
|
276
309
|
typeof data.text === "string") {
|
|
310
|
+
sawTurnResponse = true;
|
|
277
311
|
const payload = data;
|
|
278
312
|
this.queueBotLlmText(payload.text, {
|
|
279
313
|
logical_turn_id: payload.logical_turn_id,
|
|
@@ -284,6 +318,72 @@ export class SSESession {
|
|
|
284
318
|
return;
|
|
285
319
|
}
|
|
286
320
|
this.flushBotLlmText();
|
|
321
|
+
const event = unwrapRTVIEvent(eventType, data);
|
|
322
|
+
if (responseLifecycleStarted(event.type, event.data))
|
|
323
|
+
sawTurnResponse = true;
|
|
324
|
+
const isTerminal = event.type === "bot-turn-completed" || event.type === "llm-no-response";
|
|
325
|
+
let acceptedTerminal = false;
|
|
326
|
+
if (isTerminal
|
|
327
|
+
&& typeof event.data === "object" && event.data !== null && !Array.isArray(event.data)) {
|
|
328
|
+
const terminal = event.data;
|
|
329
|
+
if (!("logical_turn_id" in terminal)) {
|
|
330
|
+
// Older runtimes omit the optional echo. That terminal still completes
|
|
331
|
+
// this request; only an explicitly conflicting echo is rejected.
|
|
332
|
+
sawTerminal = true;
|
|
333
|
+
acceptedTerminal = true;
|
|
334
|
+
pendingTurnIds.clear();
|
|
335
|
+
}
|
|
336
|
+
else if (isValidLogicalTurnId(terminal.logical_turn_id)) {
|
|
337
|
+
if (!hasTrackedTurnIds || pendingTurnIds.has(terminal.logical_turn_id)) {
|
|
338
|
+
sawTerminal = true;
|
|
339
|
+
acceptedTerminal = true;
|
|
340
|
+
pendingTurnIds.delete(terminal.logical_turn_id);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// A rejected terminal is not a successful public completion. Preserve
|
|
345
|
+
// partial output; EOF will report the missing matching terminal.
|
|
346
|
+
if (isTerminal && !acceptedTerminal) {
|
|
347
|
+
eventType = "message";
|
|
348
|
+
eventData = [];
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const acknowledgedIndex = acknowledgedMessageIndex(event.type, event.data, messages, pendingAcknowledgements);
|
|
352
|
+
if (acknowledgedIndex !== undefined) {
|
|
353
|
+
// Final acks consume silent and producing messages alike. Interim
|
|
354
|
+
// acks may confirm generation but must not advance same-type FIFO.
|
|
355
|
+
const response = asRecord(event.data);
|
|
356
|
+
if (response?.status === "success" || response?.status === "error") {
|
|
357
|
+
pendingAcknowledgements.delete(acknowledgedIndex);
|
|
358
|
+
}
|
|
359
|
+
const acknowledgedMessage = messages[acknowledgedIndex];
|
|
360
|
+
const extras = asRecord(response?.extras);
|
|
361
|
+
// Actual generation is authoritative even when an auto/silent hint
|
|
362
|
+
// did not statically promise output. Interim acks do not advance FIFO.
|
|
363
|
+
if (response?.status !== "error"
|
|
364
|
+
&& (extras?.actual_run_llm === "true" || extras?.llm_triggered === true)) {
|
|
365
|
+
pendingResponseProducers.add(acknowledgedIndex);
|
|
366
|
+
}
|
|
367
|
+
const acceptedUpdate = acknowledgedRespondModeUpdate(event.data, acknowledgedMessage);
|
|
368
|
+
if (acceptedUpdate) {
|
|
369
|
+
this.applyRespondModeUpdates([acceptedUpdate]);
|
|
370
|
+
// Accepted mode changes apply to later messages in this ordered
|
|
371
|
+
// batch, not to controls that preceded the mode update.
|
|
372
|
+
for (let index = acknowledgedIndex + 1; index < messages.length; index += 1) {
|
|
373
|
+
if (!pendingAcknowledgements.has(index))
|
|
374
|
+
continue;
|
|
375
|
+
if (this.messageStartsTurn(messages[index]))
|
|
376
|
+
pendingResponseProducers.add(index);
|
|
377
|
+
else
|
|
378
|
+
pendingResponseProducers.delete(index);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (asRecord(event.data)?.status === "error" && pendingResponseProducers.delete(acknowledgedIndex)) {
|
|
382
|
+
if (acknowledgedMessage.type === "user_text_message" && acknowledgedMessage.id) {
|
|
383
|
+
pendingTurnIds.delete(acknowledgedMessage.id);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
287
387
|
if (eventType === "session" || eventType === "done") {
|
|
288
388
|
const sessionId = data
|
|
289
389
|
?.character_session_id;
|
|
@@ -291,10 +391,11 @@ export class SSESession {
|
|
|
291
391
|
this.options.onCharacterSessionId(sessionId);
|
|
292
392
|
}
|
|
293
393
|
else {
|
|
294
|
-
if (
|
|
295
|
-
|
|
394
|
+
if (event.type === "error") {
|
|
395
|
+
sawError = true;
|
|
396
|
+
this.options.onError(withSseRequestErrorContext(event.data, messages, Boolean(this.options.credentialProvider)), request);
|
|
296
397
|
}
|
|
297
|
-
this.options.onMessage(new TextEncoder().encode(JSON.stringify({ type: eventType, data })));
|
|
398
|
+
this.options.onMessage(new TextEncoder().encode(JSON.stringify({ type: eventType, data })), request);
|
|
298
399
|
}
|
|
299
400
|
eventType = "message";
|
|
300
401
|
eventData = [];
|
|
@@ -326,10 +427,63 @@ export class SSESession {
|
|
|
326
427
|
}
|
|
327
428
|
dispatch();
|
|
328
429
|
this.flushBotLlmText();
|
|
430
|
+
// EOF is a request boundary, not proof the model finished the turn.
|
|
431
|
+
// Preserve partial output and fail only when the response has closed;
|
|
432
|
+
// no watchdog may cancel an otherwise active long-running stream.
|
|
433
|
+
if (!signal.aborted &&
|
|
434
|
+
!sawError &&
|
|
435
|
+
(pendingResponseProducers.size > 0 || sawTurnResponse) &&
|
|
436
|
+
(!sawTerminal || pendingTurnIds.size > 0)) {
|
|
437
|
+
throw Object.assign(new Error("SSE response ended before the turn completed"), {
|
|
438
|
+
code: "SSE_RESPONSE_INCOMPLETE",
|
|
439
|
+
});
|
|
440
|
+
}
|
|
329
441
|
return;
|
|
330
442
|
}
|
|
331
443
|
}
|
|
332
444
|
}
|
|
445
|
+
messageStartsTurn(message) {
|
|
446
|
+
if (message.type === "user_text_message")
|
|
447
|
+
return true;
|
|
448
|
+
const data = asRecord(message.data);
|
|
449
|
+
switch (message.type) {
|
|
450
|
+
case "context-update": {
|
|
451
|
+
if (data?.run_llm !== undefined)
|
|
452
|
+
return data.run_llm === "true";
|
|
453
|
+
return controlRespondMode(data, this.activeRespondModes?.contextUpdate)
|
|
454
|
+
=== "must_respond";
|
|
455
|
+
}
|
|
456
|
+
case "vision-trigger":
|
|
457
|
+
return controlRespondMode(data, this.activeRespondModes?.vision)
|
|
458
|
+
=== "must_respond";
|
|
459
|
+
case "trigger-message":
|
|
460
|
+
return this.activeRespondModes?.trigger === "must_respond";
|
|
461
|
+
case "update-scene-metadata":
|
|
462
|
+
return controlRespondMode(data, this.activeRespondModes?.sceneMetadata)
|
|
463
|
+
=== "must_respond";
|
|
464
|
+
default:
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
applyRespondModeUpdates(updates) {
|
|
469
|
+
for (const { modality, mode } of updates) {
|
|
470
|
+
this.activeRespondModes ?? (this.activeRespondModes = {});
|
|
471
|
+
switch (modality) {
|
|
472
|
+
case "vision":
|
|
473
|
+
this.activeRespondModes.vision = mode;
|
|
474
|
+
break;
|
|
475
|
+
case "context_update":
|
|
476
|
+
this.activeRespondModes.contextUpdate = mode;
|
|
477
|
+
break;
|
|
478
|
+
case "trigger":
|
|
479
|
+
this.activeRespondModes.trigger = mode;
|
|
480
|
+
break;
|
|
481
|
+
case "scene_metadata":
|
|
482
|
+
this.activeRespondModes.sceneMetadata = mode;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
333
487
|
queueBotLlmText(text, metadata = {}) {
|
|
334
488
|
const definedMetadata = Object.fromEntries(Object.entries(metadata).filter(([, value]) => value !== undefined));
|
|
335
489
|
if (this.pendingBotLlmText &&
|
|
@@ -452,7 +606,7 @@ class SseRequestCancellation extends Error {
|
|
|
452
606
|
function isSseRequestCancellation(error) {
|
|
453
607
|
return error instanceof SseRequestCancellation;
|
|
454
608
|
}
|
|
455
|
-
function
|
|
609
|
+
function sseRequestContext(messages) {
|
|
456
610
|
return {
|
|
457
611
|
transport: "sse",
|
|
458
612
|
logicalTurnIds: messages
|
|
@@ -461,10 +615,84 @@ function sseRequestErrorContext(messages) {
|
|
|
461
615
|
messageTypes: messages.map((message) => message.type),
|
|
462
616
|
};
|
|
463
617
|
}
|
|
618
|
+
function asRecord(value) {
|
|
619
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
620
|
+
? value
|
|
621
|
+
: null;
|
|
622
|
+
}
|
|
623
|
+
function asRespondMode(value) {
|
|
624
|
+
return value === "must_respond" || value === "auto" || value === "silent"
|
|
625
|
+
? value
|
|
626
|
+
: null;
|
|
627
|
+
}
|
|
628
|
+
function controlRespondMode(data, configuredMode) {
|
|
629
|
+
if (data && "respond_mode" in data) {
|
|
630
|
+
return asRespondMode(data.respond_mode) ?? undefined;
|
|
631
|
+
}
|
|
632
|
+
return configuredMode;
|
|
633
|
+
}
|
|
634
|
+
function acknowledgedMessageIndex(eventType, data, messages, pendingAcknowledgements) {
|
|
635
|
+
if (eventType !== "server-response")
|
|
636
|
+
return undefined;
|
|
637
|
+
const response = asRecord(data);
|
|
638
|
+
if (typeof response?.event_type !== "string"
|
|
639
|
+
|| (response.status !== "success" && response.status !== "error"
|
|
640
|
+
&& response.status !== "pending" && response.status !== "processing")) {
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
const extras = asRecord(response.extras);
|
|
644
|
+
// Mode updates have explicit correlation. A conflicting or malformed echo
|
|
645
|
+
// must not fall back to another same-type request message.
|
|
646
|
+
const hasUpdateId = response.event_type === "respond-mode-update"
|
|
647
|
+
&& extras !== null && "update_id" in extras;
|
|
648
|
+
if (hasUpdateId && typeof extras?.update_id !== "string")
|
|
649
|
+
return undefined;
|
|
650
|
+
// Core injects request messages in order and sends one final acknowledgement
|
|
651
|
+
// per handler. Without an explicit echo, consume same-type acks FIFO across
|
|
652
|
+
// *all* messages, not just those classified as response-producing.
|
|
653
|
+
return [...pendingAcknowledgements].find(index => {
|
|
654
|
+
const message = messages[index];
|
|
655
|
+
return message.type === response.event_type
|
|
656
|
+
&& (!hasUpdateId || asRecord(message.data)?.update_id === extras?.update_id);
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
function acknowledgedRespondModeUpdate(data, message) {
|
|
660
|
+
const response = asRecord(data);
|
|
661
|
+
if (message.type !== "respond-mode-update" || response?.status !== "success") {
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
const extras = asRecord(response.extras);
|
|
665
|
+
const mode = asRespondMode(extras?.actual_respond_mode)
|
|
666
|
+
// Older Core acks call the accepted value `mode`; it is server-derived,
|
|
667
|
+
// unlike the request's mode. The request ledger already matched this ack.
|
|
668
|
+
?? asRespondMode(extras?.mode);
|
|
669
|
+
if (!mode)
|
|
670
|
+
return null;
|
|
671
|
+
const modality = asRespondModeModality(asRecord(message.data)?.modality);
|
|
672
|
+
return modality ? { modality, mode } : null;
|
|
673
|
+
}
|
|
674
|
+
function asRespondModeModality(value) {
|
|
675
|
+
return value === "vision" || value === "context_update" || value === "trigger"
|
|
676
|
+
|| value === "scene_metadata"
|
|
677
|
+
? value
|
|
678
|
+
: null;
|
|
679
|
+
}
|
|
680
|
+
function responseLifecycleStarted(eventType, data) {
|
|
681
|
+
return eventType === "bot-llm-started" || eventType === "bot-llm-text"
|
|
682
|
+
|| eventType === "bot-llm-text-raw" || eventType === "bot-llm-stopped"
|
|
683
|
+
|| eventType === "bot-transcription" || eventType === "action-response"
|
|
684
|
+
|| eventType === "bot-output" || eventType === "bot-tts-text"
|
|
685
|
+
|| eventType === "bot-tts-started" || eventType === "bot-tts-stopped"
|
|
686
|
+
|| eventType === "bot-started-speaking" || eventType === "bot-stopped-speaking"
|
|
687
|
+
// Model-output v2 can arrive directly or in the legacy server-message
|
|
688
|
+
// envelope. Both represent model execution, even if the payload later
|
|
689
|
+
// fails consumer validation, so an EOF before a terminal is incomplete.
|
|
690
|
+
|| extractModelOutputPayload({ type: eventType, data }) !== undefined;
|
|
691
|
+
}
|
|
464
692
|
function withSseRequestErrorContext(error, messages, workspaceRequest = false) {
|
|
465
693
|
if (isSseRequestCancellation(error))
|
|
466
694
|
return error;
|
|
467
|
-
const context =
|
|
695
|
+
const context = sseRequestContext(messages);
|
|
468
696
|
if (error instanceof Error) {
|
|
469
697
|
// Providers own their Error objects: they may freeze or reuse them. Copy
|
|
470
698
|
// their diagnostic fields, never rewrite an earlier emission's turn IDs.
|
|
@@ -496,4 +724,3 @@ function withSseRequestErrorContext(error, messages, workspaceRequest = false) {
|
|
|
496
724
|
// failures. Personal primitive payloads keep their preexisting value/type.
|
|
497
725
|
return workspaceRequest ? { error, ...context } : error;
|
|
498
726
|
}
|
|
499
|
-
//# sourceMappingURL=SSESession.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat widget's character name and avatar lookup.
|
|
3
|
+
*
|
|
4
|
+
* One copy, because there were two: `useCharacterInfo` and the vanilla
|
|
5
|
+
* widget's inline version, the latter carrying the comment "matches React
|
|
6
|
+
* useCharacterInfo hook" — a sync kept by hand, which is how they came to
|
|
7
|
+
* share a hardcoded host nobody could override.
|
|
8
|
+
*
|
|
9
|
+
* This is cosmetic. The result decorates the widget header and nothing else:
|
|
10
|
+
* no connection, credential or message depends on it, so a failure degrades
|
|
11
|
+
* to the fallback name and no image rather than breaking the chat.
|
|
12
|
+
*/
|
|
13
|
+
/** Origin that serves `POST /character/get`. Not `api2.convai.com`, which does not. */
|
|
14
|
+
export declare const DEFAULT_CHARACTER_INFO_URL = "https://api.convai.com";
|
|
15
|
+
/** The two fields the widget header reads. */
|
|
16
|
+
export interface CharacterInfo {
|
|
17
|
+
name: string;
|
|
18
|
+
image: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** Shown when the character has no name of its own, or the lookup fails. */
|
|
21
|
+
export declare const FALLBACK_CHARACTER_NAME = "Convi";
|
|
22
|
+
export interface FetchCharacterInfoOptions {
|
|
23
|
+
characterId: string;
|
|
24
|
+
/** Sent as `X-API-Key`. Ignored when `authToken` is present. */
|
|
25
|
+
apiKey?: string | null;
|
|
26
|
+
/** Sent as `API-AUTH-TOKEN`, and preferred over `apiKey`. */
|
|
27
|
+
authToken?: string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Origin to ask, for a deployment that is not Convai's SaaS. Defaults to
|
|
30
|
+
* {@link DEFAULT_CHARACTER_INFO_URL}. An on-prem deployment must set this,
|
|
31
|
+
* or the lookup leaves its network — carrying the API key with it.
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string | null;
|
|
34
|
+
/** Lets a caller abort in flight; the widget drops it on unmount. */
|
|
35
|
+
signal?: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
/** Pick the name and avatar out of a `/character/get` body, with the widget's fallbacks. */
|
|
38
|
+
export declare function readCharacterInfo(data: unknown): CharacterInfo;
|
|
39
|
+
/**
|
|
40
|
+
* Fetch a character's display name and avatar.
|
|
41
|
+
*
|
|
42
|
+
* Throws on a non-OK response so a caller can report it; callers that only
|
|
43
|
+
* decorate a header should catch and keep the fallback.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fetchCharacterInfo(options: FetchCharacterInfoOptions): Promise<CharacterInfo>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chat widget's character name and avatar lookup.
|
|
3
|
+
*
|
|
4
|
+
* One copy, because there were two: `useCharacterInfo` and the vanilla
|
|
5
|
+
* widget's inline version, the latter carrying the comment "matches React
|
|
6
|
+
* useCharacterInfo hook" — a sync kept by hand, which is how they came to
|
|
7
|
+
* share a hardcoded host nobody could override.
|
|
8
|
+
*
|
|
9
|
+
* This is cosmetic. The result decorates the widget header and nothing else:
|
|
10
|
+
* no connection, credential or message depends on it, so a failure degrades
|
|
11
|
+
* to the fallback name and no image rather than breaking the chat.
|
|
12
|
+
*/
|
|
13
|
+
/** Origin that serves `POST /character/get`. Not `api2.convai.com`, which does not. */
|
|
14
|
+
export const DEFAULT_CHARACTER_INFO_URL = "https://api.convai.com";
|
|
15
|
+
/** Shown when the character has no name of its own, or the lookup fails. */
|
|
16
|
+
export const FALLBACK_CHARACTER_NAME = "Convi";
|
|
17
|
+
/** Pick the name and avatar out of a `/character/get` body, with the widget's fallbacks. */
|
|
18
|
+
export function readCharacterInfo(data) {
|
|
19
|
+
const body = (data ?? {});
|
|
20
|
+
const str = (v) => typeof v === "string" && v.length > 0 ? v : null;
|
|
21
|
+
const details = body.model_details;
|
|
22
|
+
return {
|
|
23
|
+
name: str(body.character_name) ?? FALLBACK_CHARACTER_NAME,
|
|
24
|
+
image: str(details?.METAHUMAN?.avatar_image_square) ??
|
|
25
|
+
str(details?.METAHUMAN?.avatar_image) ??
|
|
26
|
+
str(details?.modelPlaceholder),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fetch a character's display name and avatar.
|
|
31
|
+
*
|
|
32
|
+
* Throws on a non-OK response so a caller can report it; callers that only
|
|
33
|
+
* decorate a header should catch and keep the fallback.
|
|
34
|
+
*/
|
|
35
|
+
export async function fetchCharacterInfo(options) {
|
|
36
|
+
const { characterId, apiKey, authToken, baseUrl, signal } = options;
|
|
37
|
+
const headers = {
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
};
|
|
40
|
+
if (authToken)
|
|
41
|
+
headers["API-AUTH-TOKEN"] = authToken;
|
|
42
|
+
else if (apiKey)
|
|
43
|
+
headers["X-API-Key"] = apiKey;
|
|
44
|
+
const origin = (baseUrl || DEFAULT_CHARACTER_INFO_URL).replace(/\/+$/, "");
|
|
45
|
+
const response = await fetch(`${origin}/character/get`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers,
|
|
48
|
+
body: JSON.stringify({ charID: characterId }),
|
|
49
|
+
signal,
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`Failed to fetch character info: ${response.status}`);
|
|
53
|
+
}
|
|
54
|
+
return readCharacterInfo(await response.json());
|
|
55
|
+
}
|
|
@@ -37,4 +37,3 @@ export declare function parseCharacterReference(value: string): CharacterReferen
|
|
|
37
37
|
export declare function resolveCharacterReference(characterId: string, characterVersion?: CharacterVersionSelector | null): CharacterReference;
|
|
38
38
|
/** True when `value` is a bare character UUID. */
|
|
39
39
|
export declare function isCharacterUuid(value: string): boolean;
|
|
40
|
-
//# sourceMappingURL=characterReference.d.ts.map
|
|
@@ -57,4 +57,3 @@ export interface ActionConnectRequestConfig {
|
|
|
57
57
|
tools?: ClientToolConnectRequestDeclaration[];
|
|
58
58
|
}
|
|
59
59
|
export declare function buildActionConnectConfig(config: Pick<ConvaiConfig, "actionConfig">): ActionConnectRequestConfig | undefined;
|
|
60
|
-
//# sourceMappingURL=connectRequest.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ContextUpdateOptions, RespondMode } from "./types.js";
|
|
2
2
|
export declare function shouldPreemptForContextUpdateResponse(options: Pick<ContextUpdateOptions, "run_llm" | "respond_mode">): boolean;
|
|
3
3
|
export declare function shouldPreemptForExplicitRespondMode(respondMode: RespondMode | undefined): boolean;
|
|
4
|
-
//# sourceMappingURL=contextUpdateRequest.d.ts.map
|
package/dist/core/index.d.ts
CHANGED
|
@@ -15,8 +15,13 @@ export { parseCharacterReference, resolveCharacterReference, isCharacterVersionS
|
|
|
15
15
|
export { BlendshapeQueue } from './BlendshapeQueue.js';
|
|
16
16
|
export type { TurnStats, BlendshapeChunkMetadata } from './BlendshapeQueue.js';
|
|
17
17
|
export { EventEmitter } from './EventEmitter.js';
|
|
18
|
+
export { fetchCharacterInfo, readCharacterInfo, DEFAULT_CHARACTER_INFO_URL, FALLBACK_CHARACTER_NAME, } from './characterInfo.js';
|
|
19
|
+
export type { CharacterInfo, FetchCharacterInfoOptions } from './characterInfo.js';
|
|
18
20
|
export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
|
|
19
21
|
export type { InlineNode, MediaKind } from '../utils/inlineMarkdown.js';
|
|
22
|
+
export { linkKindForUrl, describeUrl, fileNameOf, documentBadge, contactLabel, hoverTitle, isMixedContent, } from '../utils/linkPresentation.js';
|
|
23
|
+
export type { LinkKind } from '../utils/linkPresentation.js';
|
|
24
|
+
export { resolveLinkPreviewCached, isCardWorthy, LINK_PREVIEW_TIMEOUT_MS, safeHttpUrl, siteNameFor, faviconFor, resetLinkPreviewCache, } from '../utils/linkPreview.js';
|
|
25
|
+
export type { LinkPreviewMeta, LinkPreviewResolver } from '../utils/linkPreview.js';
|
|
20
26
|
export { ModelOutputExtensionRegistry, isJsonObject, isJsonValue, parseModelOutputMessage, } from './modelOutput.js';
|
|
21
27
|
export type { ExtensionRenderResult, ModelOutputExtensionRenderer, } from './modelOutput.js';
|
|
22
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.js
CHANGED
|
@@ -20,11 +20,30 @@ export { parseCharacterReference, resolveCharacterReference, isCharacterVersionS
|
|
|
20
20
|
export { BlendshapeQueue } from './BlendshapeQueue.js';
|
|
21
21
|
// Event Emitter (for advanced usage)
|
|
22
22
|
export { EventEmitter } from './EventEmitter.js';
|
|
23
|
+
// The widget header's character name/avatar lookup. Public so any UI —
|
|
24
|
+
// including @convai/web-widget once the chat UI moves there, and anyone
|
|
25
|
+
// building their own — reuses the one implementation and honours
|
|
26
|
+
// `characterInfoUrl`, rather than hardcoding a host the way two hand-synced
|
|
27
|
+
// copies used to.
|
|
28
|
+
export { fetchCharacterInfo, readCharacterInfo, DEFAULT_CHARACTER_INFO_URL, FALLBACK_CHARACTER_NAME, } from './characterInfo.js';
|
|
23
29
|
// Inline markdown tokenizer. `bot-llm-text` arrives as a plain string, so a
|
|
24
30
|
// custom chat UI — anything not using ConvaiWidget — needs this to turn one
|
|
25
31
|
// line of it into links, images and bare URLs. Only the scheme allowlist in
|
|
26
32
|
// `isSafeHref` becomes a link, so a renderer built on these nodes cannot emit
|
|
27
33
|
// a javascript: href however the server framed it.
|
|
28
34
|
export { parseInlineMarkdown, mediaKindForUrl, isSafeHref, compactUrl } from '../utils/inlineMarkdown.js';
|
|
35
|
+
// Pure functions for labelling a link: URL in, string out. Public so a UI
|
|
36
|
+
// rendering links — the bundled widgets, @convai/web-widget, or your own —
|
|
37
|
+
// derives the same file name, badge, contact label and hover text. The
|
|
38
|
+
// styling half of that module (glyph SVGs, CSS objects, card-count policy) is
|
|
39
|
+
// rendering, and stays with the UI.
|
|
40
|
+
export { linkKindForUrl, describeUrl, fileNameOf, documentBadge, contactLabel, hoverTitle, isMixedContent, } from '../utils/linkPresentation.js';
|
|
41
|
+
// `safeHttpUrl` is a sanitiser — http and https only — and a sanitiser should
|
|
42
|
+
// have exactly one implementation, so it is public rather than re-derived by
|
|
43
|
+
// each UI that renders a preview's favicon.
|
|
44
|
+
export { resolveLinkPreviewCached, isCardWorthy, LINK_PREVIEW_TIMEOUT_MS, safeHttpUrl, siteNameFor, faviconFor,
|
|
45
|
+
// The preview cache is module-level and shared by every card on the page,
|
|
46
|
+
// so a consumer had no way to drop it — on sign-out, say, or between tests
|
|
47
|
+
// of a UI that lives outside this package and so cannot reach it by path.
|
|
48
|
+
resetLinkPreviewCache, } from '../utils/linkPreview.js';
|
|
29
49
|
export { ModelOutputExtensionRegistry, isJsonObject, isJsonValue, parseModelOutputMessage, } from './modelOutput.js';
|
|
30
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -5,4 +5,3 @@ export declare const OUTPUT_ID_MAX_UTF8_BYTES = 128;
|
|
|
5
5
|
export declare function isValidLogicalTurnId(value: unknown): value is string;
|
|
6
6
|
/** Return whether a Core model invocation id is safe to retain and expose. */
|
|
7
7
|
export declare function isValidOutputId(value: unknown): value is string;
|
|
8
|
-
//# sourceMappingURL=logicalTurn.d.ts.map
|
package/dist/core/logicalTurn.js
CHANGED
package/dist/core/modelOutput.js
CHANGED
|
@@ -6,4 +6,3 @@ import type { PublishedChatConnectOptions } from "./types.js";
|
|
|
6
6
|
* omit any caller-supplied id at this higher-level session boundary.
|
|
7
7
|
*/
|
|
8
8
|
export declare function freshPublicationGrantOptions(options?: PublishedChatConnectOptions): PublishedChatConnectOptions | undefined;
|
|
9
|
-
//# sourceMappingURL=publishedChat.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Internal event view; callers retain the original transport envelope. */
|
|
2
|
+
export function unwrapRTVIEvent(type, data) {
|
|
3
|
+
if (type !== "server-message" || typeof data !== "object" || data === null
|
|
4
|
+
|| Array.isArray(data) || typeof data.type !== "string") {
|
|
5
|
+
return { type, data };
|
|
6
|
+
}
|
|
7
|
+
const { type: innerType, ...payload } = data;
|
|
8
|
+
return { type: innerType, data: "data" in payload ? payload.data : payload };
|
|
9
|
+
}
|