Skip to content

Several AI connections at once, one per provider - #2069

Merged
davidmckayv merged 30 commits into
mainfrom
guido/multiple-subs
Nov 25, 2026
Merged

davidmckayv merged 30 commits into
mainfrom
guido/multiple-subs

Conversation

@guidovizoso

@guidovizoso guidovizoso commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What this changes

Several AI connections at once, one per provider. A person who pays for a Claude plan and a ChatGPT plan, or holds a few keys, keeps all of them connected and picks a model from any of them per conversation, instead of switching one connection that moves every Bot and conversation.

API (api/openapi/model-connections.yaml, bots.yaml). Only grows; nothing existing changes meaning. Today's single-connection operations describe the default connection.

  • Organization (admins): listAiConnections, connectAiConnection, removeAiConnection, makeAiConnectionDefault under /ai-connections.
  • A person's own (OpenBot Cloud): the same four under /people/{personId}/ai-connections.
  • Organization sign-ins: startAiSignIn, getAiSignIn, finishAiSignIn under /ai-connection-sign-ins, as the personal ones, on OpenBot Cloud and a self-hosted OpenBot. OpenBot Desktop running its own OpenBot keeps its own plan sign-in (signIns empty).
  • Optional fields: ModelCatalogue.connections (each connection's models, owner, source, ready, problem), ModelChoice.connection and stopped, ModelChoiceInput.connection, and a Bot's defaultModel input source.
  • Rules: connecting a provider that already has a connection replaces it and keeps its id; the first is the default; a removal that leaves exactly one makes it the default; with more and none the default, a run with no pick gets a stopped choice (no-default). Ids are unique within their list only.

App.

  • Settings → Providers is its own screen (it was AI model, under General), and Admin → Providers the same: one row per connection with a Default tag, each opening that provider's page (Make default, Change, Disconnect). Connect another AI is a page too. A stopped connection's page leads with Sign in again or Replace key. Dialogs stay only where a released server or Desktop needs the old single connection.
  • The composer's model picker has a providers rail once two or more AIs are connected, the default first: the list shows the chosen one's models and opens on the one in use, a search looks through all of them, and a pick saves its connection. It stays when the default can't be read or there is none, so another connection can still be picked.
  • A refused turn whose connection stopped working says so, with Reconnect for whoever can fix it and Choose another model; with no default, Choose a default.
  • A Bot's default model applies on any of a person's connections of its kind.
  • Against an OpenBot without the list (404), every screen draws what it drew before.

Draft until it has been run against a server that answers the new operations.

Where it runs

  • New state that outlives a request? None in the app. Connections and the default live in the database, on the server.
  • What happens on the second replica? Nothing new here: every read goes to the API, and the app keeps no state of its own beyond the query cache.
  • Anything serialised? Not here. Making a default and removing one are separate requests; the server answers for doing them at once.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act.
  • New refusals and new failures each write a row (connect, remove and make-default are audited; a turn refused because its connection stopped is kept as a refused turn, AI_CONNECTION_STOPPED).
  • Nothing new is trusted from the client that the server can resolve itself: a run reads the pick from the server's record, never from the browser.

API and database

  • It changes api/ and keeps every rule: only new operations and optional fields, new answer enums open (x-extensible-enum, never reachable from a request), no key or address in any answer, and the existing operations keep their meaning so a released app behaves as before. No database change in this repository.

Changelog

  • A line in CHANGELOG.md under Unreleased, API.

Proof

  • bun run api:lint, bun test api/ (78 pass), bun run format:check, bun run lint, bun run typecheck.
  • App tests for every touched screen in happy-dom (all pass), and the Settings files that need a real browser in Chromium (OPENBOT_APP_BROWSER=1).
  • Not yet seen against a server that answers the new operations.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The shape is right: the spec only grows, every write carries an Idempotency-Key, the new extensible enums appear only in answers, the 404 fallback really does draw the old screens, and Reconnect appears only for whoever can fix it. Four things to fix before this goes in, plus two small ones.

Should fix

  1. The picker disappears when the default connection can't be read. model-picker.tsx:169 returns before the grouped branch when !catalogue.choosable. With several connections, the top-level fields describe the default. So when the default's Claude sign-in ends but an OpenAI connection still works, the picker is gone. "Choose another model" in the stopped notice (stopped-connection-notice.tsx:16) then clicks a trigger that isn't there and does nothing. The same applies to the no-default case. Fix: when pickerGroups(catalogue) is non-empty, skip the choosable gate, or base it on whether any connection is ready. Add a test with choosable: false plus connections.

  2. Change on a non-default row adds a connection instead of changing that one. ai-connection-list.tsx:349-356 (button at :500) opens "Connect another AI" with no provider preset. If the person picks a different provider there, the old row stays and a new one appears. The fix step at :366-373 already presets provider: entry.provider; Change should do the same.

  3. The Disconnect dialog contradicts itself. At :284 and :390, removing the default when two or more others remain but none is ready gives choosing=false. The dialog then says "Bots can't run until you connect another" while other connections are still listed under it.

  4. Two existing operations don't say what they do once there are several connections (model-connections.yaml:447-466, 543-555).

    • deleteAiConnection still says "Afterwards the organization has no AI". The new list description says the others stay and the organization is left with no default.
    • replaceAiConnection doesn't say what happens when the new provider already has its own connection. Does it replace the default, merge into that provider's connection, or move ids?
    • The default row's Change still calls replaceAiConnection (ai-connection-list.tsx:331), so this is a live path. State both rules in those descriptions, and the same for the personal pair.

Small

  • A failed Make default leaves the list stale. It invalidates on success only (mutations.ts:423), so a 409 not-ready leaves the row showing ready. Use onSettled, as remove does.
  • mutations.ts:435 says "The server never moves the default by itself". The spec says a removal that leaves exactly one makes it the default.

On the open call (a run refused because its connection stopped): record it as a refused turn. Whether a run is stopped is known before the run is admitted, just like the allowlist, which is recorded. Without a record, after a reload the person's message sits unanswered with no reason, and on Cloud the free run has already been spent. In this PR that only means updating the listRefusedTurns description, which names three codes today, to include the stopped-connection code. RefusedTurn.code is already a plain string.

List, connect, remove and make default the organization's AI connections
and a person's own, and sign the organization in to a provider the way a
person signs in. The single-connection operations keep their meaning and
describe the default connection. The model catalogue lists each
connection's models, a model choice names its connection and says when it
stopped, and a Bot's default model input can name its source. Every new
field is optional, so an older client sends and reads what it did.
AI model, Your AI and Admin, Providers draw one row per connection where
the server lists them: the default tagged once there are two, Make
default, Change and Disconnect in each row's dialog, and Connect another
AI with the shared chooser in a new adding mode. Disconnecting the
default asks which connection takes over and makes it the default first.
Connections with no default say so. The organization's sign-ins go
through its own sign-in operations. Against a server older than the list,
or with nothing connected yet, the sections draw the one row they drew
before.
… connection

With several connections the composer's picker lists each one's models
under its name, the default first, and a stopped connection's group says
why in place of its models. Picking saves the connection with the model,
so the same model on two connections is two choices and changing the
default never moves a pick. A pick whose connection is gone shows the
default and saves nothing; with no default the picker asks to choose.
With one connection it is the picker it was.
After a refused turn the conversation reads its model choice again. When
the server says the connection the next run would use is connected but
can't run, a notice under the turn gives its sentence, Reconnect into
that connection's row in Settings for whoever can fix it, and Choose
another model, which opens the composer's picker. The picker's trigger
carries a warning mark meanwhile. Nothing reads the refusal's own words,
and an older server draws nothing new.
A Bot is shared and each person runs it on their own connections, so its
default keeps naming a kind of connection. With several connections it
applies on the first ready connection of that kind that lists the model,
not only on the one in use, and falls back to the default connection's
default otherwise. The Default model section picks from the grouped list
and saves the group's kind as the source; with one connection it sends
none, as before.
…tays put

When an older app disconnects the default and one connection is left, the
picker names it so a conversation can still run on it. A pick on a
connection that stopped working is shown on that connection, by its id
if the connection lists nothing, instead of moving to the default's
model.
…efault

The sentence after Connect another AI or a row's Change read whether the
new connection is the default from the list as it stood, and was wrong
with no default or when the default's own provider was connected again.
It now follows the server's answer.
A conversation's Reconnect link now says whose connection it is, and only
that list in Settings opens its row: on OpenBot Cloud an admin's own
connection and the organization's may share an id, and both dialogs used
to open. The API says ids are unique within their list only.
In Settings a stopped row's dialog leads with Sign in again or Replace
key, which opens the chooser on that provider under a title naming the
fix. In the model picker, a stopped connection of the person's own gets
a Reconnect link in its group; the organization's waits on an admin.
When the last connection that can run is disconnected, the confirm step
uses the sentences the single connection's dialogs always used: a
person's runs fall back to the organization's AI, the organization's on
OpenBot Cloud leaves only people with their own, otherwise Bots can't
run. A person left with no AI where one is required is sent to connect
one again.
As agreed for the backend: when a removal leaves exactly one AI
connection, the server makes it the default, so disconnecting the default
with one other left asks nothing. With more left and none the default, a
run with no pick is refused and the conversation's model choice says so
(stopped, no-default), and the notice links to choosing a default.
Organization sign-ins are offered on OpenBot Cloud and a self-hosted
OpenBot; OpenBot Desktop keeps its own plan sign-in.
…rs do

Since TrustedRouter, a provider in an answer is AiConnectionProviderAnswer,
so a released app doesn't break when one is added. The connection list
and the catalogue's connections now use it too, and the app's names
accept a provider it doesn't know.
…lt example that can happen

Words for three new audit events the backend records: the organization's
or a person's default AI changed, and an organization sign-in. The
example of connections with no default now shows two left, since one
left becomes the default.
…nd for connecting another

"AI model" leaves Settings → General for Settings → Providers, first under Every Bot. Each
connected provider's row leads to its own page (details, Change or Sign in again, Make default,
Disconnect with what happens said beside it), and Connect another AI and Change are pages too,
not dialogs. Admin → Providers draws the same pages under /admin/providers. A conversation's
Reconnect and Choose a default lead there. The one-row screens kept for an older server or an
older OpenBot Desktop keep their dialogs.
One button per connection down the popup's left edge, the default first, as T3 Code's picker
has its providers. The list shows the chosen connection's models and opens on the one in use; a
search looks through every connection, each under its name. A connection that can't run is marked
on the rail and says why when chosen. With one connection there is no rail.
…refused Make default reads the list again, and Change keeps to its provider
…tions, and a refused turn can be a stopped AI connection
@guidovizoso

Copy link
Copy Markdown
Collaborator Author

Thanks, Dave. All fixed, and the branch is rebased on main again. One thing changed under you since your review: Settings → Providers is now its own screen with a page per provider (and Admin → Providers the same), and the composer's picker has a providers rail once two or more AIs are connected.

  1. Picker vanishing. The choosable gate was in two places: the picker, and the conversation's model hook, which also skipped reading stopped. Both now use canChoose, which counts the other connections, so a stopped default or no default still draws the picker and "Choose another model" works. Test with choosable: false plus connections, both cases.
  2. Change on a non-default connection. Change now opens that provider's own page, preset to it, with no other provider to pick. Test added.
  3. Disconnect copy. Removing the default when the others left can't run now says so: there's no default until one is fixed and made the default. Test added.
  4. replaceAiConnection / deleteAiConnection and the personal pair now state the several-connections rules. Replace makes the saved connection the default, in place of that provider's own (same id), and the old default stays as one of the others. The organization's delete leaves the others; exactly one left becomes the default, more leave none. The personal delete removes all of a person's connections.

Small ones: Make default invalidates on settled (test with a 409), and the comments now say the server moves the default only when a removal leaves exactly one.

Your call: listRefusedTurns and RefusedTurn.code now name AI_CONNECTION_STOPPED, for a stopped connection and for no default. The app already draws stored refused turns, with the Reconnect notice under the latest.

Also: main's new rule that every answer declares X-Request-Id now covers the new operations. The description is reworded.

@guidovizoso
guidovizoso marked this pull request as ready for review November 24, 2026 20:08
davidmckayv and others added 9 commits November 24, 2026 12:57
# Conflicts:
#	app/src/components/bot-profile/default-model.tsx
…oviders after a disconnect

- Change and Replace key keep to the connection's own provider: its tile no longer opens the
  other providers, which connected a second AI instead of changing this one. They open on the
  connection's own way in, so a key connection asks for the key rather than a plan sign-in.
- After Disconnect the page goes back to Providers. The list read after the removal no longer
  has the connection, so the page left before the mutation's own callback ran and stayed on
  "isn't connected".
- The radios that choose the next default are drawn in the app's colours, as the Bot's default
  model choice draws them.
- Under a refused turn that already says why, the connection notice adds only Reconnect and
  Choose another model, rather than the same sentence again.
- On OpenBot Cloud the organization's several connections say they are for whoever has none of
  their own: the reader's own Bots may run on their own connections instead.
# Conflicts:
#	app/src/components/channels/chat-transcript.tsx
#	app/src/components/settings/ai-connection.tsx
@davidmckayv
davidmckayv merged commit 44e7b3a into main Nov 25, 2026
33 checks passed
@davidmckayv
davidmckayv deleted the guido/multiple-subs branch November 25, 2026 02:16
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