Skip to content

Plugin SDK: expose the composer's selected provider and carry new-thread draft metadata into provider options #4395

Description

@samanthar0se

The workflow

A plugin that ships both a provider (bb.providers.register) and composer UI needs two things. They apply to any provider plugin, not just the one that prompted this (Polytoken). Mode, profile, or agent selectors for ACP/OpenCode-style agents (#1093, #2787) are potential consumers when exposed through a provider plugin. This request does not add native ACP mode controls.

  1. Know which provider the composer is targeting. A composer plugin should only show its provider-specific control (for example a mode, profile, or "facet" chip) when its own provider is selected in that composer. It should hide the control after the user switches to Codex or Claude Code.
  2. Carry a choice made in the new-thread draft into the provider's configuration. The user picks something in the new-thread composer before the thread exists. That value should be persisted with the thread and handed to the provider plugin's deriveProviderOptions hook on each dispatch, so the bridge can start the session in that state.

What happens today

On public main at d81d3d1f8a5c55d7dafbd86b61d086aced02df90:

  • ComposerView exposes scope, layout, draft, and run state, but not the provider selected in that composer. Plugins have to guess from project defaults, which differ from the live picker value after a switch.
  • feat(plugin-sdk): add thread plugin metadata with review fixes #3555 added per-thread plugin metadata. A thread can be seeded with it only via createThreadRequestSchema.pluginMetadata, which requires origin: "plugin" (a plugin creating its own thread). A user-created thread from the ordinary new-thread composer cannot carry any plugin's namespace, and a composer plugin has no draft-scoped place to store it.
  • PluginProviderOptionsContext gives deriveProviderOptions the thread, project, model, permission mode, prompt mode, and settings, but not the provider plugin's own thread metadata. So even stored metadata cannot influence provider options without a separate side channel.

What you would expect

Three experimental, opt-in additions. A working prototype is linked below.

  1. ComposerView.experimental_selectedProviderId: string | null: the effective provider in the composer where the plugin is mounted. It is reactive to provider switches, including when a project default differs from the selected value. It is null while unresolved or where the host does not supply it; the prototype wires new-thread and follow-up composers, and other surfaces report null. It exposes no provider metadata or server state.
  2. New-thread draft metadata: useComposer().experimental_pluginMetadata / experimental_setPluginMetadata(obj). This is a persistent JSON object per plugin, keyed by the existing prompt-draft storage key. A plugin reads and writes only its own namespace, and an empty object clears it. The getter is null and the setter absent when the host composer doesn't support it. On submit, the map is sent as createThreadRequestSchema.experimental_pluginMetadataByPlugin and written into each plugin's feat(plugin-sdk): add thread plugin metadata with review fixes #3555 namespace in the same transaction as thread creation.
    • It is rejected with origin: "plugin", originKind, or sourceThreadId (forks). Plugin-origin requests keep using pluginMetadata.
    • The aggregate limit is 256 KiB.
    • It is not echoed in thread responses.
    • On submit it is cleared together with the text draft and restored together with it if creation fails, so newer edits are never mixed with the old pair.
    • CLI (bb thread spawn) and SDK (threads.create) can pass the map and keep their normal origin.
  3. PluginProviderOptionsContext.experimental_pluginMetadata: the owning provider plugin's own per-thread metadata, read synchronously on each dispatch. It is deep-frozen, {} when absent or corrupt, and treated as untrusted, user-writable, nonsecret JSON. The hook decides which values to use. A test asserts the raw snapshot is not serialized into command output. No server/daemon wire change: deriveProviderOptions runs server-side.

Non-goals / limits:

  • No provider-state observation, no model-ownership semantics, and no native mode/facet placement. Those are a separate design-alignment topic (see Context).
  • No metadata for forks or follow-up turns. Only thread creation seeds it; after that, existing feat(plugin-sdk): add thread plugin metadata with review fixes #3555 thread metadata APIs apply.
  • All three members use the experimental_ prefix, with docs/api_to_audit.md entries listing the stabilization audits: cross-surface consistency for selectedProviderId, namespace ownership, reload/provider-switch isolation, concurrency, and size semantics.

Context and alternatives

Prototype (fork branch, not a PR; opening an issue first per CONTRIBUTING):

Verification on the prototype (rebased onto d81d3d1f8, macOS, Node 26.8.2):

  • pnpm exec turbo run typecheck passed for app, server, cli, db, plugin-sdk, sdk, and server-contract. Lint passed with 0 errors (warnings only).

  • Targeted tests:

    Package Tests
    @bb/app (10 composer/prompt-box/plugin-host files) 191/191
    @bb/server (test/threads + provider registration) 529/529
    @bb/db (test/data) 438/438
    @bb/cli (thread-spawn) 48/48
    @get-bb/plugin-sdk (public types, app harness) 65/65
    @bb/sdk 113/113
    @bb/server-contract 84/84
    scheduled-send plugin 22/22
  • Mutation checks: removing the ROOT-fork metadata guard makes the fork-rejection test fail, and the remaining metadata tests cover stale-generation writes, clear/restore pairing, contract rejections, 256 KiB limit, and runtime-config injection.

Related, not duplicates:

Alternatives considered:

  • Deriving the provider from project defaults in the plugin breaks after an in-composer switch.
  • Storing draft state in plugin-private storage and patching thread metadata after creation leaves a race with the first dispatch, and the first turn misses the value.
  • A plugin-side RPC from the bridge to fetch metadata puts a side channel on the hot dispatch path, where the server already holds the data.

Verification limit: fork rejection is tested by seeding the fork through useRootComposeForkSeed. The location-state fork path has a separately reproduced upstream test regression on current main, not verified in the live app. The prototype was not exercised in the live app.

Checks

  • I searched open and closed issues for the same request.
  • If an agent wrote this, the body ends with > AGENT GENERATED.

AGENT GENERATED

Activity

  1. added
    plugins
    providers
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pluginsproviders

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions