@crievo/omni 0.0.0-stage → 0.1.0
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 +14 -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.test.tsx +30 -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,393 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
One omnichat pass on one post: read the new comments, decide who gets the
|
|
3
|
+
DM (dedupe by comment id, skip the account's own and the ones it already
|
|
4
|
+
answered by hand), let an optional classifier decide the uncertain ones,
|
|
5
|
+
then work the queue (DM first; the public reply only once the DM went).
|
|
6
|
+
Pure: the record comes in and is saved through `save`; the Instagram calls
|
|
7
|
+
go through an injected client; the classifier is an injected function (the
|
|
8
|
+
CLI asks Claude; the cloud runs without one and leaves uncertain comments).
|
|
9
|
+
============================================================================ */
|
|
10
|
+
|
|
11
|
+
import { DAY, withDefaults } from "../http.mjs";
|
|
12
|
+
import { CURSOR_MARGIN, DM_DEADLINE, MAX_PAGES } from "./config.mjs";
|
|
13
|
+
import { errorType, PauseError } from "./errors.mjs";
|
|
14
|
+
import { normalize, triggers } from "./match.mjs";
|
|
15
|
+
import { sendOpener } from "./gate.mjs";
|
|
16
|
+
import { buttonLabel, deliveryMessage, deliveryPreview, gateOn, openingText, publicReplyText } from "./text.mjs";
|
|
17
|
+
|
|
18
|
+
/** @typedef {import("../http.mjs").Deps} Deps */
|
|
19
|
+
/** @typedef {import("./match.mjs").Rule} Rule */
|
|
20
|
+
/** @typedef {import("./config.mjs").OmnichatConfig} OmnichatConfig */
|
|
21
|
+
/** @typedef {import("../platforms/instagram.mjs").InstagramClient} InstagramClient */
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {object} CommentRecord
|
|
25
|
+
* @property {string | null} username
|
|
26
|
+
* @property {string} text
|
|
27
|
+
* @property {string} commented_at
|
|
28
|
+
* @property {"queued" | "retry" | "uncertain" | "done" | "failed" | "skipped"} state
|
|
29
|
+
* @property {number} [attempts]
|
|
30
|
+
* @property {number} [pauses]
|
|
31
|
+
* @property {number} [uncertain_count]
|
|
32
|
+
* @property {string} [reason]
|
|
33
|
+
* @property {string} [error]
|
|
34
|
+
* @property {string} [context]
|
|
35
|
+
* @property {string} [account_reply]
|
|
36
|
+
* @property {boolean} [manual]
|
|
37
|
+
* @property {string} [manual_at]
|
|
38
|
+
* @property {import("./gate.mjs").GateRecord} [gate] the button and follow gate: where the person is after the opener
|
|
39
|
+
* @property {{ at?: string, id?: string | null, text?: string, error?: string, failed_at?: string }} [dm] `text`: what the DM said (the opener, when the rule has a button)
|
|
40
|
+
* @property {{ at?: string, id?: string | null, text?: string, manual?: boolean, error?: string, failed_at?: string }} [public_reply]
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {object} PostRecord omnichat-record.json `instagram`
|
|
45
|
+
* @property {string} [media]
|
|
46
|
+
* @property {Record<string, CommentRecord>} comments
|
|
47
|
+
* @property {string | null} [seen_until]
|
|
48
|
+
* @property {number | null} [count]
|
|
49
|
+
* @property {string} [count_lag_since] when the count moved but the comment list did not (see runPass)
|
|
50
|
+
* @property {string | null} [next_check]
|
|
51
|
+
* @property {{ url: string, limit: number } | null} [resume]
|
|
52
|
+
* @property {string} [rule_seen]
|
|
53
|
+
* @property {string} [checked_at]
|
|
54
|
+
* @property {string} [warning]
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The classifier for uncertain comments: { id: true|false }, or null when it could not answer.
|
|
59
|
+
* @typedef {(items: Array<[string, CommentRecord]>) => Promise<Record<string, boolean> | null>} Classify
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/** How long a moved count with an unchanged comment list is treated as the API lagging. */
|
|
63
|
+
const COUNT_LAG_MS = 10 * 60_000;
|
|
64
|
+
|
|
65
|
+
/** Pass identity for the account: the token client, the user id and its (lazily fetched) username. */
|
|
66
|
+
/** @typedef {{ client: InstagramClient, id: string, username: () => Promise<string> }} Account */
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Minutes between checks, by the post's age.
|
|
70
|
+
* @param {string | number} publishedAt @param {number} now @param {OmnichatConfig} C
|
|
71
|
+
*/
|
|
72
|
+
export function intervalMin(publishedAt, now, C) {
|
|
73
|
+
const age = now - Date.parse(/** @type {string} */ (publishedAt));
|
|
74
|
+
if (age < 2 * DAY) return C.interval_min.first_48h;
|
|
75
|
+
if (age < 7 * DAY) return C.interval_min.first_week;
|
|
76
|
+
return C.interval_min.after;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The comments waiting for a reply.
|
|
81
|
+
* @param {{ comments?: Record<string, CommentRecord> }} r
|
|
82
|
+
*/
|
|
83
|
+
export const pendingOf = r =>
|
|
84
|
+
Object.entries(r.comments ?? {}).filter(([, c]) => c.state === "queued" || c.state === "retry");
|
|
85
|
+
|
|
86
|
+
/** @param {any} c */
|
|
87
|
+
export const authorOf = c => (c.from?.username ?? c.username ?? "").toLowerCase();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The account's manual replies to each comment: the one nested in it and a loose comment with @someone.
|
|
91
|
+
* @param {any[]} read @param {string} us the account's username, lower-case
|
|
92
|
+
* @returns {(c: any) => any[]}
|
|
93
|
+
*/
|
|
94
|
+
export function accountReplies(read, us) {
|
|
95
|
+
const mentions = new Map();
|
|
96
|
+
for (const c of read.filter(c => authorOf(c) === us)) {
|
|
97
|
+
for (const [, u] of String(c.text ?? "").matchAll(/@([\w.]+)/g)) {
|
|
98
|
+
const k = u.toLowerCase().replace(/\.$/, "");
|
|
99
|
+
mentions.set(k, [...(mentions.get(k) ?? []), c]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return c => [
|
|
103
|
+
...(c.replies?.data ?? []).filter((/** @type {any} */ x) => x.username?.toLowerCase() === us),
|
|
104
|
+
...(mentions.get(authorOf(c)) ?? []).filter((/** @type {any} */ x) => x.timestamp >= c.timestamp),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Turns freshly read comments into record entries. Dedupe: a comment already in the record
|
|
110
|
+
* is not touched (except a skipped one, reread in case the rule changed), nor is the
|
|
111
|
+
* account's own. Mutates `r.comments`.
|
|
112
|
+
* @param {PostRecord} r @param {any[]} read @param {Rule} rule @param {string} us @param {OmnichatConfig} C
|
|
113
|
+
* @returns {number} how many new comments trigger
|
|
114
|
+
*/
|
|
115
|
+
export function ingest(r, read, rule, us, C) {
|
|
116
|
+
const replies = accountReplies(read, us);
|
|
117
|
+
let fresh = 0;
|
|
118
|
+
for (const c of read) {
|
|
119
|
+
const username = c.from?.username ?? c.username ?? null;
|
|
120
|
+
if ((r.comments[c.id] && r.comments[c.id].state !== "skipped") || authorOf(c) === us) continue;
|
|
121
|
+
const trigger = triggers(rule, c.text, C);
|
|
122
|
+
if (!trigger) continue;
|
|
123
|
+
/* already replied by hand: skip, unless the rule says send (and, with already_replied_if,
|
|
124
|
+
only when that reply says one of the snippets) */
|
|
125
|
+
const ours = replies(c);
|
|
126
|
+
if (ours.length) {
|
|
127
|
+
const ifSays = (rule.already_replied_if ?? []).map(normalize).filter(Boolean);
|
|
128
|
+
const send =
|
|
129
|
+
rule.already_replied === "send" &&
|
|
130
|
+
(!ifSays.length || ours.some(x => ifSays.some(t => ` ${normalize(x.text)} `.includes(` ${t} `))));
|
|
131
|
+
if (!send) {
|
|
132
|
+
r.comments[c.id] = {
|
|
133
|
+
username,
|
|
134
|
+
text: c.text ?? "",
|
|
135
|
+
commented_at: c.timestamp,
|
|
136
|
+
state: "skipped",
|
|
137
|
+
reason: "já respondido pela conta",
|
|
138
|
+
account_reply: ours[0].text ?? "",
|
|
139
|
+
};
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
r.comments[c.id] = {
|
|
144
|
+
username,
|
|
145
|
+
text: c.text ?? "",
|
|
146
|
+
commented_at: c.timestamp,
|
|
147
|
+
state: trigger === "yes" ? "queued" : "uncertain",
|
|
148
|
+
attempts: 0,
|
|
149
|
+
};
|
|
150
|
+
fresh++;
|
|
151
|
+
}
|
|
152
|
+
return fresh;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Applies the classifier's answer to the uncertain comments; no answer counts toward
|
|
157
|
+
* `attempts`, after which the comment is skipped. Mutates the comments.
|
|
158
|
+
* @param {Array<[string, CommentRecord]>} uncertain @param {Record<string, boolean> | null} resp @param {OmnichatConfig} C
|
|
159
|
+
*/
|
|
160
|
+
export function applyClassification(uncertain, resp, C) {
|
|
161
|
+
for (const [cid, c] of uncertain) {
|
|
162
|
+
if (resp && typeof resp[cid] === "boolean") {
|
|
163
|
+
Object.assign(
|
|
164
|
+
c,
|
|
165
|
+
resp[cid]
|
|
166
|
+
? { state: "queued", context: "o Claude leu como pedido" }
|
|
167
|
+
: { state: "skipped", reason: "não pede o envio (o Claude leu pelo contexto)" },
|
|
168
|
+
);
|
|
169
|
+
} else {
|
|
170
|
+
c.uncertain_count = (c.uncertain_count ?? 0) + 1;
|
|
171
|
+
if (c.uncertain_count >= C.attempts)
|
|
172
|
+
Object.assign(c, { state: "skipped", reason: "pedido no meio de uma frase e o Claude não respondeu" });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Replies to one comment: the DM (once: a comment with `dm.at` never gets a second one),
|
|
179
|
+
* then the public reply. Rate limit, block and token errors throw PauseError (the account
|
|
180
|
+
* pauses); the rest marks the comment retry or failed. Mutates `c`.
|
|
181
|
+
* With a button on the rule, the DM is the opener (the link goes out when the person taps, see gate.mjs).
|
|
182
|
+
* @param {{ cid: string, c: CommentRecord, rule: Rule, account: { client: InstagramClient, id: string },
|
|
183
|
+
* media: string, name: string, post: string | null, C: OmnichatConfig } & Deps} p
|
|
184
|
+
*/
|
|
185
|
+
export async function reply({ cid, c, rule, account, media, name, post, C, ...deps }) {
|
|
186
|
+
const d = withDefaults(deps);
|
|
187
|
+
const iso = () => new Date(d.now()).toISOString();
|
|
188
|
+
const who = `@${c.username ?? "?"}`;
|
|
189
|
+
c.attempts = (c.attempts ?? 0) + 1;
|
|
190
|
+
/** @param {"dm" | "public_reply"} step @param {any} e */
|
|
191
|
+
const failStep = (step, e) => {
|
|
192
|
+
const type = errorType(e);
|
|
193
|
+
c.error = e.message;
|
|
194
|
+
c[step] = { error: e.message, failed_at: iso() };
|
|
195
|
+
if (type === "rate_limit" || type === "blocked" || type === "account") {
|
|
196
|
+
c.attempts = /** @type {number} */ (c.attempts) - 1;
|
|
197
|
+
c.pauses = (c.pauses ?? 0) + 1;
|
|
198
|
+
if (type !== "account" || c.pauses < C.attempts) {
|
|
199
|
+
c.state = "retry";
|
|
200
|
+
throw new PauseError(
|
|
201
|
+
`${{ blocked: "a Meta bloqueou a ação", rate_limit: "limite de taxa da Meta", account: "token ou permissão" }[type]}: ${e.message}`,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
c.state = "failed";
|
|
205
|
+
d.log(
|
|
206
|
+
`${iso()} ${name}: ${step === "dm" ? "DM" : "resposta pública"} para ${who} falhou ${c.pauses} vezes, desisti: ${e.message}`,
|
|
207
|
+
);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
c.state = type === "transient" && /** @type {number} */ (c.attempts) < C.attempts ? "retry" : "failed";
|
|
211
|
+
d.log(
|
|
212
|
+
`${iso()} ${name}: ${step === "dm" ? "DM" : "resposta pública"} para ${who} ${c.state === "retry" ? "falhou, tento de novo" : "falhou"}: ${e.message}`,
|
|
213
|
+
);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
if (!c.dm?.at) {
|
|
217
|
+
try {
|
|
218
|
+
if (gateOn(rule)) {
|
|
219
|
+
const { id, via } = await sendOpener({
|
|
220
|
+
client: account.client,
|
|
221
|
+
userId: account.id,
|
|
222
|
+
media,
|
|
223
|
+
commentId: cid,
|
|
224
|
+
rule,
|
|
225
|
+
username: c.username,
|
|
226
|
+
C,
|
|
227
|
+
});
|
|
228
|
+
c.dm = { at: iso(), id, text: openingText(rule, c.username, C) };
|
|
229
|
+
c.gate = { state: "awaiting_tap", via, at: iso() };
|
|
230
|
+
} else {
|
|
231
|
+
const { id } = await account.client.privateReply(account.id, cid, deliveryMessage(rule, c.username, post, C));
|
|
232
|
+
c.dm = { at: iso(), id, text: deliveryPreview(rule, c.username, post, C) };
|
|
233
|
+
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
failStep("dm", e);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const publicText = c.public_reply?.at ? null : publicReplyText(rule, c.username, C, d.random);
|
|
240
|
+
if (publicText) {
|
|
241
|
+
try {
|
|
242
|
+
const { id } = await account.client.publicReply(cid, publicText);
|
|
243
|
+
c.public_reply = { at: iso(), id, text: publicText };
|
|
244
|
+
} catch (e) {
|
|
245
|
+
failStep("public_reply", e);
|
|
246
|
+
/* the DM already went: a public reply that won't go for good does not hold the comment in the queue */
|
|
247
|
+
if (c.state === "retry") return;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
c.state = "done";
|
|
251
|
+
delete c.error;
|
|
252
|
+
d.log(`${iso()} ${name}: ${who} respondido (DM${c.public_reply?.at ? " e pública" : ""})`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* One pass on one published post. Throws PauseError when the account must pause.
|
|
257
|
+
* @param {{ rule: Rule, media: string, stored?: Partial<PostRecord> | null, account: Account, name: string,
|
|
258
|
+
* postFallback: string | null, dryRun?: boolean, force?: boolean, maxPages?: number, classify?: Classify,
|
|
259
|
+
* save: (r: PostRecord) => void | Promise<void>, C: OmnichatConfig } & Deps} p
|
|
260
|
+
* `stored` is omnichat-record.json's `instagram`; `save` persists it (never called on a dry run; awaited, so a
|
|
261
|
+
* database write finishes before the next DM goes). `force` reads now even before next_check: a webhook said
|
|
262
|
+
* there is a new comment. `maxPages` caps the comment pages read in this pass (a cloud function has a
|
|
263
|
+
* budget of subrequests); the rest resumes on the next one
|
|
264
|
+
* @returns {Promise<PostRecord>}
|
|
265
|
+
*/
|
|
266
|
+
export async function runPass({
|
|
267
|
+
rule,
|
|
268
|
+
media,
|
|
269
|
+
stored,
|
|
270
|
+
account,
|
|
271
|
+
name,
|
|
272
|
+
postFallback,
|
|
273
|
+
dryRun = false,
|
|
274
|
+
force = false,
|
|
275
|
+
maxPages = MAX_PAGES,
|
|
276
|
+
classify,
|
|
277
|
+
save,
|
|
278
|
+
C,
|
|
279
|
+
...deps
|
|
280
|
+
}) {
|
|
281
|
+
const d = withDefaults(deps);
|
|
282
|
+
const iso = () => new Date(d.now()).toISOString();
|
|
283
|
+
/** @type {PostRecord} */
|
|
284
|
+
let r = /** @type {any} */ (stored ?? {});
|
|
285
|
+
/* published again (--again): another post, read from scratch; the already replied stay */
|
|
286
|
+
if (r.media && r.media !== media) r = /** @type {any} */ ({ comments: r.comments });
|
|
287
|
+
r.media = media;
|
|
288
|
+
r.comments ??= {};
|
|
289
|
+
/* rule changed (another keyword, any comment): rereads the 7 days with the new rule */
|
|
290
|
+
if (r.rule_seen !== rule.updated_at)
|
|
291
|
+
Object.assign(r, { seen_until: null, count: null, next_check: null, resume: null, rule_seen: rule.updated_at });
|
|
292
|
+
const persist = async () => {
|
|
293
|
+
if (!dryRun) await save(r);
|
|
294
|
+
};
|
|
295
|
+
const now = d.now();
|
|
296
|
+
/* without a classifier, uncertain comments wait for a pass that has one: they don't force a read */
|
|
297
|
+
const waitingClassifier = !!classify && Object.values(r.comments).some(c => c.state === "uncertain");
|
|
298
|
+
if (
|
|
299
|
+
!dryRun &&
|
|
300
|
+
!force &&
|
|
301
|
+
r.next_check &&
|
|
302
|
+
Date.parse(r.next_check) > now &&
|
|
303
|
+
!r.resume &&
|
|
304
|
+
!pendingOf(r).length &&
|
|
305
|
+
!waitingClassifier
|
|
306
|
+
)
|
|
307
|
+
return r;
|
|
308
|
+
|
|
309
|
+
const m = await account.client.media(media, "comments_count,timestamp,permalink");
|
|
310
|
+
const post = m.permalink ?? postFallback;
|
|
311
|
+
r.checked_at = iso();
|
|
312
|
+
r.next_check = new Date(now + intervalMin(m.timestamp ?? now, now, C) * 60_000).toISOString();
|
|
313
|
+
|
|
314
|
+
/* 1. new comments, newest to oldest, down to the last seen one */
|
|
315
|
+
/* the count alone misses a comment that came while another was deleted (the total stays the same):
|
|
316
|
+
a forced pass (a webhook said there is a new one) always reads */
|
|
317
|
+
if (force || m.comments_count !== r.count || !r.seen_until || r.resume || dryRun) {
|
|
318
|
+
/* a pass that stopped midway (more than MAX_PAGES pages) continues where it stopped, with the
|
|
319
|
+
same limit, instead of moving the cursor over what was left out */
|
|
320
|
+
const resuming = !dryRun && r.resume ? r.resume : null;
|
|
321
|
+
const limit =
|
|
322
|
+
resuming?.limit ?? Math.max(r.seen_until ? Date.parse(r.seen_until) - CURSOR_MARGIN : 0, now - DM_DEADLINE);
|
|
323
|
+
const { read, next } = await account.client.comments(media, limit, resuming?.url, maxPages);
|
|
324
|
+
let newest = r.seen_until ?? null;
|
|
325
|
+
for (const c of read) if (!newest || c.timestamp > newest) newest = c.timestamp;
|
|
326
|
+
const us = read.length ? await account.username() : "";
|
|
327
|
+
const fresh = ingest(r, read, rule, us, C);
|
|
328
|
+
if (!dryRun) r.resume = next ? { url: next, limit } : null;
|
|
329
|
+
if (next) d.log(`${iso()} ${name}: mais de ${maxPages * 50} comentários para ler; o resto vem na próxima passada`);
|
|
330
|
+
/* the list comes back empty, without error, when the token lacks instagram_business_manage_comments */
|
|
331
|
+
if (!read.length && !r.seen_until && m.comments_count > 0) {
|
|
332
|
+
r.warning = `o post tem ${m.comments_count} comentário(s) e a API não devolveu nenhum: o token tem instagram_business_manage_comments e o app está publicado (Live)?`;
|
|
333
|
+
d.log(`${iso()} ${name}: ${r.warning}`);
|
|
334
|
+
} else delete r.warning;
|
|
335
|
+
/* the count moves before the list does: if it changed but nothing newer than the cursor came
|
|
336
|
+
back, the list is lagging. Keep the old count so the next pass reads again, for up to
|
|
337
|
+
COUNT_LAG_MS (a deleted comment also lowers the count and would otherwise reread forever) */
|
|
338
|
+
const lagging = !dryRun && r.count != null && m.comments_count !== r.count && newest === r.seen_until;
|
|
339
|
+
if (lagging) r.count_lag_since ??= iso();
|
|
340
|
+
if (!lagging || now - Date.parse(r.count_lag_since ?? iso()) > COUNT_LAG_MS) {
|
|
341
|
+
r.count = m.comments_count;
|
|
342
|
+
delete r.count_lag_since;
|
|
343
|
+
}
|
|
344
|
+
if (newest) r.seen_until = newest;
|
|
345
|
+
if (dryRun)
|
|
346
|
+
d.log(`${name}: ${m.comments_count} comentário(s) no post, ${read.length} lido(s) agora, ${fresh} disparam`);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* 2. the request in the middle of a sentence: the classifier decides from the post's context */
|
|
350
|
+
const uncertain = Object.entries(r.comments).filter(([, c]) => c.state === "uncertain");
|
|
351
|
+
if (uncertain.length && classify) {
|
|
352
|
+
applyClassification(uncertain, await classify(uncertain), C);
|
|
353
|
+
if (dryRun)
|
|
354
|
+
for (const [, c] of uncertain)
|
|
355
|
+
d.log(
|
|
356
|
+
` em dúvida, @${c.username ?? "?"}: "${c.text.slice(0, 60)}" → ${c.state === "queued" ? "manda" : c.state === "skipped" ? "não manda" : "sem resposta do Claude"}`,
|
|
357
|
+
);
|
|
358
|
+
await persist();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/* 3. the queue: oldest comment to newest, up to the pass maximum */
|
|
362
|
+
const queue = pendingOf(r).sort(([, a], [, b]) => a.commented_at.localeCompare(b.commented_at));
|
|
363
|
+
let done = 0;
|
|
364
|
+
try {
|
|
365
|
+
for (const [cid, c] of queue) {
|
|
366
|
+
if (done >= C.max_per_pass) break;
|
|
367
|
+
if (now - Date.parse(c.commented_at) > DM_DEADLINE && !c.dm?.at) {
|
|
368
|
+
Object.assign(c, { state: "failed", error: "passou dos 7 dias que a Meta dá para responder pela DM" });
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (dryRun) {
|
|
372
|
+
d.log(` @${c.username ?? "?"}: "${c.text.slice(0, 60)}"`);
|
|
373
|
+
if (gateOn(rule)) {
|
|
374
|
+
d.log(` DM: ${openingText(rule, c.username, C)} [${buttonLabel(rule, C)}]`);
|
|
375
|
+
d.log(
|
|
376
|
+
` ao tocar${rule.require_follow ? " (se seguir)" : ""}: ${deliveryPreview(rule, c.username, post, C).replace(/\n/g, " ⏎ ")}`,
|
|
377
|
+
);
|
|
378
|
+
} else d.log(` DM: ${deliveryPreview(rule, c.username, post, C).replace(/\n/g, " ⏎ ")}`);
|
|
379
|
+
d.log(` pública: ${publicReplyText(rule, c.username, C, d.random) ?? "nenhuma"}`);
|
|
380
|
+
done++;
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
if (done) await d.sleep((C.pause_between_s + d.random() * C.pause_between_s) * 1000);
|
|
384
|
+
await reply({ cid, c, rule, account, media, name, post, C, ...d });
|
|
385
|
+
done++;
|
|
386
|
+
await persist();
|
|
387
|
+
}
|
|
388
|
+
} finally {
|
|
389
|
+
await persist();
|
|
390
|
+
}
|
|
391
|
+
if (dryRun && !queue.length) d.log(" nada para responder");
|
|
392
|
+
return r;
|
|
393
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/* The record and the rule over time: totals, retrying what failed, who was left
|
|
2
|
+
without a DM, and what happens to the rule when the post goes up. Pure. */
|
|
3
|
+
|
|
4
|
+
import { DM_DEADLINE } from "./config.mjs";
|
|
5
|
+
import { triggers } from "./match.mjs";
|
|
6
|
+
import { accountReplies, authorOf } from "./pass.mjs";
|
|
7
|
+
import { deliveryPreview, gateOn, newRule, openingText, ruleProblems } from "./text.mjs";
|
|
8
|
+
|
|
9
|
+
/** @typedef {import("./match.mjs").Rule} Rule */
|
|
10
|
+
/** @typedef {import("./config.mjs").OmnichatConfig} OmnichatConfig */
|
|
11
|
+
/** @typedef {import("./pass.mjs").CommentRecord} CommentRecord */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The record's comments, newest first, with their id.
|
|
15
|
+
* @param {{ comments?: Record<string, CommentRecord> } | null | undefined} r
|
|
16
|
+
*/
|
|
17
|
+
export const recordItems = r =>
|
|
18
|
+
Object.entries(r?.comments ?? {})
|
|
19
|
+
.map(([id, c]) => ({ id, ...c }))
|
|
20
|
+
.sort((a, b) => b.commented_at.localeCompare(a.commented_at));
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {Array<CommentRecord>} items
|
|
24
|
+
*/
|
|
25
|
+
export function totals(items) {
|
|
26
|
+
const t = {
|
|
27
|
+
triggers: items.length,
|
|
28
|
+
dms: 0,
|
|
29
|
+
public_replies: 0,
|
|
30
|
+
queued: 0,
|
|
31
|
+
uncertain: 0,
|
|
32
|
+
failures: 0,
|
|
33
|
+
awaiting: 0,
|
|
34
|
+
delivered: 0,
|
|
35
|
+
};
|
|
36
|
+
for (const c of items) {
|
|
37
|
+
if (c.dm?.at) t.dms++;
|
|
38
|
+
if (c.public_reply?.at) t.public_replies++;
|
|
39
|
+
if (c.state === "queued" || c.state === "retry") t.queued++;
|
|
40
|
+
if (c.state === "failed") t.failures++;
|
|
41
|
+
if (c.gate?.state === "delivered") t.delivered++;
|
|
42
|
+
else if (c.gate) t.awaiting++;
|
|
43
|
+
if (c.state === "uncertain") t.uncertain++;
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* What failed without a delivered DM goes back to the queue; past Meta's 7 days there is no way back.
|
|
50
|
+
* Mutates the record.
|
|
51
|
+
* @param {{ comments?: Record<string, CommentRecord>, next_check?: string | null } | null | undefined} r
|
|
52
|
+
* @param {number} now
|
|
53
|
+
* @returns {{ n: number, old: number }}
|
|
54
|
+
*/
|
|
55
|
+
export function retryFailed(r, now) {
|
|
56
|
+
let n = 0,
|
|
57
|
+
old = 0;
|
|
58
|
+
for (const c of Object.values(r?.comments ?? {})) {
|
|
59
|
+
if (c.state !== "failed" || c.dm?.at) continue;
|
|
60
|
+
if (now - Date.parse(c.commented_at) > DM_DEADLINE) {
|
|
61
|
+
old++;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
Object.assign(c, { state: "queued", attempts: 0, pauses: 0 });
|
|
65
|
+
delete c.error;
|
|
66
|
+
delete c.dm;
|
|
67
|
+
n++;
|
|
68
|
+
}
|
|
69
|
+
if (n && r) r.next_check = null;
|
|
70
|
+
return { n, old };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Who did not get the DM, from a fresh read of the post (read only).
|
|
75
|
+
* @param {{ read: any[], us: string, rec: Record<string, CommentRecord>, rule: Rule | null, now: number, C: OmnichatConfig }} p
|
|
76
|
+
*/
|
|
77
|
+
export function withoutDm({ read, us, rec, rule, now, C }) {
|
|
78
|
+
const replies = accountReplies(read, us);
|
|
79
|
+
return read
|
|
80
|
+
.filter(c => authorOf(c) !== us && !rec[c.id]?.dm?.at)
|
|
81
|
+
.map(c => {
|
|
82
|
+
const prev = rec[c.id];
|
|
83
|
+
return {
|
|
84
|
+
id: c.id,
|
|
85
|
+
username: c.from?.username ?? c.username ?? null,
|
|
86
|
+
text: c.text ?? "",
|
|
87
|
+
commented_at: c.timestamp,
|
|
88
|
+
/* what the agent already did with it (null: did not trigger, or not read yet) */
|
|
89
|
+
state: prev?.state ?? null,
|
|
90
|
+
reason: prev?.reason ?? prev?.error ?? null,
|
|
91
|
+
triggers: rule ? triggers(rule, c.text, C) : false,
|
|
92
|
+
account_reply: replies(c)[0]?.text ?? null,
|
|
93
|
+
/* Meta only accepts the DM up to 7 days after the comment */
|
|
94
|
+
within_deadline: now - Date.parse(c.timestamp) <= DM_DEADLINE,
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The whole post as a chat: every top-level comment with the replies nested in it (people's and the
|
|
101
|
+
* account's), its status and the DM it got. The account's loose comments that @ someone nest under that
|
|
102
|
+
* person's latest comment before it (the way the app threads them). Read only.
|
|
103
|
+
* @param {{ read: any[], us: string, rec: Record<string, CommentRecord>, rule: Rule | null, now: number,
|
|
104
|
+
* post: string | null, C: OmnichatConfig }} p
|
|
105
|
+
*/
|
|
106
|
+
export function thread({ read, us, rec, rule, now, post, C }) {
|
|
107
|
+
/** @param {any} x */
|
|
108
|
+
const node = x => ({
|
|
109
|
+
id: x.id,
|
|
110
|
+
username: x.from?.username ?? x.username ?? null,
|
|
111
|
+
text: x.text ?? "",
|
|
112
|
+
at: x.timestamp,
|
|
113
|
+
own: authorOf(x) === us,
|
|
114
|
+
});
|
|
115
|
+
/** the loose comments of the account that mention someone: nested under that person's comment */
|
|
116
|
+
const loose = new Map();
|
|
117
|
+
const tops = [];
|
|
118
|
+
const byAuthor = new Map();
|
|
119
|
+
for (const c of [...read].sort((a, b) => a.timestamp.localeCompare(b.timestamp)))
|
|
120
|
+
if (authorOf(c) !== us) byAuthor.set(authorOf(c), [...(byAuthor.get(authorOf(c)) ?? []), c]);
|
|
121
|
+
for (const c of read) {
|
|
122
|
+
if (authorOf(c) === us) {
|
|
123
|
+
const mention = String(c.text ?? "").match(/@([\w.]+)/);
|
|
124
|
+
const target = mention
|
|
125
|
+
? (byAuthor.get(mention[1].toLowerCase().replace(/\.$/, "")) ?? [])
|
|
126
|
+
.filter(x => x.timestamp <= c.timestamp)
|
|
127
|
+
.at(-1)
|
|
128
|
+
: null;
|
|
129
|
+
if (target) {
|
|
130
|
+
loose.set(target.id, [...(loose.get(target.id) ?? []), { ...node(c), loose: true }]);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
tops.push(c);
|
|
135
|
+
}
|
|
136
|
+
return tops.map(c => {
|
|
137
|
+
const prev = rec[c.id];
|
|
138
|
+
const own = authorOf(c) === us;
|
|
139
|
+
const dm = prev?.dm?.at
|
|
140
|
+
? {
|
|
141
|
+
at: prev.dm.at,
|
|
142
|
+
/* older records did not keep the text: the rule's, as it reads today */
|
|
143
|
+
text:
|
|
144
|
+
prev.dm.text ??
|
|
145
|
+
(rule
|
|
146
|
+
? gateOn(rule)
|
|
147
|
+
? openingText(rule, prev.username, C)
|
|
148
|
+
: deliveryPreview(rule, prev.username, post, C)
|
|
149
|
+
: null),
|
|
150
|
+
exact: !!prev.dm.text,
|
|
151
|
+
gate: prev.gate?.state ?? null,
|
|
152
|
+
}
|
|
153
|
+
: null;
|
|
154
|
+
const replies = [...(c.replies?.data ?? []).map(node), ...(loose.get(c.id) ?? [])].sort((a, b) =>
|
|
155
|
+
a.at.localeCompare(b.at),
|
|
156
|
+
);
|
|
157
|
+
return {
|
|
158
|
+
...node(c),
|
|
159
|
+
at: c.timestamp,
|
|
160
|
+
own,
|
|
161
|
+
replies,
|
|
162
|
+
dm,
|
|
163
|
+
/* what the agent already did with it (null: did not trigger, or not read yet) */
|
|
164
|
+
state: prev?.state ?? null,
|
|
165
|
+
reason: prev?.reason ?? prev?.error ?? null,
|
|
166
|
+
triggers: !own && rule ? triggers(rule, c.text, C) : false,
|
|
167
|
+
within_deadline: now - Date.parse(c.timestamp) <= DM_DEADLINE,
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* What happens to the rule when the post goes up. With enable_on_publish (the config's
|
|
174
|
+
* permanent approval) a rule not yet enabled enables now: without a rule it is born from
|
|
175
|
+
* the narration's keyword and the link found in the content; a draft enables as is. It
|
|
176
|
+
* never enables one the user disabled, one for any comment, nor one that doesn't add up
|
|
177
|
+
* (that one is written disabled, with the problems).
|
|
178
|
+
* @param {{ rule: Rule | null, enableOnPublish: boolean, keyword: () => string | null,
|
|
179
|
+
* link: () => { link: string, found_in: string } | null, now: number, C: OmnichatConfig }} p
|
|
180
|
+
* @returns {{ kind: "already_enabled", rule: Rule } | { kind: "off" } | { kind: "disabled_by_user" } | { kind: "any_comment" }
|
|
181
|
+
* | { kind: "no_keyword" }
|
|
182
|
+
* | { kind: "draft", rule: Rule, problems: string[], born: { keyword: string, found: { link: string, found_in: string } | null } | null }
|
|
183
|
+
* | { kind: "enable", rule: Rule, born: { keyword: string, found: { link: string, found_in: string } | null } | null }}
|
|
184
|
+
*/
|
|
185
|
+
export function publishedPlan({ rule, enableOnPublish, keyword, link, now, C }) {
|
|
186
|
+
if (rule?.enabled) return { kind: "already_enabled", rule };
|
|
187
|
+
if (!enableOnPublish) return { kind: "off" };
|
|
188
|
+
if (rule?.disabled_at) return { kind: "disabled_by_user" };
|
|
189
|
+
if (rule?.any_comment) return { kind: "any_comment" };
|
|
190
|
+
let r = rule;
|
|
191
|
+
let born = null;
|
|
192
|
+
if (!r) {
|
|
193
|
+
const kw = keyword();
|
|
194
|
+
if (!kw) return { kind: "no_keyword" };
|
|
195
|
+
const found = link();
|
|
196
|
+
r = {
|
|
197
|
+
...newRule(C),
|
|
198
|
+
keywords: [kw],
|
|
199
|
+
generic_phrases: true,
|
|
200
|
+
link: found?.link ?? "",
|
|
201
|
+
updated_at: new Date(now).toISOString(),
|
|
202
|
+
};
|
|
203
|
+
born = { keyword: kw, found };
|
|
204
|
+
}
|
|
205
|
+
const problems = ruleProblems(r, C);
|
|
206
|
+
if (problems.length) return { kind: "draft", rule: r, problems, born };
|
|
207
|
+
return { kind: "enable", rule: { ...r, enabled: true, enabled_at: new Date(now).toISOString() }, born };
|
|
208
|
+
}
|