Skip to content

feat(ai): add Muse (Meta Model API) provider - #1586

Merged
nguyenvantruc92 merged 1 commit into
mainfrom
feat/ai-muse
Nov 1, 2026
Merged

nguyenvantruc92 merged 1 commit into
mainfrom
feat/ai-muse

Conversation

@nguyenvantruc92

@nguyenvantruc92 nguyenvantruc92 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Muse (Meta Model API, https://api.meta.ai/v1) as an AI provider. A workspace connects it with an API key, like Claude, DeepSeek and Gemini.

Muse can be used in:

  • AI flow steps: generate text, text agent, extract data, analyze image, generate image, edit image, delete message history
  • AI agents and AI agent actions
  • Call summaries and appointment availability replies
  • Speech to Text (WAV only, see below)

This PR also fixes two bugs that affect all providers:

  • AI steps reported success with empty text when the provider stream failed.
  • In AI agent replies, text written before a tool call ran into the text after it.

Deploy

Deploy the worker before the builder. Once the builder is out, users can connect Muse and save Muse steps, and an older worker cannot run them.

Changes

Muse provider

  • packages/ai: createMuse, built on @ai-sdk/openai-compatible. Each request is adjusted for Muse:
    • reasoning_effort is minimal below 1024 tokens, otherwise low.
    • 1024 tokens are added to max_tokens for reasoning, so short replies do not come back empty.
    • temperature is capped at 1.
    • Muse accepts only tool_choice: "auto". A forced choice becomes auto, and none removes the tools.
  • Models: muse-spark-1.3 (default), muse-spark-1.2, muse-wonder-1.0 (preview) and muse-image-1.0.
  • packages/database: new IntegrationMuse table (migration 20261027162148_add_integration_muse, new table only). muse is added to integrationTypes and aiAgentProviders.
  • packages/business: connect, update and disconnect; API key check against GET /v1/models; cleanup when a workspace is deleted. Defaults are muse-spark-1.3 and 4096 tokens.
  • packages/connections: Muse can be connected with POST /v1/connections. The old /v1/integrations/ai/{provider} routes also accept muse.
  • packages/flow-config: Muse is added to the AI step providers. Generate text and analyze image reject a Muse temperature above 1.
  • apps/builder: settings page settings/integrations/muse, Muse in the model selects and the perform-action menu, and strings in all 21 locales.

Muse images

  • Muse always returns WebP, and WhatsApp shows WebP as a sticker. Generate image and edit image now convert WebP to JPEG, or to PNG when the image has transparency (heavy/handlers/channel-safe-image.ts).
  • Edit image checks that the input really is an image. A non-image input goes to the error branch instead of being retried.

Speech to Text with Muse

Muse accepts only WAV: PCM 16-bit, mono, 16 or 24 kHz, at most 10 minutes. Anything else (Ogg voice notes, mp3, stereo, 44.1 kHz) goes to the error branch. Nothing is converted, because the heavy worker has no ffmpeg.

  • The step schema is now one shape per provider (openai | muse). Muse steps can set languageBias and keywords.
  • packages/ai/src/server/muse-transcribe.ts: the transcription client. It checks the WAV header, not the content type.
  • New env settings: MUSE_TRANSCRIBE_MAX_AUDIO_BYTES (default 32 MiB − 64 KiB) and MUSE_TRANSCRIBE_TIMEOUT_MS (default 9 minutes). The heavy worker lock and the step deadline grow to fit them.
  • The heavy job id is sent to Meta as sessionId, so every retry of one step run uses the same session.

Test plan

  • Package tests: flow-config, worker-config, ai, worker, builder
  • turbo check-types
  • Manual end-to-end runs against the real Muse API, with local scripts that are not part of this PR: provider steps and Speech to Text both pass, except the public Flow API error message above
  • pnpm lint (includes db:check-drift)
  • Apply the migration on a dev database
  • Manual: connect Muse with a real key, then run generate text, generate image (WhatsApp receives a JPEG), edit image and Speech to Text (a WAV file succeeds, an Ogg voice note goes to the error branch)
  • Docker build of the worker image

@github-actions github-actions Bot added the feature New feature or request label Oct 29, 2026
@nguyenvantruc92
nguyenvantruc92 force-pushed the feat/ai-muse branch 3 times, most recently from f7d9ac6 to 9907eb1 Compare October 31, 2026 05:39
Adds Muse (Meta Model API) as an AI provider: a Muse integration in
workspace settings, Muse models for the flow AI steps, and Muse voice
transcribe as a Speech to Text provider.

Muse voice transcribe provider for Speech to Text

Muse accepts only WAV (PCM 16-bit, mono, 16/24 kHz, at most 10 min,
request at most 32 MB). The step checks the RIFF header and sends any
other file (ogg voice notes, mp3, stereo, 44.1 kHz) to the error branch.
Nothing is converted, because the heavy worker has no ffmpeg.

- The flow-config schema becomes a provider union (openai | muse). The
  Muse branch adds languageBias and keywords; OpenAI steps reject both.
- The heavy worker gets a Muse transcription client, MUSE_TRANSCRIBE_*
  env limits and a per-provider attempt budget. The budget sizes the
  completion deadline, the fallback resume and the heavy lock (10 min);
  the outcome TTL now outlives that deadline.
- The heavy job id is sent as Meta's sessionId and stays the same across
  BullMQ retries.
- A malformed transcribe response is not retried, and only transcript is
  required in the response schema.
- No content-type allowlist: inspectMuseWav decides, so WAV served as
  binary/octet-stream or without a header is accepted.
- Builder: a Muse Speech to Text menu entry, a provider-aware dialog
  with a WAV format note, and i18n strings in all 21 locales.

Muse request shaping

- Muse counts reasoning against max_tokens, so the provider adds 1024
  tokens of headroom: without it Spark 1.3/1.2 return empty replies at an
  agent budget of 100 and the 128-token handoff classifier never fits its
  tool call. maxOutputTokens is therefore the reply-text budget for Muse;
  the API descriptions say the extra reasoning tokens are billed.
- Muse temperature is at most 1 (at 2 it returns empty replies or 500s).
  The Generate Text and Analyze Image step schemas reject a higher value,
  the step dialog caps the input, and the provider still clamps agents.
- Muse accepts only tool_choice "auto". A named or "required" choice
  becomes "auto" and "none" drops the tools; before this the handoff
  re-entry classifier got a 400 on every Muse model.

Heavy step outcome

- Heavy step results move from one outputValue to outputValues[] plus a
  skip status; the Redis outcome records resultStatus so a retried skip
  still resumes through skip.
- outputValues are stored on the outcome when the write is claimed; a
  retry after a partial write replays them instead of calling the
  provider again (no double billing, no re-reading an overwritten input
  field). STALE_WRITE_MS is 10s so speech retries (15s backoff) also
  replay; the resume lease keeps its own 30s constant.
- A fresh write lease held by another attempt returns "busy" instead of
  "writing", which let two attempts write the same fields.

AI agent replies

- textStream concatenates every step's text, so text a model writes
  before a tool call ran into the reply after the tool result. The text
  is rebuilt from result.stream with a paragraph break between steps, so
  each step is sent as its own message.
- AI Action set_custom_field ids are opaque createId() values, so the
  model left `values` empty unless the When text spelled out what to
  save. The tool description now names the custom field behind each
  value action.

The AI Segment Image step (SAM 3.1) and @meta-sam/parser (SAM License)
are not part of this change; they are kept on a separate branch until
Meta confirms the license. Deploy the worker before the builder.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nguyenvantruc92
nguyenvantruc92 merged commit 2a81a74 into main Nov 1, 2026
17 checks passed
hello-jackytruong referenced this pull request in hello-jackytruong/ChatWorkAI Nov 22, 2026
Adds Muse (Meta Model API) as an AI provider: a Muse integration in
workspace settings, Muse models for the flow AI steps, and Muse voice
transcribe as a Speech to Text provider.

Muse voice transcribe provider for Speech to Text

Muse accepts only WAV (PCM 16-bit, mono, 16/24 kHz, at most 10 min,
request at most 32 MB). The step checks the RIFF header and sends any
other file (ogg voice notes, mp3, stereo, 44.1 kHz) to the error branch.
Nothing is converted, because the heavy worker has no ffmpeg.

- The flow-config schema becomes a provider union (openai | muse). The
  Muse branch adds languageBias and keywords; OpenAI steps reject both.
- The heavy worker gets a Muse transcription client, MUSE_TRANSCRIBE_*
  env limits and a per-provider attempt budget. The budget sizes the
  completion deadline, the fallback resume and the heavy lock (10 min);
  the outcome TTL now outlives that deadline.
- The heavy job id is sent as Meta's sessionId and stays the same across
  BullMQ retries.
- A malformed transcribe response is not retried, and only transcript is
  required in the response schema.
- No content-type allowlist: inspectMuseWav decides, so WAV served as
  binary/octet-stream or without a header is accepted.
- Builder: a Muse Speech to Text menu entry, a provider-aware dialog
  with a WAV format note, and i18n strings in all 21 locales.

Muse request shaping

- Muse counts reasoning against max_tokens, so the provider adds 1024
  tokens of headroom: without it Spark 1.3/1.2 return empty replies at an
  agent budget of 100 and the 128-token handoff classifier never fits its
  tool call. maxOutputTokens is therefore the reply-text budget for Muse;
  the API descriptions say the extra reasoning tokens are billed.
- Muse temperature is at most 1 (at 2 it returns empty replies or 500s).
  The Generate Text and Analyze Image step schemas reject a higher value,
  the step dialog caps the input, and the provider still clamps agents.
- Muse accepts only tool_choice "auto". A named or "required" choice
  becomes "auto" and "none" drops the tools; before this the handoff
  re-entry classifier got a 400 on every Muse model.

Heavy step outcome

- Heavy step results move from one outputValue to outputValues[] plus a
  skip status; the Redis outcome records resultStatus so a retried skip
  still resumes through skip.
- outputValues are stored on the outcome when the write is claimed; a
  retry after a partial write replays them instead of calling the
  provider again (no double billing, no re-reading an overwritten input
  field). STALE_WRITE_MS is 10s so speech retries (15s backoff) also
  replay; the resume lease keeps its own 30s constant.
- A fresh write lease held by another attempt returns "busy" instead of
  "writing", which let two attempts write the same fields.

AI agent replies

- textStream concatenates every step's text, so text a model writes
  before a tool call ran into the reply after the tool result. The text
  is rebuilt from result.stream with a paragraph break between steps, so
  each step is sent as its own message.
- AI Action set_custom_field ids are opaque createId() values, so the
  model left `values` empty unless the When text spelled out what to
  save. The tool description now names the custom field behind each
  value action.

The AI Segment Image step (SAM 3.1) and @meta-sam/parser (SAM License)
are not part of this change; they are kept on a separate branch until
Meta confirms the license. Deploy the worker before the builder.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant