Skip to content

Workspace Integrations Implementation

Status: Current implementation reference Scope: Factory workflow, workspace module, Studio workspace page, app integrations page

For the user-facing guide, see Integrations.

Purpose

Workspace integrations give Mozaiks one shared place to understand external services. The system separates what services exist, what the workspace has configured, and what a specific app needs.

This prevents generated apps from repeatedly asking for the same credentials and lets Studio show setup blockers only when an app actually depends on a service. Internal conversations are separate from this system: the app messages module owns threads and message records, while integrations can optionally deliver those message events to external channels.

Architecture

Catalog
  defines supported services and setup metadata

Workspace connector
  stores workspace-scoped credential metadata and vault references

App integration declaration
  records services a generated app needs plus allowed setup lanes

App facade/module/client
  consumes those services without exposing provider internals to app UI

Runtime Module

Module root:

factory_app/app/modules/workspace_integrations/

Main actions:

Action Responsibility
list_integrations Return catalog entries, environment-derived status, notes, and usage counts for apps owned by the caller.
get_integration Return one catalog entry with safe setup metadata.
set_integration_note Save an operator note.
save_workspace_connector Save a workspace-scoped connector and vault secret reference.
list_workspace_connectors Return saved workspace connectors with health metadata.
check_workspace_connector_health Run the registered server-side health check for a workspace connector; returns frontend-safe status and never secret values.
delete_workspace_connector Delete a saved workspace connector and vault secret.
declare_app_integration_needs Persist build-produced app requirements.
upsert_app_integration_need Create or update one app requirement.
delete_app_integration_need Soft-delete a removable app requirement.
list_app_integration_needs Return app requirements with live workspace setup overlay.

No action returns raw secret values.

Workspace connector actions act only on the caller's verified workspace: the workspace the validated token is bound to (AUTH_WORKSPACE_ID_CLAIM, default workspace_id), or a membership the host's module_scope_resolver hook asserted with verified_workspace_id. The optional workspace_id argument must name that workspace; any other workspace is refused, and a workspace or tenant selected by the request never chooses one. A signed-in caller with no verified workspace cannot use the connector actions, and list_app_integration_needs returns declarations without a connector overlay when no scope was requested. A requested workspace or tenant without verified identity is refused. With authentication off and development access, the action uses the requested workspace, then the dispatch workspace or tenant, then demo-workspace.

Workspace, app-catalog and declaration actions refuse a dispatch workspace or tenant that conflicts with the verified principal before storage or events. App declaration actions require the selected app to have an app registry record owned by the caller; the selected app may differ from Studio's loaded app. Module dispatch remains bound to the loaded host app. Catalog usage counts are limited to the caller's registry-owned apps. The AppGenerator tool writes declarations through the service directly under its build authorization.

The connector vault uses the same explicit app or workspace scope as the metadata record. A workspace connector is never selected by an app ID alone. App-level overrides and workspace defaults remain distinct even when their identifiers and service names happen to match.

The scoped vault never reads a secret record that lacks its app or workspace scope. Azure connector writes and deletes require permission to inspect all version properties and refuse a name with any unowned or unknown version. Prevent other principals from writing connector names during inspection and mutation; Azure has no atomic version-history lock across those calls. Deployments sharing one Mongo instance must not rely on different secret prefixes for isolation: the connector collection uses a fixed system database and its key omits the prefix. Use separate Mongo instances.

Build Workflow

AppGenerator owns the build-time flow:

  1. check_workspace_integrations lets planning inspect catalog status.
  2. IntegrationReadinessAgent resolves required, optional, and custom services, blocking only on required build_time or validation_time setup. Runtime-only needs remain recorded as deployment requirements without blocking generation.
  3. save_integration_manifest runs automatically after readiness and persists all app integration declarations, including runtime-only requirements.
  4. AppGenerator assembly materializes app/config/integrations.yaml and app/config/targets.json into generated app bundles.
  5. Monetizable apps receive a removable Mozaiks Pay declaration unless the build explicitly declared a different payment path.

Important files:

factory_app/workflows/AppGenerator/tools/check_workspace_integrations.py
factory_app/workflows/AppGenerator/tools/materialize_app_config_contracts.py
factory_app/workflows/AppGenerator/tools/save_integration_manifest.py
factory_app/workflows/AppGenerator/agents.yaml
factory_app/workflows/AppGenerator/tools.yaml

Setup Lanes

Integration requirements are not API-key-first. Each declaration may expose one or more setup lanes:

Lane Meaning
managed A hosted or managed provider can provision the setup for the app.
connect_account The user connects an account through an OAuth/OIDC-style flow.
bring_your_own_key The user supplies their own credential values through the connector UI.
not_required The integration is declared for metadata or optional readiness only.

Mozaiks Pay defaults to managed with bring_your_own_key as a supported self-host fallback. The OSS catalog only declares those lanes. Hosted provisioning, billing, marketplace, and provider mechanics remain outside OSS.

Studio UI

Workspace page:

/integrations
factory_app/app/admin/pages/WorkspaceIntegrationsPage.jsx

The page groups services by task state:

  • Needs attention: used by apps and missing setup.
  • Connected: ready from environment variables or a saved workspace connector.
  • Available: supported but not currently blocking any app.

App page:

/apps/:appId/integrations
factory_app/app/admin/pages/AppIntegrationsPage.jsx

The app page groups declarations by:

  • Required
  • Optional
  • App-specific

Status Rules

Catalog-backed services can be ready in either of two ways:

  • all required environment variables are present, or
  • a ready workspace connector exists for the service.

Custom services are not in the catalog, so they rely on connector status.

Optional defaults that a user turns off stay turned off for later builds of the same app.

Catalog Ownership

The current catalog is duplicated:

factory_app/build_context/integrations/catalog.yaml
factory_app/app/modules/workspace_integrations/backend/schemas.py

The YAML file is factory build context. The Python list is the runtime module's catalog. Keep both synchronized until the runtime loads the YAML through a strict typed catalog loader.

Both catalog copies must include setup-lane metadata so Factory workflows, generated app config, and Studio integration screens agree on the same setup contract.

Testing

Targeted tests:

python -m pytest tests/test_workspace_integrations_module.py tests/test_appgenerator_integration_manifest.py tests/test_check_workspace_integrations_tool.py -q --no-cov
npm --prefix web_shell run test:responsive-smoke -- --grep "workspace integrations|app integrations"

Also run the web shell build after UI changes:

npm --prefix web_shell run build