Skip to content

refactor: switch from mux/ai package to 🤐#230

Open
walkerfrankenberg wants to merge 6 commits intomainfrom
wf/use-robots
Open

refactor: switch from mux/ai package to 🤐#230
walkerfrankenberg wants to merge 6 commits intomainfrom
wf/use-robots

Conversation

@walkerfrankenberg
Copy link

@walkerfrankenberg walkerfrankenberg commented Mar 17, 2026

Overview

Replace the @mux/ai package and its dual OpenAI/Hive moderation providers with direct calls to the Mux Robots API. Migrate all HTTP calls from got to native fetch, fix the resulting test breakages, and add missing response.ok checks.

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/workflows types
  • workflows/process-mux-ai.ts — Rewrote the workflow to use robots-client instead of @mux/ai. Removed caption-hook machinery (no longer needed); moderation now uses a single provider instead of OpenAI + Hive
  • app/api/webhooks/mux/route.ts (new, replaces mux-ai/route.ts) — Simplified webhook handler; only handles video.asset.ready, removed track.ready/track.errored caption-hook logic
  • lib/moderation-action.ts — Switched from got to fetch, collapsed dual-provider logic into single moderationResult, added response.ok check on Airtable call
  • lib/slack-notifier.ts — Switched from got to fetch, merged dual OpenAI/Hive score display into single moderation block, added response.ok checks on all Slack webhook calls
  • app/api/report/route.ts — Switched from got to fetch, added response.ok check on Airtable call
  • lib/moderation-action.spec.ts — Updated types, set Airtable env vars in beforeEach, hardcoded nock URLs to match
  • lib/slack-notifier.spec.ts — Updated types, added @jest-environment node for fetch availability
  • package.json — Removed @mux/ai, upgraded nock to v14 (native fetch interception)

Suggested review order

  1. types/robots.ts — new type definitions that everything else depends on
  2. lib/robots-client.ts — new API client; check auth, polling, and error handling
  3. workflows/process-mux-ai.ts — core workflow rewrite
  4. app/api/webhooks/mux/route.ts + deleted mux-ai/route.ts — webhook simplification
  5. lib/moderation-action.ts + lib/slack-notifier.ts + app/api/report/route.tsgotfetch migration and response.ok fixes
  6. lib/moderation-action.spec.ts + lib/slack-notifier.spec.ts — test fixes

Note

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/ai dual-provider (OpenAI/Hive) workflow with direct Mux Robots API jobs for moderate, summarize, and ask-questions, including new lib/robots-client.ts, Robots output types, and polling/normalization logic in workflows/process-mux-ai.ts.

Simplifies the Mux webhook surface by deleting app/api/webhooks/mux-ai/route.ts (caption hook + track event handling) and adding app/api/webhooks/mux/route.ts that only starts the workflow on video.asset.ready, while requiring signature verification in production.

Migrates outbound HTTP from got to native fetch across Airtable/Slack/reporting code paths, adding res.ok checks and removing lib/got-client.ts; Slack moderation messaging is collapsed to a single moderation score block, tests are updated accordingly, and @mux/ai/got deps are removed (with nock bumped to v14).

Written by Cursor Bugbot for commit 124d498. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stream-new Ready Ready Preview, Comment Mar 25, 2026 9:18pm

Request Review


type FetchFn = typeof globalThis.fetch;

function toBase64(str: string): string {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' +

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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');

@philcluff philcluff changed the title refactor: switch from mux/ai package to robots API refactor: switch from mux/ai package to 🤐 Mar 17, 2026
@walkerfrankenberg walkerfrankenberg marked this pull request as draft March 17, 2026 19:18
Copy link
Contributor

@cjpillsbury cjpillsbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking): Should this be a 200 (noticed the equivalent from the old impl is the same here)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants