@crievo/omni 0.0.0-stage → 0.1.1
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/.env.example +41 -0
- package/README.md +2 -2
- package/bin/omni.mjs +18 -0
- package/docs/onboarding/clone-voice.png +0 -0
- package/docs/onboarding/getting-started.png +0 -0
- package/docs/onboarding/new-video.png +0 -0
- package/docs/onboarding/providers.png +0 -0
- package/docs/onboarding/publish.png +0 -0
- package/docs/onboarding/references.png +0 -0
- package/docs/onboarding.md +212 -0
- package/omnivideo.config.example.json +437 -0
- package/package.json +40 -4
- package/reference/captions.md +156 -0
- package/reference/carousel-contract.md +91 -0
- package/reference/cloud.md +96 -0
- package/reference/learnings.md +792 -0
- package/reference/omnichat.md +305 -0
- package/reference/premiere-mcp.md +91 -0
- package/reference/publish.md +305 -0
- package/reference/scenes-contract.md +109 -0
- package/reference/studio.md +666 -0
- package/reference/voicestudio.md +81 -0
- package/reference/writing-for-voice.md +67 -0
- package/requirements.txt +3 -0
- package/studio/api/app.ts +87 -0
- package/studio/api/lib/errors.ts +33 -0
- package/studio/api/lib/files.ts +41 -0
- package/studio/api/lib/hono.ts +9 -0
- package/studio/api/lib/result.ts +14 -0
- package/studio/api/lib/validate.ts +31 -0
- package/studio/api/lib/video.ts +10 -0
- package/studio/api/middleware/json-charset.ts +11 -0
- package/studio/api/middleware/local-only.ts +32 -0
- package/studio/api/middleware/no-timeout.ts +10 -0
- package/studio/api/routes/admin.ts +18 -0
- package/studio/api/routes/agent-cascade.ts +100 -0
- package/studio/api/routes/agent-history.ts +23 -0
- package/studio/api/routes/agent.ts +162 -0
- package/studio/api/routes/analytics.ts +31 -0
- package/studio/api/routes/approval.ts +60 -0
- package/studio/api/routes/archive.ts +12 -0
- package/studio/api/routes/captions.ts +28 -0
- package/studio/api/routes/carousel.ts +38 -0
- package/studio/api/routes/clone.ts +27 -0
- package/studio/api/routes/create.ts +19 -0
- package/studio/api/routes/events.ts +11 -0
- package/studio/api/routes/export.ts +14 -0
- package/studio/api/routes/media.ts +30 -0
- package/studio/api/routes/omnichat.ts +113 -0
- package/studio/api/routes/onboarding.ts +14 -0
- package/studio/api/routes/publish.ts +40 -0
- package/studio/api/routes/queue.ts +14 -0
- package/studio/api/routes/references.ts +40 -0
- package/studio/api/routes/runner.ts +17 -0
- package/studio/api/routes/schedule.ts +47 -0
- package/studio/api/routes/services.ts +11 -0
- package/studio/api/routes/sessions.ts +27 -0
- package/studio/api/routes/settings.ts +102 -0
- package/studio/api/routes/sound.ts +45 -0
- package/studio/api/routes/thumbnail.ts +18 -0
- package/studio/api/routes/usage.ts +13 -0
- package/studio/api/routes/videos.ts +41 -0
- package/studio/api/routes/voices.ts +71 -0
- package/studio/api/services/admin.ts +113 -0
- package/studio/api/services/agent-cascade.ts +975 -0
- package/studio/api/services/agent-claude.ts +47 -0
- package/studio/api/services/agent-history.ts +103 -0
- package/studio/api/services/agent-persona.ts +77 -0
- package/studio/api/services/agent-tools.ts +2237 -0
- package/studio/api/services/agent-ui-tools.ts +259 -0
- package/studio/api/services/agent-wait.ts +32 -0
- package/studio/api/services/agent.ts +553 -0
- package/studio/api/services/analytics.ts +92 -0
- package/studio/api/services/approval.ts +134 -0
- package/studio/api/services/archive.ts +38 -0
- package/studio/api/services/captions.ts +268 -0
- package/studio/api/services/carousel.ts +206 -0
- package/studio/api/services/classify.ts +196 -0
- package/studio/api/services/clone-phrases.ts +75 -0
- package/studio/api/services/clone.ts +722 -0
- package/studio/api/services/create.ts +421 -0
- package/studio/api/services/events.ts +215 -0
- package/studio/api/services/media.ts +32 -0
- package/studio/api/services/omnichat.ts +624 -0
- package/studio/api/services/onboarding.ts +77 -0
- package/studio/api/services/publish.ts +287 -0
- package/studio/api/services/queue.ts +150 -0
- package/studio/api/services/references.ts +269 -0
- package/studio/api/services/root.ts +60 -0
- package/studio/api/services/services.ts +114 -0
- package/studio/api/services/sessions.ts +1007 -0
- package/studio/api/services/settings.ts +983 -0
- package/studio/api/services/sound.ts +311 -0
- package/studio/api/services/thumbnail.ts +133 -0
- package/studio/api/services/usage.ts +27 -0
- package/studio/api/services/videos.ts +418 -0
- package/studio/api/services/voice-pause.ts +98 -0
- package/studio/api/services/voices.ts +324 -0
- package/studio/runner/runner.ts +244 -0
- package/studio/shared/omni-actions.ts +68 -0
- package/studio/shared/omni-admin.ts +52 -0
- package/studio/shared/omni-farewell.ts +48 -0
- package/studio/shared/omni-hotword.ts +20 -0
- package/studio/shared/omni-screens.ts +228 -0
- package/studio/shared/schemas/admin.ts +15 -0
- package/studio/shared/schemas/agent-cascade.ts +58 -0
- package/studio/shared/schemas/agent-history.ts +73 -0
- package/studio/shared/schemas/agent.ts +50 -0
- package/studio/shared/schemas/analytics.ts +6 -0
- package/studio/shared/schemas/approval.ts +22 -0
- package/studio/shared/schemas/captions.ts +19 -0
- package/studio/shared/schemas/carousel.ts +26 -0
- package/studio/shared/schemas/clone.ts +40 -0
- package/studio/shared/schemas/common.ts +16 -0
- package/studio/shared/schemas/omnichat.ts +54 -0
- package/studio/shared/schemas/onboarding.ts +5 -0
- package/studio/shared/schemas/publish.ts +45 -0
- package/studio/shared/schemas/references.ts +20 -0
- package/studio/shared/schemas/settings.ts +82 -0
- package/studio/shared/schemas/sound.ts +22 -0
- package/studio/shared/schemas/videos.ts +38 -0
- package/studio/shared/schemas/voices.ts +23 -0
- package/studio/shared/types/api.ts +1290 -0
- package/studio/studio.ts +148 -0
- package/studio/tsconfig.json +15 -0
- package/studio/web/assets/logos/cartesia.svg +4 -0
- package/studio/web/assets/logos/elevenlabs.svg +12 -0
- package/studio/web/assets/logos/fish.svg +24 -0
- package/studio/web/assets/logos/omni-black.png +0 -0
- package/studio/web/assets/logos/omni-white.png +0 -0
- package/studio/web/assets/logos/voicestudio.svg +21 -0
- package/studio/web/components/AgentMark.tsx +7 -0
- package/studio/web/components/AgentWalking.tsx +11 -0
- package/studio/web/components/ApiKeyField.tsx +104 -0
- package/studio/web/components/AppShell.tsx +64 -0
- package/studio/web/components/ApprovalNotice.tsx +65 -0
- package/studio/web/components/AvatarGroupIcon.tsx +22 -0
- package/studio/web/components/AvatarNameField.tsx +86 -0
- package/studio/web/components/AvatarPicker.tsx +84 -0
- package/studio/web/components/BrandLogo.tsx +16 -0
- package/studio/web/components/CartesiaPlanSetting.tsx +90 -0
- package/studio/web/components/ClaudeWalking.tsx +32 -0
- package/studio/web/components/CloneVoiceDialog/GuidedScript.tsx +39 -0
- package/studio/web/components/CloneVoiceDialog/LanguageBar.tsx +37 -0
- package/studio/web/components/CloneVoiceDialog/LevelMeter.tsx +31 -0
- package/studio/web/components/CloneVoiceDialog/ProviderChoice.tsx +81 -0
- package/studio/web/components/CloneVoiceDialog/QualityPanel.tsx +62 -0
- package/studio/web/components/CloneVoiceDialog/RecordStep.tsx +50 -0
- package/studio/web/components/CloneVoiceDialog/RecorderBar.tsx +79 -0
- package/studio/web/components/CloneVoiceDialog/RedoSummary.tsx +54 -0
- package/studio/web/components/CloneVoiceDialog/SaveStep.tsx +91 -0
- package/studio/web/components/CloneVoiceDialog/SourceBar.tsx +30 -0
- package/studio/web/components/CloneVoiceDialog/index.tsx +141 -0
- package/studio/web/components/CloneVoiceDialog/types.ts +28 -0
- package/studio/web/components/CloneVoiceDialog/useCloneVoice.ts +528 -0
- package/studio/web/components/ConnectionSignals.tsx +51 -0
- package/studio/web/components/EditVoiceDialog/EditVoiceFooter.tsx +72 -0
- package/studio/web/components/EditVoiceDialog/ProviderCards.tsx +81 -0
- package/studio/web/components/EditVoiceDialog/index.tsx +256 -0
- package/studio/web/components/ErrorBanner.tsx +115 -0
- package/studio/web/components/FinishedTask.tsx +41 -0
- package/studio/web/components/FishModelSetting.tsx +69 -0
- package/studio/web/components/FishPriceSetting.tsx +44 -0
- package/studio/web/components/HumanBanner.tsx +64 -0
- package/studio/web/components/Lightbox.tsx +41 -0
- package/studio/web/components/LogStream.tsx +42 -0
- package/studio/web/components/Markdown.tsx +21 -0
- package/studio/web/components/MissingDmsPanel/BatchSend.tsx +137 -0
- package/studio/web/components/MissingDmsPanel/CommentCard.tsx +168 -0
- package/studio/web/components/MissingDmsPanel/CommentFeed.tsx +45 -0
- package/studio/web/components/MissingDmsPanel/DmBubble.tsx +38 -0
- package/studio/web/components/MissingDmsPanel/ReplyComposer.tsx +63 -0
- package/studio/web/components/MissingDmsPanel/index.tsx +98 -0
- package/studio/web/components/NotFound.tsx +48 -0
- package/studio/web/components/Omni/OmniAvatarPicker.tsx +92 -0
- package/studio/web/components/Omni/OmniCards.tsx +202 -0
- package/studio/web/components/Omni/OmniGlow.tsx +183 -0
- package/studio/web/components/Omni/OmniHistory.tsx +119 -0
- package/studio/web/components/Omni/OmniHotword.tsx +40 -0
- package/studio/web/components/Omni/OmniMicSelect.tsx +92 -0
- package/studio/web/components/Omni/OmniVoiceSample.tsx +81 -0
- package/studio/web/components/Omni/OmniWidget.tsx +743 -0
- package/studio/web/components/Omni/PendingActions.tsx +200 -0
- package/studio/web/components/Omni/Transcript.tsx +127 -0
- package/studio/web/components/OmnichatAccountStatus.tsx +87 -0
- package/studio/web/components/OmnichatRulePanel/RuleConfig.tsx +150 -0
- package/studio/web/components/OmnichatRulePanel/RuleDryRun.tsx +15 -0
- package/studio/web/components/OmnichatRulePanel/RuleEnableConfirm.tsx +42 -0
- package/studio/web/components/OmnichatRulePanel/RuleSkeleton.tsx +18 -0
- package/studio/web/components/OmnichatRulePanel/RuleStatus.tsx +55 -0
- package/studio/web/components/OmnichatRulePanel/index.tsx +115 -0
- package/studio/web/components/OmnichatRulePanel/rule-steps.ts +67 -0
- package/studio/web/components/OmnichatRulePanel/steps/MessageStep.tsx +91 -0
- package/studio/web/components/OmnichatRulePanel/steps/RepliesStep.tsx +201 -0
- package/studio/web/components/OmnichatRulePanel/steps/TriggerStep.tsx +76 -0
- package/studio/web/components/OmnichatRulePanel/steps/types.ts +11 -0
- package/studio/web/components/Palette.tsx +17 -0
- package/studio/web/components/PlatformCard.tsx +109 -0
- package/studio/web/components/PlatformIcon.tsx +19 -0
- package/studio/web/components/ProviderCard.tsx +80 -0
- package/studio/web/components/ProviderDetail.tsx +367 -0
- package/studio/web/components/ProviderLogo.tsx +20 -0
- package/studio/web/components/QueuePanel.tsx +77 -0
- package/studio/web/components/ReferenceActions.tsx +89 -0
- package/studio/web/components/ReferencePicker.tsx +136 -0
- package/studio/web/components/ResultMessage.tsx +7 -0
- package/studio/web/components/RuleForm.tsx +138 -0
- package/studio/web/components/RuleLog.tsx +151 -0
- package/studio/web/components/RunningTask.tsx +23 -0
- package/studio/web/components/SampleList.tsx +55 -0
- package/studio/web/components/SessionPanel.tsx +352 -0
- package/studio/web/components/SettingRow.tsx +14 -0
- package/studio/web/components/SettingsCategorySkeleton.tsx +25 -0
- package/studio/web/components/SidePanel.tsx +77 -0
- package/studio/web/components/Sidebar.tsx +289 -0
- package/studio/web/components/StageStepper.tsx +87 -0
- package/studio/web/components/StudioOffline.tsx +80 -0
- package/studio/web/components/TaskName.tsx +17 -0
- package/studio/web/components/TopBanners.tsx +30 -0
- package/studio/web/components/VideoOmnichatPanel.tsx +287 -0
- package/studio/web/components/VoiceAvatar.tsx +33 -0
- package/studio/web/components/VoiceCarousel.tsx +196 -0
- package/studio/web/components/VoiceCategory.tsx +9 -0
- package/studio/web/components/VoiceModal.tsx +39 -0
- package/studio/web/components/VoiceProfileCard.tsx +75 -0
- package/studio/web/components/VoiceProfilePicker.tsx +107 -0
- package/studio/web/components/VoiceProfilesSettings.tsx +150 -0
- package/studio/web/components/VoiceProviderCard.tsx +118 -0
- package/studio/web/components/VoiceProvidersCard.tsx +26 -0
- package/studio/web/components/WaitList.tsx +21 -0
- package/studio/web/components/icons.tsx +247 -0
- package/studio/web/components/ui/accordion.tsx +47 -0
- package/studio/web/components/ui/badge.tsx +18 -0
- package/studio/web/components/ui/calendar.tsx +43 -0
- package/studio/web/components/ui/chart.tsx +229 -0
- package/studio/web/components/ui/checkbox.tsx +26 -0
- package/studio/web/components/ui/cx.ts +2 -0
- package/studio/web/components/ui/date-time-picker.tsx +84 -0
- package/studio/web/components/ui/panel.tsx +23 -0
- package/studio/web/components/ui/picker.tsx +58 -0
- package/studio/web/components/ui/popover.tsx +24 -0
- package/studio/web/components/ui/select.tsx +89 -0
- package/studio/web/components/ui/skeleton.tsx +10 -0
- package/studio/web/components/ui/slider.tsx +68 -0
- package/studio/web/components/ui/switch.tsx +13 -0
- package/studio/web/components/ui/tooltip.tsx +59 -0
- package/studio/web/hooks/useAccounts.ts +27 -0
- package/studio/web/hooks/useAdmin.ts +12 -0
- package/studio/web/hooks/useAnalytics.ts +21 -0
- package/studio/web/hooks/useAvatarAudioReactive.ts +87 -0
- package/studio/web/hooks/useBrowserConnect.ts +48 -0
- package/studio/web/hooks/useClonePlan.ts +14 -0
- package/studio/web/hooks/useConnected.ts +7 -0
- package/studio/web/hooks/useLiveQuery.ts +29 -0
- package/studio/web/hooks/useMenuCollapsed.ts +32 -0
- package/studio/web/hooks/useMicDevices.ts +53 -0
- package/studio/web/hooks/useMissingDms.ts +211 -0
- package/studio/web/hooks/useMissingSetupSteps.ts +26 -0
- package/studio/web/hooks/useNow.ts +11 -0
- package/studio/web/hooks/useOmniAgent.ts +278 -0
- package/studio/web/hooks/useOmniClaude.ts +124 -0
- package/studio/web/hooks/useOmniDock.ts +142 -0
- package/studio/web/hooks/useOmniGreeting.ts +60 -0
- package/studio/web/hooks/useOmniHotword.ts +128 -0
- package/studio/web/hooks/useOmnichat.ts +26 -0
- package/studio/web/hooks/useOnboarding.ts +27 -0
- package/studio/web/hooks/usePost.ts +23 -0
- package/studio/web/hooks/useQueue.ts +10 -0
- package/studio/web/hooks/useReferences.ts +20 -0
- package/studio/web/hooks/useRuleEditor.ts +101 -0
- package/studio/web/hooks/useRunner.ts +24 -0
- package/studio/web/hooks/useSaveAction.ts +23 -0
- package/studio/web/hooks/useSchedule.ts +11 -0
- package/studio/web/hooks/useServices.ts +10 -0
- package/studio/web/hooks/useSessions.ts +15 -0
- package/studio/web/hooks/useSettings.ts +11 -0
- package/studio/web/hooks/useSettingsSection.ts +30 -0
- package/studio/web/hooks/useSidePanel.ts +23 -0
- package/studio/web/hooks/useSound.ts +30 -0
- package/studio/web/hooks/useUsage.ts +11 -0
- package/studio/web/hooks/useVideoVoice.ts +36 -0
- package/studio/web/hooks/useVideos.ts +21 -0
- package/studio/web/hooks/useVoiceProfilePreview.ts +52 -0
- package/studio/web/hooks/useVoiceProfiles.ts +7 -0
- package/studio/web/hooks/useVoiceRunning.ts +10 -0
- package/studio/web/hooks/useVoiceStudioClosed.ts +8 -0
- package/studio/web/index.html +19 -0
- package/studio/web/lib/agent.ts +7 -0
- package/studio/web/lib/alerts.ts +210 -0
- package/studio/web/lib/analytics-metrics.ts +351 -0
- package/studio/web/lib/api.ts +70 -0
- package/studio/web/lib/audio.ts +39 -0
- package/studio/web/lib/avatars.ts +41 -0
- package/studio/web/lib/calendar.ts +218 -0
- package/studio/web/lib/caption-position.ts +249 -0
- package/studio/web/lib/carousel.ts +24 -0
- package/studio/web/lib/chime.ts +42 -0
- package/studio/web/lib/clone-voice.ts +55 -0
- package/studio/web/lib/export.ts +11 -0
- package/studio/web/lib/files.ts +8 -0
- package/studio/web/lib/format.ts +93 -0
- package/studio/web/lib/media.ts +29 -0
- package/studio/web/lib/mic-device.ts +72 -0
- package/studio/web/lib/missing-dms.ts +70 -0
- package/studio/web/lib/omni-cards.ts +42 -0
- package/studio/web/lib/omni-cascade.ts +1067 -0
- package/studio/web/lib/omni-greeting-audio.ts +24 -0
- package/studio/web/lib/omni-hotword.ts +231 -0
- package/studio/web/lib/omni-panel.ts +67 -0
- package/studio/web/lib/omni-realtime.ts +811 -0
- package/studio/web/lib/omni-ui.ts +402 -0
- package/studio/web/lib/omni-wait.ts +174 -0
- package/studio/web/lib/omnichat-api.ts +44 -0
- package/studio/web/lib/orb.ts +270 -0
- package/studio/web/lib/pcm-recorder.ts +115 -0
- package/studio/web/lib/platforms.ts +17 -0
- package/studio/web/lib/providers.ts +27 -0
- package/studio/web/lib/publish-draft.ts +52 -0
- package/studio/web/lib/publish-settings.ts +81 -0
- package/studio/web/lib/query-client.ts +122 -0
- package/studio/web/lib/references.ts +13 -0
- package/studio/web/lib/services.ts +40 -0
- package/studio/web/lib/sessions.ts +103 -0
- package/studio/web/lib/settings-categories.ts +58 -0
- package/studio/web/lib/sound-audio.ts +33 -0
- package/studio/web/lib/sound-timeline.ts +291 -0
- package/studio/web/lib/sse.ts +86 -0
- package/studio/web/lib/stage-history.ts +141 -0
- package/studio/web/lib/stages.ts +344 -0
- package/studio/web/lib/studio-offline.ts +60 -0
- package/studio/web/lib/upload.ts +24 -0
- package/studio/web/lib/video-tabs.ts +118 -0
- package/studio/web/lib/voice-profile-draft.ts +34 -0
- package/studio/web/lib/voice-profiles.ts +3 -0
- package/studio/web/main.tsx +14 -0
- package/studio/web/pages/AdminPage/index.tsx +123 -0
- package/studio/web/pages/AgentPage/components/Measurements.tsx +102 -0
- package/studio/web/pages/AgentPage/index.tsx +28 -0
- package/studio/web/pages/AnalyticsPage/components/About.tsx +52 -0
- package/studio/web/pages/AnalyticsPage/components/ChannelCards.tsx +106 -0
- package/studio/web/pages/AnalyticsPage/components/ChannelView.tsx +137 -0
- package/studio/web/pages/AnalyticsPage/components/CollectionStatus.tsx +46 -0
- package/studio/web/pages/AnalyticsPage/components/Comparison.tsx +68 -0
- package/studio/web/pages/AnalyticsPage/components/Diagnosis.tsx +50 -0
- package/studio/web/pages/AnalyticsPage/components/Highlights.tsx +49 -0
- package/studio/web/pages/AnalyticsPage/components/Hint.tsx +11 -0
- package/studio/web/pages/AnalyticsPage/components/HookVsBody.tsx +100 -0
- package/studio/web/pages/AnalyticsPage/components/HourlyWave.tsx +133 -0
- package/studio/web/pages/AnalyticsPage/components/Insights.tsx +70 -0
- package/studio/web/pages/AnalyticsPage/components/MetricCard.tsx +46 -0
- package/studio/web/pages/AnalyticsPage/components/PlanSection.tsx +40 -0
- package/studio/web/pages/AnalyticsPage/components/ProgressionChart.tsx +155 -0
- package/studio/web/pages/AnalyticsPage/components/ReelBarsChart.tsx +154 -0
- package/studio/web/pages/AnalyticsPage/components/ReelThumb.tsx +19 -0
- package/studio/web/pages/AnalyticsPage/components/ReelView.tsx +290 -0
- package/studio/web/pages/AnalyticsPage/components/ReelsTable.tsx +269 -0
- package/studio/web/pages/AnalyticsPage/components/RequestWithFocus.tsx +38 -0
- package/studio/web/pages/AnalyticsPage/components/SegmentedControl.tsx +35 -0
- package/studio/web/pages/AnalyticsPage/components/VsMedian.tsx +31 -0
- package/studio/web/pages/AnalyticsPage/index.tsx +17 -0
- package/studio/web/pages/GettingStartedPage/index.tsx +174 -0
- package/studio/web/pages/NewVideoPage/components/DeliverablesPicker.tsx +62 -0
- package/studio/web/pages/NewVideoPage/components/FormatPicker.tsx +33 -0
- package/studio/web/pages/NewVideoPage/index.tsx +133 -0
- package/studio/web/pages/NotFoundPage/index.tsx +9 -0
- package/studio/web/pages/OmnichatPage/components/NewFromLink.tsx +59 -0
- package/studio/web/pages/OmnichatPage/components/RuleListItem.tsx +64 -0
- package/studio/web/pages/OmnichatPage/components/RulePreview.tsx +14 -0
- package/studio/web/pages/OmnichatPage/components/RuleView.tsx +88 -0
- package/studio/web/pages/OmnichatPage/index.tsx +153 -0
- package/studio/web/pages/QueuePage/index.tsx +22 -0
- package/studio/web/pages/ReferencePage/components/ReferenceTexts.tsx +131 -0
- package/studio/web/pages/ReferencePage/index.tsx +216 -0
- package/studio/web/pages/ReferencesPage/components/NewReferenceForm.tsx +150 -0
- package/studio/web/pages/ReferencesPage/components/ReferenceCard.tsx +42 -0
- package/studio/web/pages/ReferencesPage/components/ReferenceGridSkeleton.tsx +31 -0
- package/studio/web/pages/ReferencesPage/index.tsx +67 -0
- package/studio/web/pages/SchedulePage/components/CalendarSkeleton.tsx +18 -0
- package/studio/web/pages/SchedulePage/components/DayView.tsx +177 -0
- package/studio/web/pages/SchedulePage/components/HourPicker.tsx +103 -0
- package/studio/web/pages/SchedulePage/components/MonthDayCell.tsx +111 -0
- package/studio/web/pages/SchedulePage/components/MonthView.tsx +47 -0
- package/studio/web/pages/SchedulePage/components/PlatformIcons.tsx +12 -0
- package/studio/web/pages/SchedulePage/components/PostThumb.tsx +15 -0
- package/studio/web/pages/SchedulePage/components/WeekColumn.tsx +75 -0
- package/studio/web/pages/SchedulePage/components/WeekView.tsx +35 -0
- package/studio/web/pages/SchedulePage/index.tsx +285 -0
- package/studio/web/pages/SettingsPage/components/AgentAccounts.tsx +263 -0
- package/studio/web/pages/SettingsPage/components/AgentCategory.tsx +20 -0
- package/studio/web/pages/SettingsPage/components/ModelPicker.tsx +49 -0
- package/studio/web/pages/SettingsPage/components/ModelsSettings.tsx +138 -0
- package/studio/web/pages/SettingsPage/components/PlatformsCategory.tsx +23 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/AccountStatus.tsx +29 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/AutoPublishPanel.tsx +90 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/BrowserConnect.tsx +62 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/CheckField.tsx +19 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/InstagramPanel.tsx +113 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/OmnichatSettingsPanel.tsx +146 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/SaveBar.tsx +33 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/SchedulePanel.tsx +132 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/SettingsCard.tsx +47 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/SettingsCardGroup.tsx +19 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/TextPanel.tsx +55 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/TiktokPanel.tsx +123 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/YoutubePanel.tsx +100 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/badges.tsx +15 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/index.tsx +40 -0
- package/studio/web/pages/SettingsPage/components/PublishingCategory/types.ts +10 -0
- package/studio/web/pages/SettingsPage/components/UsageCategory.tsx +389 -0
- package/studio/web/pages/SettingsPage/components/VoiceProvidersCategory.tsx +97 -0
- package/studio/web/pages/SettingsPage/index.tsx +85 -0
- package/studio/web/pages/VideoPage/components/AudioPlayer.tsx +113 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/AxisField.tsx +50 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/CaptionList.tsx +56 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/CaptionListItem.tsx +92 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/CaptionMargins.tsx +57 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/CaptionStyleFields.tsx +70 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/CaptionTextForm.tsx +87 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/ColorField.tsx +37 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/MarginField.tsx +59 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/NumberField.tsx +57 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/PositionControls.tsx +140 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/captionEditor.ts +215 -0
- package/studio/web/pages/VideoPage/components/CaptionPositionEditor/useCaptionPosition.ts +154 -0
- package/studio/web/pages/VideoPage/components/CarouselChangeRequest.tsx +72 -0
- package/studio/web/pages/VideoPage/components/CarouselCompositionStage.tsx +80 -0
- package/studio/web/pages/VideoPage/components/CarouselCreate.tsx +63 -0
- package/studio/web/pages/VideoPage/components/CarouselMissing.tsx +19 -0
- package/studio/web/pages/VideoPage/components/CarouselPublishStage.tsx +173 -0
- package/studio/web/pages/VideoPage/components/CarouselScriptStage.tsx +82 -0
- package/studio/web/pages/VideoPage/components/CarouselSlideCard.tsx +49 -0
- package/studio/web/pages/VideoPage/components/CarouselViewer.tsx +55 -0
- package/studio/web/pages/VideoPage/components/ChangedVoices.tsx +53 -0
- package/studio/web/pages/VideoPage/components/CompositionStage.tsx +78 -0
- package/studio/web/pages/VideoPage/components/CoverPicker.tsx +32 -0
- package/studio/web/pages/VideoPage/components/EditorStage.tsx +53 -0
- package/studio/web/pages/VideoPage/components/LineTakes.tsx +160 -0
- package/studio/web/pages/VideoPage/components/LineTextEditor.tsx +124 -0
- package/studio/web/pages/VideoPage/components/LineVoicePicker.tsx +37 -0
- package/studio/web/pages/VideoPage/components/MediaImage.tsx +25 -0
- package/studio/web/pages/VideoPage/components/MotionScriptStage.tsx +39 -0
- package/studio/web/pages/VideoPage/components/NarrationStage.tsx +70 -0
- package/studio/web/pages/VideoPage/components/PublishForm.tsx +387 -0
- package/studio/web/pages/VideoPage/components/PublishStage.tsx +76 -0
- package/studio/web/pages/VideoPage/components/PublishText.tsx +149 -0
- package/studio/web/pages/VideoPage/components/ScenesApprovalPanel.tsx +278 -0
- package/studio/web/pages/VideoPage/components/ScheduledInfo.tsx +72 -0
- package/studio/web/pages/VideoPage/components/ScriptApprovalPanel.tsx +189 -0
- package/studio/web/pages/VideoPage/components/ScriptStage.tsx +17 -0
- package/studio/web/pages/VideoPage/components/SequencePlayer.tsx +146 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/AddSound.tsx +117 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/AreaSelection.tsx +74 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/BedPanel.tsx +94 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/BedRow.tsx +45 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/CaptionOverlay.tsx +44 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/CaptionSaveBar.tsx +32 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/CaptionsPanel.tsx +22 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/ClipBlock.tsx +111 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/ClipPanel.tsx +76 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/CutsPanel.tsx +44 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/EditorTabBar.tsx +73 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/EffectChoice.tsx +46 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/EffectItem.tsx +89 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/EffectPanel.tsx +232 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/EffectsRow.tsx +21 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/Lane.tsx +39 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/MarkerRow.tsx +40 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/MuteButton.tsx +36 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/NumberInput.tsx +37 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/PlanWarnings.tsx +19 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/PlayerResizeHandle.tsx +50 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/PreviewControls.tsx +51 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/SceneRow.tsx +54 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/SettingsPanel.tsx +65 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/SoundLibrary.tsx +99 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/SoundPreview.tsx +82 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/SpeedPanel.tsx +128 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TimelineDock.tsx +56 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TimelineFooter.tsx +26 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TimelineSkeleton.tsx +21 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TimelineToolbar.tsx +160 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TimelineTracks.tsx +121 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/TrackSidebar.tsx +30 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/VoiceRow.tsx +53 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/Waveform.tsx +97 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/clipActions.ts +50 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/effectActions.ts +161 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/index.tsx +161 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/timelineGeometry.ts +45 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/types.ts +43 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useAutosave.ts +107 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useEditorShortcuts.ts +168 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useFitHeight.ts +40 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useFollowPlayhead.ts +21 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useListenMix.ts +43 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/usePlayback.ts +231 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/usePlayerWidth.ts +27 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useSoundData.ts +124 -0
- package/studio/web/pages/VideoPage/components/SoundTimeline/useSoundTimeline.ts +511 -0
- package/studio/web/pages/VideoPage/components/StageDrawer/CompareVersions.tsx +111 -0
- package/studio/web/pages/VideoPage/components/StageDrawer/VersionCard.tsx +81 -0
- package/studio/web/pages/VideoPage/components/StageDrawer/VersionMedia.tsx +24 -0
- package/studio/web/pages/VideoPage/components/StageDrawer/VersionText.tsx +15 -0
- package/studio/web/pages/VideoPage/components/StageDrawer/index.tsx +109 -0
- package/studio/web/pages/VideoPage/components/StageProcess.tsx +126 -0
- package/studio/web/pages/VideoPage/components/StageResult.tsx +69 -0
- package/studio/web/pages/VideoPage/components/SwapReference.tsx +92 -0
- package/studio/web/pages/VideoPage/components/ThumbnailPanel.tsx +252 -0
- package/studio/web/pages/VideoPage/components/TimingPanel.tsx +89 -0
- package/studio/web/pages/VideoPage/components/VideoPlayer.tsx +18 -0
- package/studio/web/pages/VideoPage/components/VideoSkeleton.tsx +50 -0
- package/studio/web/pages/VideoPage/components/VideoVoiceInfo.tsx +33 -0
- package/studio/web/pages/VideoPage/components/VideoVoicePicker.tsx +165 -0
- package/studio/web/pages/VideoPage/components/VoicePauseBanner.tsx +56 -0
- package/studio/web/pages/VideoPage/components/WithLogo.tsx +10 -0
- package/studio/web/pages/VideoPage/index.tsx +295 -0
- package/studio/web/pages/VideosPage/components/PublishedOn.tsx +85 -0
- package/studio/web/pages/VideosPage/components/ServicesPanel.tsx +81 -0
- package/studio/web/pages/VideosPage/components/SessionsPanel.tsx +62 -0
- package/studio/web/pages/VideosPage/components/VideoListSkeleton.tsx +25 -0
- package/studio/web/pages/VideosPage/components/VideoRow.tsx +122 -0
- package/studio/web/pages/VideosPage/index.tsx +134 -0
- package/studio/web/pages/VoicePage/index.tsx +28 -0
- package/studio/web/router.tsx +201 -0
- package/studio/web/styles/base/elements.css +55 -0
- package/studio/web/styles/base/utilities.css +25 -0
- package/studio/web/styles/components/badge.css +33 -0
- package/studio/web/styles/components/claude-running.css +27 -0
- package/studio/web/styles/components/claude-session.css +212 -0
- package/studio/web/styles/components/claude-walking.css +92 -0
- package/studio/web/styles/components/clone-voice-save.css +136 -0
- package/studio/web/styles/components/clone-voice.css +379 -0
- package/studio/web/styles/components/controls.css +70 -0
- package/studio/web/styles/components/data-and-image.css +54 -0
- package/studio/web/styles/components/forms.css +132 -0
- package/studio/web/styles/components/human-banner.css +99 -0
- package/studio/web/styles/components/lightbox.css +50 -0
- package/studio/web/styles/components/markdown.css +68 -0
- package/studio/web/styles/components/modal.css +70 -0
- package/studio/web/styles/components/omni-cards.css +105 -0
- package/studio/web/styles/components/omni.css +859 -0
- package/studio/web/styles/components/omnichat.css +538 -0
- package/studio/web/styles/components/panel.css +115 -0
- package/studio/web/styles/components/platform-card.css +140 -0
- package/studio/web/styles/components/provider-card.css +132 -0
- package/studio/web/styles/components/queue.css +185 -0
- package/studio/web/styles/components/reference-actions.css +133 -0
- package/studio/web/styles/components/reference-picker.css +146 -0
- package/studio/web/styles/components/results-drawer.css +224 -0
- package/studio/web/styles/components/segmented.css +115 -0
- package/studio/web/styles/components/side-panel-tab.css +23 -0
- package/studio/web/styles/components/status-signals.css +66 -0
- package/studio/web/styles/components/stepper.css +208 -0
- package/studio/web/styles/components/table.css +19 -0
- package/studio/web/styles/components/tabs.css +24 -0
- package/studio/web/styles/components/ui/accordion.css +71 -0
- package/studio/web/styles/components/ui/chart.css +162 -0
- package/studio/web/styles/components/ui/checkbox.css +37 -0
- package/studio/web/styles/components/ui/date-picker.css +153 -0
- package/studio/web/styles/components/ui/select.css +110 -0
- package/studio/web/styles/components/ui/skeleton.css +25 -0
- package/studio/web/styles/components/ui/slider.css +81 -0
- package/studio/web/styles/components/ui/switch.css +41 -0
- package/studio/web/styles/components/ui/tooltip.css +24 -0
- package/studio/web/styles/components/voice-carousel.css +255 -0
- package/studio/web/styles/components/voice-editor.css +179 -0
- package/studio/web/styles/components/voice-grid.css +56 -0
- package/studio/web/styles/components/voice-profiles.css +192 -0
- package/studio/web/styles/design-system.md +136 -0
- package/studio/web/styles/index.css +116 -0
- package/studio/web/styles/layout/page.css +41 -0
- package/studio/web/styles/layout/sidebar-groups.css +39 -0
- package/studio/web/styles/layout/sidebar.css +111 -0
- package/studio/web/styles/pages/agent.css +26 -0
- package/studio/web/styles/pages/analytics/dashboard.css +614 -0
- package/studio/web/styles/pages/analytics/insights.css +48 -0
- package/studio/web/styles/pages/getting-started.css +166 -0
- package/studio/web/styles/pages/new-video/form.css +32 -0
- package/studio/web/styles/pages/not-found.css +59 -0
- package/studio/web/styles/pages/references.css +204 -0
- package/studio/web/styles/pages/schedule/calendar.css +541 -0
- package/studio/web/styles/pages/schedule/chip-states.css +60 -0
- package/studio/web/styles/pages/settings/models.css +72 -0
- package/studio/web/styles/pages/settings/shell.css +361 -0
- package/studio/web/styles/pages/settings/usage.css +63 -0
- package/studio/web/styles/pages/studio-offline.css +105 -0
- package/studio/web/styles/pages/video/caption-controls.css +194 -0
- package/studio/web/styles/pages/video/captions-grid.css +70 -0
- package/studio/web/styles/pages/video/captions.css +79 -0
- package/studio/web/styles/pages/video/editor-chat.css +103 -0
- package/studio/web/styles/pages/video/export.css +50 -0
- package/studio/web/styles/pages/video/frames.css +29 -0
- package/studio/web/styles/pages/video/fullscreen-stage.css +400 -0
- package/studio/web/styles/pages/video/instagram-carousel.css +309 -0
- package/studio/web/styles/pages/video/layout.css +285 -0
- package/studio/web/styles/pages/video/narration.css +138 -0
- package/studio/web/styles/pages/video/preview-overview.css +11 -0
- package/studio/web/styles/pages/video/processing-notice.css +34 -0
- package/studio/web/styles/pages/video/publish-when.css +76 -0
- package/studio/web/styles/pages/video/publish.css +97 -0
- package/studio/web/styles/pages/video/result.css +96 -0
- package/studio/web/styles/pages/video/scenes.css +167 -0
- package/studio/web/styles/pages/video/sound-timeline.css +672 -0
- package/studio/web/styles/pages/video/sound-toolbar.css +149 -0
- package/studio/web/styles/pages/video/take-player.css +100 -0
- package/studio/web/styles/pages/video/thumbnail.css +157 -0
- package/studio/web/styles/pages/video/timeline.css +117 -0
- package/studio/web/styles/pages/video/voice-picker.css +14 -0
- package/studio/web/styles/pages/video-list/active-row.css +27 -0
- package/studio/web/styles/pages/video-list/card-link.css +49 -0
- package/studio/web/styles/pages/video-list/list.css +86 -0
- package/studio/web/styles/theme/identity/details.css +204 -0
- package/studio/web/styles/theme/identity/shell.css +249 -0
- package/studio/web/styles/theme/identity/surfaces.css +183 -0
- package/studio/web/styles/theme/identity/titles-and-buttons.css +120 -0
- package/studio/web/styles/theme/no-borders/blocks.css +208 -0
- package/studio/web/styles/theme/no-borders/controls.css +256 -0
- package/studio/web/styles/tokens.css +245 -0
- package/studio/web/types/api.ts +2 -0
- package/studio/web/types/assets.d.ts +9 -0
- package/templates/brief.md +27 -0
- package/templates/captions.html +204 -0
- package/templates/carousel-composition.md +47 -0
- package/templates/carousel-script.md +60 -0
- package/templates/components/voiceavatar/README.md +87 -0
- package/templates/components/voiceavatar/demo.html +50 -0
- package/templates/components/voiceavatar/voiceavatar.js +415 -0
- package/templates/motion.md +80 -0
- package/templates/playbook.md +43 -0
- package/templates/reference.md +123 -0
- package/templates/scene.html +112 -0
- package/templates/scenes.example.json +96 -0
- package/templates/script.md +63 -0
- package/templates/slide.html +71 -0
- package/templates/wireframe.html +91 -0
- package/tools/analysis.mjs +300 -0
- package/tools/approval.mjs +442 -0
- package/tools/assemble.mjs +942 -0
- package/tools/build-motion.mjs +437 -0
- package/tools/captions.mjs +246 -0
- package/tools/carousel.mjs +558 -0
- package/tools/compose.mjs +307 -0
- package/tools/cuts.mjs +74 -0
- package/tools/editor.mjs +419 -0
- package/tools/epidemic-capture.js +54 -0
- package/tools/fanout.mjs +69 -0
- package/tools/history.mjs +70 -0
- package/tools/history.py +61 -0
- package/tools/job-queue.mjs +180 -0
- package/tools/job_queue.py +430 -0
- package/tools/lib/agents.mjs +412 -0
- package/tools/lib/channel.mjs +399 -0
- package/tools/lib/claude-settings.mjs +67 -0
- package/tools/lib/cli.mjs +9 -0
- package/tools/lib/fanout.mjs +234 -0
- package/tools/lib/http.mjs +94 -0
- package/tools/lib/index.js +14 -0
- package/tools/lib/mcp-server.mjs +69 -0
- package/tools/lib/metrics/metrics.mjs +204 -0
- package/tools/lib/narration.mjs +15 -0
- package/tools/lib/oauth-client.mjs +295 -0
- package/tools/lib/omnichat/config.mjs +139 -0
- package/tools/lib/omnichat/errors.mjs +42 -0
- package/tools/lib/omnichat/extract.mjs +82 -0
- package/tools/lib/omnichat/gate.mjs +151 -0
- package/tools/lib/omnichat/manual.mjs +166 -0
- package/tools/lib/omnichat/match.mjs +78 -0
- package/tools/lib/omnichat/pass.mjs +393 -0
- package/tools/lib/omnichat/record.mjs +208 -0
- package/tools/lib/omnichat/text.mjs +315 -0
- package/tools/lib/omnichat/webhook.mjs +166 -0
- package/tools/lib/pairing.mjs +99 -0
- package/tools/lib/paths.mjs +41 -0
- package/tools/lib/platforms/instagram.mjs +469 -0
- package/tools/lib/platforms/tiktok.mjs +343 -0
- package/tools/lib/platforms/youtube.mjs +228 -0
- package/tools/lib/publish/publish.mjs +244 -0
- package/tools/lib/schedule/schedule.mjs +191 -0
- package/tools/lib/service.mjs +134 -0
- package/tools/lib/skill-client.mjs +126 -0
- package/tools/lib/skills-release.mjs +196 -0
- package/tools/lib/testing.mjs +52 -0
- package/tools/lib/up.mjs +187 -0
- package/tools/metrics.mjs +415 -0
- package/tools/models.mjs +134 -0
- package/tools/narrate.mjs +257 -0
- package/tools/omni.mjs +298 -0
- package/tools/omni_paths.py +12 -0
- package/tools/omnichat.mjs +1577 -0
- package/tools/omnivideo.py +1122 -0
- package/tools/package.mjs +130 -0
- package/tools/platforms.mjs +236 -0
- package/tools/premiere.mjs +533 -0
- package/tools/publish.mjs +1496 -0
- package/tools/reference.mjs +1408 -0
- package/tools/render.mjs +426 -0
- package/tools/runner.mjs +156 -0
- package/tools/setup.mjs +466 -0
- package/tools/skills-release.mjs +93 -0
- package/tools/sound.mjs +1323 -0
- package/tools/soundtrack.mjs +217 -0
- package/tools/thumbnail.mjs +271 -0
- package/tools/timing.mjs +108 -0
- package/tools/usage.py +628 -0
- package/tools/voice-envelope.mjs +185 -0
- package/tools/voice.py +448 -0
- package/tools/voice_sample.py +75 -0
- package/tools/wireframe.mjs +230 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
/* The Omni conversation in the browser: one WebSocket to Grok Voice (xAI realtime), the microphone
|
|
2
|
+
in and the reply out, both PCM16 at 24 kHz. The studio API only mints the token and runs the
|
|
3
|
+
tools: Grok asks for a function, this forwards it to /api/agent/tools and returns the output.
|
|
4
|
+
|
|
5
|
+
The reply plays through an <audio> element fed by a MediaStream (not straight to the speakers):
|
|
6
|
+
that is what lets the browser's echo cancellation subtract it from the microphone, so Omni
|
|
7
|
+
doesn't hear itself and the user can still interrupt it.
|
|
8
|
+
|
|
9
|
+
Waiting (wait_for_work, lib/omni-wait.ts): after a request that keeps a studio Claude busy for
|
|
10
|
+
minutes, the socket closes (Grok bills every open second) and only the microphone stays, with a
|
|
11
|
+
local voice detector. Speaking, or the awaited Claude stopping, resumes the same session id with a
|
|
12
|
+
new socket that gets the conversation so far; the first words said while it reconnects are kept
|
|
13
|
+
and sent once it is open. */
|
|
14
|
+
|
|
15
|
+
import { openMic } from "./mic-device";
|
|
16
|
+
import { greetingSamples } from "./omni-greeting-audio";
|
|
17
|
+
import { currentScreen, isUiTool, onScreenChange, openScreen, runUiTool } from "./omni-ui";
|
|
18
|
+
import { api, enc, send } from "./api";
|
|
19
|
+
import {
|
|
20
|
+
transcriptText,
|
|
21
|
+
WAIT_OUTPUT,
|
|
22
|
+
WAIT_TOOL,
|
|
23
|
+
type WaitTarget,
|
|
24
|
+
waitHint,
|
|
25
|
+
waitTargetOf,
|
|
26
|
+
WakeDetector,
|
|
27
|
+
WorkWatch,
|
|
28
|
+
workDoneText,
|
|
29
|
+
} from "./omni-wait";
|
|
30
|
+
import type { AgentPendingAction, AgentResolvedAction } from "../types/api";
|
|
31
|
+
import type { NavigateArgs } from "../../shared/omni-screens";
|
|
32
|
+
import { isFarewell } from "../../shared/omni-farewell";
|
|
33
|
+
|
|
34
|
+
/* waiting: the call sleeps until the user speaks or the studio's work ends (no voice billed) */
|
|
35
|
+
export type OmniStatus = "idle" | "connecting" | "listening" | "user" | "thinking" | "speaking" | "waiting" | "error";
|
|
36
|
+
|
|
37
|
+
/* the call asleep: what wakes it and what was heard while it reconnects */
|
|
38
|
+
export type OmniWait = {
|
|
39
|
+
since: number;
|
|
40
|
+
detector: WakeDetector;
|
|
41
|
+
watch: WorkWatch;
|
|
42
|
+
waking: boolean;
|
|
43
|
+
held: Int16Array[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type OmniEntry =
|
|
47
|
+
| { kind: "user"; id: string; text: string; pending: boolean }
|
|
48
|
+
| {
|
|
49
|
+
kind: "assistant";
|
|
50
|
+
id: string;
|
|
51
|
+
text: string;
|
|
52
|
+
latency_ms: number | null;
|
|
53
|
+
feedback: "up" | "down" | null;
|
|
54
|
+
/* cascade mode: where the latency went (text, LLM, voice) and the turn's cost */
|
|
55
|
+
breakdown?: string;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
kind: "tool";
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
state: "running" | "ok" | "error";
|
|
62
|
+
detail: string | null;
|
|
63
|
+
ms: number | null;
|
|
64
|
+
}
|
|
65
|
+
| { kind: "note"; id: string; text: string };
|
|
66
|
+
|
|
67
|
+
/* the screen's Confirmar: open is the screen of what it created (a new content or reference) */
|
|
68
|
+
export type ConfirmResult = { ok: boolean; output?: string; error?: string; open?: NavigateArgs | null };
|
|
69
|
+
|
|
70
|
+
export type OmniCallbacks = {
|
|
71
|
+
onStatus: (s: OmniStatus) => void;
|
|
72
|
+
onEntries: (e: OmniEntry[]) => void;
|
|
73
|
+
onPending: (a: AgentPendingAction) => void;
|
|
74
|
+
/* a card decided by voice (confirm_action, cancel_action) */
|
|
75
|
+
onResolved?: (r: AgentResolvedAction) => void;
|
|
76
|
+
onError: (message: string) => void;
|
|
77
|
+
/* today's voice quota is used up (before or during the conversation): the widget goes to Claude mode */
|
|
78
|
+
onQuota?: () => void;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const RATE = 24000;
|
|
82
|
+
|
|
83
|
+
/* the capture worklet: posts ~100 ms of PCM16 at a time */
|
|
84
|
+
const WORKLET = `
|
|
85
|
+
class Capture extends AudioWorkletProcessor {
|
|
86
|
+
constructor() { super(); this.buf = new Int16Array(2400); this.n = 0; }
|
|
87
|
+
process(inputs) {
|
|
88
|
+
const ch = inputs[0] && inputs[0][0];
|
|
89
|
+
if (ch) for (let i = 0; i < ch.length; i++) {
|
|
90
|
+
const s = Math.max(-1, Math.min(1, ch[i]));
|
|
91
|
+
this.buf[this.n++] = s < 0 ? s * 0x8000 : s * 0x7fff;
|
|
92
|
+
if (this.n === this.buf.length) { this.port.postMessage(this.buf.buffer, [this.buf.buffer]); this.buf = new Int16Array(2400); this.n = 0; }
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
registerProcessor("omni-capture", Capture);
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
function safeJson(text: string): unknown {
|
|
101
|
+
try {
|
|
102
|
+
return JSON.parse(text || "{}");
|
|
103
|
+
} catch {
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function toBase64(buf: ArrayBuffer): string {
|
|
109
|
+
const bytes = new Uint8Array(buf);
|
|
110
|
+
let s = "";
|
|
111
|
+
for (let i = 0; i < bytes.length; i += 0x8000) s += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
112
|
+
return btoa(s);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function fromBase64Pcm(b64: string): Float32Array<ArrayBuffer> {
|
|
116
|
+
const bin = atob(b64);
|
|
117
|
+
const n = bin.length >> 1;
|
|
118
|
+
const out = new Float32Array(n);
|
|
119
|
+
for (let i = 0; i < n; i++) {
|
|
120
|
+
const v = bin.charCodeAt(2 * i) | (bin.charCodeAt(2 * i + 1) << 8);
|
|
121
|
+
out[i] = (v >= 0x8000 ? v - 0x10000 : v) / 0x8000;
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class OmniConversation {
|
|
127
|
+
/* the reply audio (Omni's voice) */
|
|
128
|
+
readonly analyser: AnalyserNode;
|
|
129
|
+
/* the user's microphone: it only measures, it is not connected to the output (no echo) */
|
|
130
|
+
readonly micAnalyser: AnalyserNode;
|
|
131
|
+
sessionId: string | null = null;
|
|
132
|
+
private ctx: AudioContext;
|
|
133
|
+
private out: MediaStreamAudioDestinationNode;
|
|
134
|
+
private player: HTMLAudioElement;
|
|
135
|
+
private ws: WebSocket | null = null;
|
|
136
|
+
private mic: MediaStream | null = null;
|
|
137
|
+
private worklet: AudioWorkletNode | null = null;
|
|
138
|
+
private playing = new Set<AudioBufferSourceNode>();
|
|
139
|
+
private playhead = 0;
|
|
140
|
+
private entries: OmniEntry[] = [];
|
|
141
|
+
private status: OmniStatus = "idle";
|
|
142
|
+
private muted = false;
|
|
143
|
+
/* voice time: the open stretches already closed by a wait, plus the one open now (0: asleep) */
|
|
144
|
+
private activeMs = 0;
|
|
145
|
+
private segmentStart = 0;
|
|
146
|
+
/* wait_for_work was called: the call sleeps once Omni finishes saying so */
|
|
147
|
+
private waitFor: WaitTarget | null = null;
|
|
148
|
+
private wait: OmniWait | null = null;
|
|
149
|
+
private waitMaxMs = 20 * 60_000;
|
|
150
|
+
private sleepTimer: ReturnType<typeof setInterval> | null = null;
|
|
151
|
+
/* end of the user's speech: the turn latency runs from here to the reply's first audio */
|
|
152
|
+
private speechStoppedAt: number | null = null;
|
|
153
|
+
private calls = new Map<string, Promise<void>[]>();
|
|
154
|
+
private closed = false;
|
|
155
|
+
/* idle: when everything went quiet after Omni's last real reply; Grok's own "Ainda tá aí?"
|
|
156
|
+
(input_audio_buffer.timeout_triggered) doesn't restart it, only the user does */
|
|
157
|
+
private quietSince: number | null = null;
|
|
158
|
+
private nudging = false;
|
|
159
|
+
/* how many times the user spoke (or typed): sent with each tool call, confirm_action needs the user
|
|
160
|
+
to have spoken after the card appeared */
|
|
161
|
+
private heard = 0;
|
|
162
|
+
private hangupMs = 20_000;
|
|
163
|
+
/* agent.limits.max_session_min: no conversation runs past it */
|
|
164
|
+
private maxMs = 10 * 60_000;
|
|
165
|
+
/* what is left of today's voice quota when the conversation started */
|
|
166
|
+
private voiceLeftMs = Number.POSITIVE_INFINITY;
|
|
167
|
+
private idleTimer: ReturnType<typeof setInterval> | null = null;
|
|
168
|
+
/* Omni called end_call, or the user said goodbye: hang up as soon as the goodbye finishes playing */
|
|
169
|
+
private ending = false;
|
|
170
|
+
private hangingUp = false;
|
|
171
|
+
/* whether Grok is answering, and when it last finished and the user last stopped talking: a goodbye
|
|
172
|
+
whose transcript comes after Grok's reply hangs up right away */
|
|
173
|
+
private responding = false;
|
|
174
|
+
private lastDoneAt = 0;
|
|
175
|
+
private lastSpeechStop = 0;
|
|
176
|
+
|
|
177
|
+
/* `history`: an earlier conversation the user continues; it shows above and Grok gets it as context */
|
|
178
|
+
constructor(
|
|
179
|
+
private cb: OmniCallbacks,
|
|
180
|
+
private history: OmniEntry[] = [],
|
|
181
|
+
) {
|
|
182
|
+
this.entries = [...history];
|
|
183
|
+
/* created in the click handler: Safari only plays audio from a context born in a gesture */
|
|
184
|
+
this.ctx = new AudioContext({ sampleRate: RATE });
|
|
185
|
+
this.analyser = this.ctx.createAnalyser();
|
|
186
|
+
this.analyser.fftSize = 1024;
|
|
187
|
+
this.micAnalyser = this.ctx.createAnalyser();
|
|
188
|
+
this.micAnalyser.fftSize = 1024;
|
|
189
|
+
this.out = this.ctx.createMediaStreamDestination();
|
|
190
|
+
this.analyser.connect(this.out);
|
|
191
|
+
this.player = new Audio();
|
|
192
|
+
this.player.srcObject = this.out.stream;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async start() {
|
|
196
|
+
this.setStatus("connecting");
|
|
197
|
+
try {
|
|
198
|
+
await this.ctx.resume();
|
|
199
|
+
void this.player.play();
|
|
200
|
+
const mic = openMic();
|
|
201
|
+
const s = await send(api.agent.session.$post({ json: {} }));
|
|
202
|
+
if (!s.ok && (s as { quota?: boolean }).quota) {
|
|
203
|
+
void mic.then(m => m.getTracks().forEach(t => t.stop())).catch(() => {});
|
|
204
|
+
this.closed = true;
|
|
205
|
+
this.setStatus("idle");
|
|
206
|
+
this.cb.onQuota?.();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!s.ok || !("token" in s)) throw new Error(s.error ?? "não deu para abrir a sessão");
|
|
210
|
+
this.sessionId = s.id;
|
|
211
|
+
this.hangupMs = (s.config?.idle?.hangup_s ?? 20) * 1000;
|
|
212
|
+
this.maxMs = (s.config?.limits?.max_session_min ?? 10) * 60_000;
|
|
213
|
+
this.voiceLeftMs = (s.voice_remaining_s ?? 0) * 1000;
|
|
214
|
+
this.waitMaxMs = (s.config?.wait_max_min ?? 20) * 60_000;
|
|
215
|
+
this.mic = await mic;
|
|
216
|
+
await this.openSocket(s.url, s.token, s.session);
|
|
217
|
+
/* the studio's state for this session, as a system message (the console agent keeps its persona) */
|
|
218
|
+
this.sendEvent({
|
|
219
|
+
type: "conversation.item.create",
|
|
220
|
+
item: {
|
|
221
|
+
type: "message",
|
|
222
|
+
role: "system",
|
|
223
|
+
content: [{ type: "input_text", text: `${s.context}\n\n[Tela atual: ${currentScreen()}]` }],
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
if (this.history.length)
|
|
227
|
+
this.sendEvent({
|
|
228
|
+
type: "conversation.item.create",
|
|
229
|
+
item: {
|
|
230
|
+
type: "message",
|
|
231
|
+
role: "system",
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: "input_text",
|
|
235
|
+
text: `O usuário continuou uma conversa anterior com você. O estado do estúdio pode ter mudado desde então: confira com as ferramentas antes de afirmar algo. A conversa anterior:\n${transcriptText(this.history)}`,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
/* where the user goes next, so "esse vídeo" stays the one on screen */
|
|
241
|
+
this.unwatchScreen = onScreenChange(screen =>
|
|
242
|
+
this.sendEvent({
|
|
243
|
+
type: "conversation.item.create",
|
|
244
|
+
item: { type: "message", role: "system", content: [{ type: "input_text", text: `[Tela atual: ${screen}]` }] },
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
await this.startMic();
|
|
248
|
+
this.segmentStart = performance.now();
|
|
249
|
+
/* the greeting may still be playing */
|
|
250
|
+
this.setStatus(this.playing.size ? "speaking" : "listening");
|
|
251
|
+
this.idleTimer = setInterval(() => this.checkIdle(), 500);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
this.fail(String((e as Error)?.message ?? e));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private openSocket(url: string, token: string, session: Record<string, unknown>) {
|
|
258
|
+
return new Promise<void>((resolve, reject) => {
|
|
259
|
+
const ws = new WebSocket(url, [`xai-client-secret.${token}`]);
|
|
260
|
+
this.ws = ws;
|
|
261
|
+
ws.onopen = () => {
|
|
262
|
+
this.sendEvent({ type: "session.update", session });
|
|
263
|
+
resolve();
|
|
264
|
+
};
|
|
265
|
+
ws.onerror = () => reject(new Error("a conexão com o Grok falhou"));
|
|
266
|
+
ws.onclose = e => {
|
|
267
|
+
/* a socket closed on purpose (the wait) is no longer this.ws */
|
|
268
|
+
if (!this.closed && this.ws === ws) this.fail(`a conversa caiu (${e.code}${e.reason ? `: ${e.reason}` : ""})`);
|
|
269
|
+
};
|
|
270
|
+
ws.onmessage = ev => {
|
|
271
|
+
try {
|
|
272
|
+
this.onEvent(JSON.parse(String(ev.data)));
|
|
273
|
+
} catch {
|
|
274
|
+
/* a frame that isn't JSON: ignored */
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private async startMic() {
|
|
281
|
+
if (!this.mic) return;
|
|
282
|
+
const url = URL.createObjectURL(new Blob([WORKLET], { type: "application/javascript" }));
|
|
283
|
+
await this.ctx.audioWorklet.addModule(url);
|
|
284
|
+
URL.revokeObjectURL(url);
|
|
285
|
+
const source = this.ctx.createMediaStreamSource(this.mic);
|
|
286
|
+
this.worklet = new AudioWorkletNode(this.ctx, "omni-capture");
|
|
287
|
+
this.worklet.port.onmessage = (e: MessageEvent<ArrayBuffer>) => {
|
|
288
|
+
if (this.wait) return this.onWaitChunk(new Int16Array(e.data));
|
|
289
|
+
if (!this.muted) this.sendEvent({ type: "input_audio_buffer.append", audio: toBase64(e.data) });
|
|
290
|
+
};
|
|
291
|
+
source.connect(this.worklet);
|
|
292
|
+
source.connect(this.micAnalyser);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
setMuted(muted: boolean) {
|
|
296
|
+
this.muted = muted;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/* until the user first speaks in a call the panel opened by itself, its silence is the panel's to
|
|
300
|
+
handle (OmniWidget closes it quietly): no "Ainda tá aí?" and no idle hang-up here */
|
|
301
|
+
private idleHeld = false;
|
|
302
|
+
holdIdle(hold: boolean) {
|
|
303
|
+
this.idleHeld = hold;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/* the recorded greeting, as Omni's first words in a call the panel opened by itself: through the
|
|
307
|
+
call's output, so the user can talk over it like over any reply */
|
|
308
|
+
async greet(gender: string) {
|
|
309
|
+
const samples = await greetingSamples(this.ctx, gender);
|
|
310
|
+
if (!samples || this.closed || this.status === "user" || this.status === "error") return;
|
|
311
|
+
this.play(samples);
|
|
312
|
+
this.setStatus("speaking");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/* a typed message instead of speech */
|
|
316
|
+
sendText(text: string) {
|
|
317
|
+
const t = text.trim();
|
|
318
|
+
if (!t) return;
|
|
319
|
+
this.heard++;
|
|
320
|
+
if (isFarewell(t)) {
|
|
321
|
+
/* typed: Grok's reply to it is still to come */
|
|
322
|
+
this.lastSpeechStop = performance.now();
|
|
323
|
+
this.farewell();
|
|
324
|
+
}
|
|
325
|
+
/* typing wakes a sleeping call, with this as the first thing it hears */
|
|
326
|
+
if (this.wait) {
|
|
327
|
+
this.push({ kind: "user", id: `text-${Date.now()}`, text: t, pending: false });
|
|
328
|
+
void this.wake(t);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (!this.ws) return;
|
|
332
|
+
this.nudging = false;
|
|
333
|
+
const id = `text-${Date.now()}`;
|
|
334
|
+
this.push({ kind: "user", id, text: t, pending: false });
|
|
335
|
+
this.sendEvent({
|
|
336
|
+
type: "conversation.item.create",
|
|
337
|
+
item: { type: "message", role: "user", content: [{ type: "input_text", text: t }] },
|
|
338
|
+
});
|
|
339
|
+
this.sendEvent({ type: "response.create" });
|
|
340
|
+
this.speechStoppedAt = performance.now();
|
|
341
|
+
this.setStatus("thinking");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async confirm(action: AgentPendingAction): Promise<ConfirmResult> {
|
|
345
|
+
const r = await send(api.agent.actions[":id"].confirm.$post({ param: { id: enc(action.id) }, json: {} }));
|
|
346
|
+
this.tellModel(
|
|
347
|
+
r.ok
|
|
348
|
+
? `[Tela] O usuário apertou Confirmar e deu certo: ${action.summary}. Resultado: ${(r.output ?? "").slice(-300)}.${waitHint(action.kind)}`
|
|
349
|
+
: `[Tela] O usuário apertou Confirmar, mas falhou: ${action.summary}. Erro: ${r.error}`,
|
|
350
|
+
);
|
|
351
|
+
return r;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async cancel(action: AgentPendingAction) {
|
|
355
|
+
await send(api.agent.actions[":id"].cancel.$post({ param: { id: enc(action.id) }, json: {} }));
|
|
356
|
+
this.tellModel(`[Tela] O usuário cancelou: ${action.summary}.`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/* something that happened on screen, for Omni to react to out loud */
|
|
360
|
+
private tellModel(text: string) {
|
|
361
|
+
if (!this.ws) return;
|
|
362
|
+
this.sendEvent({
|
|
363
|
+
type: "conversation.item.create",
|
|
364
|
+
item: { type: "message", role: "user", content: [{ type: "input_text", text }] },
|
|
365
|
+
});
|
|
366
|
+
this.sendEvent({ type: "response.create" });
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
feedback(item: string, value: "up" | "down" | null) {
|
|
370
|
+
this.entries = this.entries.map(e => (e.kind === "assistant" && e.id === item ? { ...e, feedback: value } : e));
|
|
371
|
+
this.cb.onEntries(this.entries);
|
|
372
|
+
this.log({ type: "feedback", item, value: value ?? "none" });
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/* the user said goodbye (shared/omni-farewell): the call ends once Grok's goodbye plays, whether or
|
|
376
|
+
not it calls end_call; with no reply in a few seconds, it ends anyway */
|
|
377
|
+
private farewell() {
|
|
378
|
+
this.ending = true;
|
|
379
|
+
if (!this.responding && this.lastDoneAt > this.lastSpeechStop) return this.hangUpAfterSpeech();
|
|
380
|
+
setTimeout(() => {
|
|
381
|
+
if (!this.closed && !this.responding) this.hangUpAfterSpeech();
|
|
382
|
+
}, 6000);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private hangUpAfterSpeech() {
|
|
386
|
+
if (this.hangingUp) return;
|
|
387
|
+
this.hangingUp = true;
|
|
388
|
+
const wait = setInterval(() => {
|
|
389
|
+
if (this.playing.size) return;
|
|
390
|
+
clearInterval(wait);
|
|
391
|
+
this.push({ kind: "note", id: `end-${Date.now()}`, text: "O Omni encerrou a conversa." });
|
|
392
|
+
this.stop("agent");
|
|
393
|
+
}, 200);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/* the voice time of this call: what was open, never the waits */
|
|
397
|
+
private elapsed() {
|
|
398
|
+
return this.activeMs + (this.segmentStart ? performance.now() - this.segmentStart : 0);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
private checkIdle() {
|
|
402
|
+
if (this.wait) {
|
|
403
|
+
if (!this.wait.waking && performance.now() - this.wait.since >= this.waitMaxMs) {
|
|
404
|
+
this.push({
|
|
405
|
+
kind: "note",
|
|
406
|
+
id: `wait-max-${Date.now()}`,
|
|
407
|
+
text: `Encerrei a conversa: ${Math.round(this.waitMaxMs / 60_000)} min esperando sem ninguém chamar.`,
|
|
408
|
+
});
|
|
409
|
+
this.stop("wait_max");
|
|
410
|
+
}
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (this.segmentStart && this.elapsed() >= this.voiceLeftMs) {
|
|
414
|
+
this.push({
|
|
415
|
+
kind: "note",
|
|
416
|
+
id: `quota-${Date.now()}`,
|
|
417
|
+
text: "Acabou a cota de voz de hoje: sigo por texto com o Claude.",
|
|
418
|
+
});
|
|
419
|
+
this.stop("quota");
|
|
420
|
+
this.cb.onQuota?.();
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
if (this.segmentStart && this.elapsed() >= this.maxMs) {
|
|
424
|
+
this.push({
|
|
425
|
+
kind: "note",
|
|
426
|
+
id: `max-${Date.now()}`,
|
|
427
|
+
text: `Encerrei a conversa: chegou ao limite de ${Math.round(this.maxMs / 60_000)} min.`,
|
|
428
|
+
});
|
|
429
|
+
return this.stop("max");
|
|
430
|
+
}
|
|
431
|
+
if (this.idleHeld || this.status !== "listening" || this.quietSince == null) return;
|
|
432
|
+
if (performance.now() - this.quietSince < this.hangupMs) return;
|
|
433
|
+
this.push({
|
|
434
|
+
kind: "note",
|
|
435
|
+
id: `idle-${Date.now()}`,
|
|
436
|
+
text: `Encerrei a conversa: ${Math.round(this.hangupMs / 1000)} s sem ninguém falar.`,
|
|
437
|
+
});
|
|
438
|
+
this.stop("idle");
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
private unwatchScreen: (() => void) | null = null;
|
|
442
|
+
|
|
443
|
+
stop(reason = "user") {
|
|
444
|
+
if (this.closed) return;
|
|
445
|
+
this.closed = true;
|
|
446
|
+
if (this.idleTimer) clearInterval(this.idleTimer);
|
|
447
|
+
this.cancelSleep();
|
|
448
|
+
this.unwatchScreen?.();
|
|
449
|
+
this.wait?.watch.stop();
|
|
450
|
+
/* asleep, the open stretch already logged its end: this one closes the call (and its cards) */
|
|
451
|
+
if (this.segmentStart || this.wait)
|
|
452
|
+
this.log({
|
|
453
|
+
type: "end",
|
|
454
|
+
duration_s: this.segmentStart ? Math.round((performance.now() - this.segmentStart) / 100) / 10 : 0,
|
|
455
|
+
reason,
|
|
456
|
+
});
|
|
457
|
+
this.wait = null;
|
|
458
|
+
this.stopPlayback();
|
|
459
|
+
this.worklet?.disconnect();
|
|
460
|
+
this.mic?.getTracks().forEach(t => t.stop());
|
|
461
|
+
this.ws?.close(1000);
|
|
462
|
+
this.player.pause();
|
|
463
|
+
void this.ctx.close();
|
|
464
|
+
this.setStatus("idle");
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/* --- events --------------------------------------------------------------------------------- */
|
|
468
|
+
private onEvent(e: any) {
|
|
469
|
+
switch (e.type) {
|
|
470
|
+
case "input_audio_buffer.speech_started":
|
|
471
|
+
/* barge-in: whatever is still queued stops; speaking before the call slept keeps it awake */
|
|
472
|
+
this.nudging = false;
|
|
473
|
+
this.heard++;
|
|
474
|
+
this.cancelSleep();
|
|
475
|
+
this.stopPlayback();
|
|
476
|
+
this.push({ kind: "user", id: e.item_id, text: "", pending: true });
|
|
477
|
+
this.setStatus("user");
|
|
478
|
+
break;
|
|
479
|
+
/* Grok re-engaging after the silence (idle_timeout_ms): its "Ainda tá aí?" */
|
|
480
|
+
case "input_audio_buffer.timeout_triggered":
|
|
481
|
+
this.nudging = true;
|
|
482
|
+
break;
|
|
483
|
+
case "input_audio_buffer.speech_stopped":
|
|
484
|
+
this.speechStoppedAt = performance.now();
|
|
485
|
+
this.lastSpeechStop = this.speechStoppedAt;
|
|
486
|
+
this.setStatus("thinking");
|
|
487
|
+
break;
|
|
488
|
+
case "conversation.item.input_audio_transcription.completed":
|
|
489
|
+
this.upsertUser(e.item_id, e.transcript ?? "");
|
|
490
|
+
if (isFarewell(e.transcript ?? "")) this.farewell();
|
|
491
|
+
break;
|
|
492
|
+
case "response.created":
|
|
493
|
+
this.responding = true;
|
|
494
|
+
break;
|
|
495
|
+
case "response.output_audio.delta":
|
|
496
|
+
case "response.audio.delta":
|
|
497
|
+
this.firstAudio(e.item_id);
|
|
498
|
+
this.play(fromBase64Pcm(e.delta));
|
|
499
|
+
break;
|
|
500
|
+
case "response.output_audio_transcript.delta":
|
|
501
|
+
case "response.audio_transcript.delta":
|
|
502
|
+
this.appendAssistant(e.item_id, e.delta ?? "");
|
|
503
|
+
break;
|
|
504
|
+
case "response.output_audio_transcript.done":
|
|
505
|
+
case "response.audio_transcript.done":
|
|
506
|
+
this.setAssistantText(e.item_id, e.transcript ?? "");
|
|
507
|
+
break;
|
|
508
|
+
case "response.function_call_arguments.done":
|
|
509
|
+
this.runCall(e.response_id, e.call_id, e.name, e.arguments ?? "{}");
|
|
510
|
+
break;
|
|
511
|
+
case "response.done":
|
|
512
|
+
this.responding = false;
|
|
513
|
+
this.lastDoneAt = performance.now();
|
|
514
|
+
void this.afterResponse(e.response?.id);
|
|
515
|
+
break;
|
|
516
|
+
case "error":
|
|
517
|
+
this.cb.onError(e.error?.message ?? e.message ?? "erro do Grok");
|
|
518
|
+
this.log({ type: "error", message: String(e.error?.message ?? e.message ?? "erro") });
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private firstAudio(item: string) {
|
|
524
|
+
const a = this.entries.find(x => x.kind === "assistant" && x.id === item);
|
|
525
|
+
if (!a) this.push({ kind: "assistant", id: item, text: "", latency_ms: null, feedback: null });
|
|
526
|
+
if (this.speechStoppedAt != null) {
|
|
527
|
+
const latency = Math.round(performance.now() - this.speechStoppedAt);
|
|
528
|
+
this.speechStoppedAt = null;
|
|
529
|
+
this.entries = this.entries.map(x =>
|
|
530
|
+
x.kind === "assistant" && x.id === item ? { ...x, latency_ms: latency } : x,
|
|
531
|
+
);
|
|
532
|
+
this.cb.onEntries(this.entries);
|
|
533
|
+
this.log({ type: "turn", latency_ms: latency, item });
|
|
534
|
+
}
|
|
535
|
+
this.setStatus("speaking");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
private runCall(responseId: string, callId: string, name: string, args: string) {
|
|
539
|
+
if (name === "end_call") {
|
|
540
|
+
this.ending = true;
|
|
541
|
+
void send(
|
|
542
|
+
api.agent.tools.$post({ json: { session: this.sessionId ?? "-", call_id: callId, name, arguments: args } }),
|
|
543
|
+
);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const id = `tool-${callId}`;
|
|
547
|
+
if (name === WAIT_TOOL) {
|
|
548
|
+
/* the browser's own: the call sleeps after Omni says it will wait (afterResponse) */
|
|
549
|
+
this.waitFor = waitTargetOf(safeJson(args));
|
|
550
|
+
this.push({ kind: "tool", id, name, state: "ok", detail: null, ms: 0 });
|
|
551
|
+
const list = this.calls.get(responseId) ?? [];
|
|
552
|
+
list.push(
|
|
553
|
+
Promise.resolve().then(() =>
|
|
554
|
+
this.sendEvent({
|
|
555
|
+
type: "conversation.item.create",
|
|
556
|
+
item: { type: "function_call_output", call_id: callId, output: JSON.stringify(WAIT_OUTPUT) },
|
|
557
|
+
}),
|
|
558
|
+
),
|
|
559
|
+
);
|
|
560
|
+
this.calls.set(responseId, list);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
this.push({ kind: "tool", id, name, state: "running", detail: null, ms: null });
|
|
564
|
+
this.setStatus("thinking");
|
|
565
|
+
const job = (async () => {
|
|
566
|
+
/* a UI tool (navigate) runs here, on the screen; the rest in the studio API */
|
|
567
|
+
const t0 = performance.now();
|
|
568
|
+
const r: { ok: boolean; output?: unknown; error?: string; ms?: number } = isUiTool(name)
|
|
569
|
+
? { ok: true, output: await runUiTool(name, safeJson(args)), ms: Math.round(performance.now() - t0) }
|
|
570
|
+
: await send(
|
|
571
|
+
api.agent.tools.$post({
|
|
572
|
+
json: { session: this.sessionId ?? "-", call_id: callId, name, arguments: args, heard: this.heard },
|
|
573
|
+
}),
|
|
574
|
+
);
|
|
575
|
+
const output: Record<string, unknown> =
|
|
576
|
+
r.ok && "output" in r ? (r.output as Record<string, unknown>) : { error: r.error ?? "falhou" };
|
|
577
|
+
const error = typeof output.error === "string" ? output.error : null;
|
|
578
|
+
this.entries = this.entries.map(x =>
|
|
579
|
+
x.kind === "tool" && x.id === id
|
|
580
|
+
? { ...x, state: error ? "error" : "ok", detail: error, ms: "ms" in r ? Number(r.ms) : null }
|
|
581
|
+
: x,
|
|
582
|
+
);
|
|
583
|
+
this.cb.onEntries(this.entries);
|
|
584
|
+
if (output.pending_action) this.cb.onPending(output.pending_action as AgentPendingAction);
|
|
585
|
+
if (output.resolved) this.cb.onResolved?.(output.resolved as AgentResolvedAction);
|
|
586
|
+
/* a tool that changed something by itself (set_omnichat): the screen that shows it */
|
|
587
|
+
if (output.open) void openScreen(output.open as NavigateArgs);
|
|
588
|
+
this.sendEvent({
|
|
589
|
+
type: "conversation.item.create",
|
|
590
|
+
item: { type: "function_call_output", call_id: callId, output: JSON.stringify(output) },
|
|
591
|
+
});
|
|
592
|
+
})();
|
|
593
|
+
const list = this.calls.get(responseId) ?? [];
|
|
594
|
+
list.push(job);
|
|
595
|
+
this.calls.set(responseId, list);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/* every output of a response's calls goes back before the next response.create */
|
|
599
|
+
private async afterResponse(responseId: string | undefined) {
|
|
600
|
+
if (this.ending) return this.hangUpAfterSpeech();
|
|
601
|
+
const jobs = responseId ? this.calls.get(responseId) : undefined;
|
|
602
|
+
if (!jobs?.length) {
|
|
603
|
+
if (this.waitFor) return this.sleepAfterSpeech();
|
|
604
|
+
if (this.status !== "speaking") this.setStatus("listening");
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
this.calls.delete(responseId!);
|
|
608
|
+
await Promise.all(jobs);
|
|
609
|
+
this.speechStoppedAt = performance.now();
|
|
610
|
+
this.sendEvent({ type: "response.create" });
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/* --- waiting -------------------------------------------------------------------------------- */
|
|
614
|
+
/* Omni said it will wait: the call sleeps once that sentence finished playing */
|
|
615
|
+
private sleepAfterSpeech() {
|
|
616
|
+
if (this.sleepTimer) return;
|
|
617
|
+
this.sleepTimer = setInterval(() => {
|
|
618
|
+
if (this.playing.size) return;
|
|
619
|
+
this.cancelSleep(false);
|
|
620
|
+
this.sleep();
|
|
621
|
+
}, 200);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/* `drop`: the user spoke first, so the wait is off */
|
|
625
|
+
private cancelSleep(drop = true) {
|
|
626
|
+
if (this.sleepTimer) clearInterval(this.sleepTimer);
|
|
627
|
+
this.sleepTimer = null;
|
|
628
|
+
if (drop) this.waitFor = null;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
private sleep() {
|
|
632
|
+
const target = this.waitFor ?? { type: null, target: null };
|
|
633
|
+
this.waitFor = null;
|
|
634
|
+
if (this.closed || this.wait) return;
|
|
635
|
+
const open = this.segmentStart ? performance.now() - this.segmentStart : 0;
|
|
636
|
+
this.activeMs += open;
|
|
637
|
+
this.segmentStart = 0;
|
|
638
|
+
/* this stretch's voice time ends here; the cards stay (reason "wait") */
|
|
639
|
+
this.log({ type: "end", duration_s: Math.round(open / 100) / 10, reason: "wait" });
|
|
640
|
+
const ws = this.ws;
|
|
641
|
+
this.ws = null;
|
|
642
|
+
ws?.close(1000);
|
|
643
|
+
this.calls.clear();
|
|
644
|
+
this.speechStoppedAt = null;
|
|
645
|
+
const watch = new WorkWatch(target, s => void this.wake(workDoneText(s)));
|
|
646
|
+
this.wait = { since: performance.now(), detector: new WakeDetector(), watch, waking: false, held: [] };
|
|
647
|
+
this.push({ kind: "note", id: `wait-${Date.now()}`, text: "Esperando o estúdio. É só falar para me chamar." });
|
|
648
|
+
this.setStatus("waiting");
|
|
649
|
+
void watch.start();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
private onWaitChunk(pcm: Int16Array) {
|
|
653
|
+
const w = this.wait;
|
|
654
|
+
if (!w) return;
|
|
655
|
+
if (w.waking) {
|
|
656
|
+
w.held.push(pcm);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
if (this.muted || !w.detector.feed(pcm)) return;
|
|
660
|
+
w.held = w.detector.take();
|
|
661
|
+
void this.wake(null);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/* `text`: what Omni hears first (the work's end, or a typed message); null: the user is speaking,
|
|
665
|
+
and what was heard meanwhile goes in as audio */
|
|
666
|
+
private async wake(text: string | null) {
|
|
667
|
+
const w = this.wait;
|
|
668
|
+
if (!w || w.waking || this.closed) return;
|
|
669
|
+
w.waking = true;
|
|
670
|
+
w.watch.stop();
|
|
671
|
+
this.setStatus("connecting");
|
|
672
|
+
const s = await send(api.agent.session.$post({ json: { resume: this.sessionId ?? undefined } }));
|
|
673
|
+
if (this.closed) return;
|
|
674
|
+
if (!s.ok && (s as { quota?: boolean }).quota) {
|
|
675
|
+
this.push({
|
|
676
|
+
kind: "note",
|
|
677
|
+
id: `quota-${Date.now()}`,
|
|
678
|
+
text: "Acabou a cota de voz de hoje: sigo por texto com o Claude.",
|
|
679
|
+
});
|
|
680
|
+
this.stop("quota");
|
|
681
|
+
this.cb.onQuota?.();
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
if (!s.ok || !("token" in s)) return this.fail(s.error ?? "não deu para voltar à conversa");
|
|
685
|
+
try {
|
|
686
|
+
await this.openSocket(s.url, s.token, s.session);
|
|
687
|
+
} catch (e) {
|
|
688
|
+
return this.fail(String((e as Error)?.message ?? e));
|
|
689
|
+
}
|
|
690
|
+
if (this.closed) return;
|
|
691
|
+
/* the quota counts what was already spoken in this call */
|
|
692
|
+
this.voiceLeftMs = this.activeMs + (s.voice_remaining_s ?? 0) * 1000;
|
|
693
|
+
this.sendEvent({
|
|
694
|
+
type: "conversation.item.create",
|
|
695
|
+
item: {
|
|
696
|
+
type: "message",
|
|
697
|
+
role: "system",
|
|
698
|
+
content: [
|
|
699
|
+
{
|
|
700
|
+
type: "input_text",
|
|
701
|
+
text: `${s.context}\n\n[Tela atual: ${currentScreen()}]\n\nVocê estava esperando o trabalho do estúdio com a conversa em pausa e voltou agora. Não cumprimente de novo. A conversa até aqui:\n${transcriptText(this.entries)}`,
|
|
702
|
+
},
|
|
703
|
+
],
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
this.wait = null;
|
|
707
|
+
this.segmentStart = performance.now();
|
|
708
|
+
if (text) {
|
|
709
|
+
this.tellModel(text);
|
|
710
|
+
this.speechStoppedAt = performance.now();
|
|
711
|
+
this.setStatus("thinking");
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
for (const c of w.held)
|
|
715
|
+
this.sendEvent({ type: "input_audio_buffer.append", audio: toBase64(c.buffer as ArrayBuffer) });
|
|
716
|
+
this.setStatus("listening");
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/* --- audio out ------------------------------------------------------------------------------ */
|
|
720
|
+
private play(samples: Float32Array<ArrayBuffer>) {
|
|
721
|
+
if (!samples.length) return;
|
|
722
|
+
const buf = this.ctx.createBuffer(1, samples.length, RATE);
|
|
723
|
+
buf.copyToChannel(samples, 0);
|
|
724
|
+
const src = this.ctx.createBufferSource();
|
|
725
|
+
src.buffer = buf;
|
|
726
|
+
src.connect(this.analyser);
|
|
727
|
+
const at = Math.max(this.ctx.currentTime + 0.02, this.playhead);
|
|
728
|
+
src.start(at);
|
|
729
|
+
this.playhead = at + buf.duration;
|
|
730
|
+
this.playing.add(src);
|
|
731
|
+
src.onended = () => {
|
|
732
|
+
this.playing.delete(src);
|
|
733
|
+
if (!this.playing.size && this.status === "speaking") this.setStatus("listening");
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
private stopPlayback() {
|
|
738
|
+
for (const s of this.playing) {
|
|
739
|
+
s.onended = null;
|
|
740
|
+
try {
|
|
741
|
+
s.stop();
|
|
742
|
+
} catch {
|
|
743
|
+
/* already stopped */
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
this.playing.clear();
|
|
747
|
+
this.playhead = 0;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/* --- transcript ----------------------------------------------------------------------------- */
|
|
751
|
+
private push(e: OmniEntry) {
|
|
752
|
+
if (this.entries.some(x => x.id === e.id && x.kind === e.kind)) return;
|
|
753
|
+
this.entries = [...this.entries, e];
|
|
754
|
+
this.cb.onEntries(this.entries);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
private upsertUser(id: string, text: string) {
|
|
758
|
+
if (!this.entries.some(x => x.kind === "user" && x.id === id))
|
|
759
|
+
this.push({ kind: "user", id, text, pending: false });
|
|
760
|
+
else this.entries = this.entries.map(x => (x.kind === "user" && x.id === id ? { ...x, text, pending: false } : x));
|
|
761
|
+
/* speech the server didn't keep (a noise): the empty bubble goes away */
|
|
762
|
+
this.entries = this.entries.filter(x => !(x.kind === "user" && !x.pending && !x.text.trim()));
|
|
763
|
+
this.cb.onEntries(this.entries);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
private appendAssistant(id: string, delta: string) {
|
|
767
|
+
if (!this.entries.some(x => x.kind === "assistant" && x.id === id))
|
|
768
|
+
this.push({ kind: "assistant", id, text: "", latency_ms: null, feedback: null });
|
|
769
|
+
this.entries = this.entries.map(x => (x.kind === "assistant" && x.id === id ? { ...x, text: x.text + delta } : x));
|
|
770
|
+
this.cb.onEntries(this.entries);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
private setAssistantText(id: string, text: string) {
|
|
774
|
+
if (!text) return;
|
|
775
|
+
this.entries = this.entries.map(x => (x.kind === "assistant" && x.id === id ? { ...x, text } : x));
|
|
776
|
+
this.cb.onEntries(this.entries);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/* --- plumbing ------------------------------------------------------------------------------- */
|
|
780
|
+
private sendEvent(e: Record<string, unknown>) {
|
|
781
|
+
if (this.ws?.readyState === WebSocket.OPEN) this.ws.send(JSON.stringify(e));
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
private setStatus(s: OmniStatus) {
|
|
785
|
+
if (this.status === s) return;
|
|
786
|
+
this.status = s;
|
|
787
|
+
if (s === "listening") {
|
|
788
|
+
if (this.nudging) this.nudging = false;
|
|
789
|
+
else this.quietSince = performance.now();
|
|
790
|
+
} else if (!this.nudging) this.quietSince = null;
|
|
791
|
+
this.cb.onStatus(s);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
private fail(message: string) {
|
|
795
|
+
this.cb.onError(message);
|
|
796
|
+
this.log({ type: "error", message });
|
|
797
|
+
this.stop("error");
|
|
798
|
+
this.setStatus("error");
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
private log(
|
|
802
|
+
body:
|
|
803
|
+
| { type: "turn"; latency_ms: number; item?: string }
|
|
804
|
+
| { type: "feedback"; item: string; value: "up" | "down" | "none" }
|
|
805
|
+
| { type: "end"; duration_s: number; reason?: string }
|
|
806
|
+
| { type: "error"; message: string },
|
|
807
|
+
) {
|
|
808
|
+
if (!this.sessionId) return;
|
|
809
|
+
void send(api.agent.sessions[":id"].log.$post({ param: { id: enc(this.sessionId) }, json: body }));
|
|
810
|
+
}
|
|
811
|
+
}
|