refactor: switch from mux/ai package to 🤐#230
refactor: switch from mux/ai package to 🤐#230walkerfrankenberg wants to merge 6 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lib/robots-client.ts
Outdated
|
|
||
| type FetchFn = typeof globalThis.fetch; | ||
|
|
||
| function toBase64(str: string): string { |
There was a problem hiding this comment.
it was erroring when I tried to use btoa 😕
errorName: 'ReferenceError',
errorStack: 'ReferenceError: btoa is not defined\n' +
' at getAuthHeader (lib/robots-client.ts:5:4)\n' +
' at createModerationJob (lib/robots-client.ts:21:27)\n' +
' at moderateAndSummarize (workflows/process-mux-ai.ts:62:45)\n' +
There was a problem hiding this comment.
is this a node-like vs. browser-like/Web API issue? should we use Buffer here? e.g. const encoded = Buffer.from("string-to-encode").toString('base64');
cjpillsbury
left a comment
There was a problem hiding this comment.
Left some comments but saving approve for @philcluff on his return.
| import { sendSlackModerationResult, sendSlackSummarizationResult, sendSlackAutoDeleteMessage } from '../lib/slack-notifier'; | ||
| import { checkAndAutoDelete, checkAndAutoDeleteWatchParty } from '../lib/moderation-action'; | ||
| import type { CaptionHookPayload, CaptionStatus } from '../types'; | ||
| import { createModerationJob, createSummarizeJob, createAskQuestionsJob, getJobStatus } from '../lib/robots-client'; |
There was a problem hiding this comment.
question(non-blocking): Should we have kept the creation + polling per workflow abstracted away from this module to denoise and keep the code similar to directly using robots? I can envision future cases where we are building/dog-fooding things in stream.new defined in our SDK but not yet supported by robots (or possibly even never intended to be supported in robots?)
| } | ||
|
|
||
| // Event type not handled | ||
| return NextResponse.json({ message: 'Event type not handled' }); |
There was a problem hiding this comment.
question(non-blocking): Should this be a 200 (noticed the equivalent from the old impl is the same here)
There was a problem hiding this comment.
I believe so, non-2xx responses are considered delivery failures and will cause us to retry the webhook. Returning a non-2xx for an event type we intentionally don't handle would cause unnecessary retries
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| /// <reference types="next" /> | ||
| /// <reference types="next/image-types/global" /> | ||
| import "./.next/types/routes.d.ts"; | ||
| import "./.next/dev/types/routes.d.ts"; |
There was a problem hiding this comment.
Accidentally committed auto-generated dev path change
Low Severity
The import path changed from .next/types/routes.d.ts to .next/dev/types/routes.d.ts. The developer confirmed this was auto-generated by running next dev and was not an intentional change. This file states "NOTE: This file should not be edited." Committing a dev-specific generated path adds noise to the diff and may diverge from what next build produces in CI.


Overview
Replace the
@mux/aipackage and its dual OpenAI/Hive moderation providers with direct calls to the Mux Robots API. Migrate all HTTP calls fromgotto nativefetch, fix the resulting test breakages, and add missingresponse.okchecks.What was changed
lib/robots-client.ts(new) — HTTP client for the Mux Robots API (/jobs/moderate,/jobs/summarize,/jobs/ask-questions, polling via/jobs/:id)types/robots.ts(new) — TypeScript types for Robots API job responses and outputs, replacing@mux/ai/workflowstypesworkflows/process-mux-ai.ts— Rewrote the workflow to userobots-clientinstead of@mux/ai. Removed caption-hook machinery (no longer needed); moderation now uses a single provider instead of OpenAI + Hiveapp/api/webhooks/mux/route.ts(new, replacesmux-ai/route.ts) — Simplified webhook handler; only handlesvideo.asset.ready, removedtrack.ready/track.erroredcaption-hook logiclib/moderation-action.ts— Switched fromgottofetch, collapsed dual-provider logic into singlemoderationResult, addedresponse.okcheck on Airtable calllib/slack-notifier.ts— Switched fromgottofetch, merged dual OpenAI/Hive score display into single moderation block, addedresponse.okchecks on all Slack webhook callsapp/api/report/route.ts— Switched fromgottofetch, addedresponse.okcheck on Airtable calllib/moderation-action.spec.ts— Updated types, set Airtable env vars inbeforeEach, hardcoded nock URLs to matchlib/slack-notifier.spec.ts— Updated types, added@jest-environment nodeforfetchavailabilitypackage.json— Removed@mux/ai, upgradednockto v14 (nativefetchinterception)Suggested review order
types/robots.ts— new type definitions that everything else depends onlib/robots-client.ts— new API client; check auth, polling, and error handlingworkflows/process-mux-ai.ts— core workflow rewriteapp/api/webhooks/mux/route.ts+ deletedmux-ai/route.ts— webhook simplificationlib/moderation-action.ts+lib/slack-notifier.ts+app/api/report/route.ts—got→fetchmigration andresponse.okfixeslib/moderation-action.spec.ts+lib/slack-notifier.spec.ts— test fixesNote
Medium Risk
Moderation and auto-deletion flow is reworked to a new Robots job/polling integration and webhook entrypoint, which could affect content deletion and notifications if job status handling or auth is misconfigured. Signature verification behavior is tightened in production, which may reject webhooks if env configuration is incomplete.
Overview
Replaces the
@mux/aidual-provider (OpenAI/Hive) workflow with direct Mux Robots API jobs formoderate,summarize, andask-questions, including newlib/robots-client.ts, Robots output types, and polling/normalization logic inworkflows/process-mux-ai.ts.Simplifies the Mux webhook surface by deleting
app/api/webhooks/mux-ai/route.ts(caption hook + track event handling) and addingapp/api/webhooks/mux/route.tsthat only starts the workflow onvideo.asset.ready, while requiring signature verification in production.Migrates outbound HTTP from
gotto nativefetchacross Airtable/Slack/reporting code paths, addingres.okchecks and removinglib/got-client.ts; Slack moderation messaging is collapsed to a single moderation score block, tests are updated accordingly, and@mux/ai/gotdeps are removed (withnockbumped to v14).Written by Cursor Bugbot for commit 124d498. This will update automatically on new commits. Configure here.