Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat: default Agent Share to Gateway WS v2 (#19752)

YuTengjing793b31df11ea
diff --git a/src/store/chat/slices/agentRun/actions/__tests__/gateway.mux.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/gateway.mux.test.ts
index 6c8421c350d..b183f7a77a6 100644
--- a/src/store/chat/slices/agentRun/actions/__tests__/gateway.mux.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/gateway.mux.test.ts
@@ -240,6 +240,33 @@ describe('GatewayActionImpl (enableGatewayMux lab)', () => {
expect(state.gatewayConnections['op-1'].client).toBe(v1Client);
});
+ it('uses the share-scoped mux by default when the lab flag is off', () => {
+ mockLab.enableGatewayMux = false;
+ const { action, mux, muxClient, state, v1Client } = createTestAction();
+
+ action.connectToGateway({
+ agentShareId: 'share-1',
+ executor: true,
+ gatewayUrl: GATEWAY_URL,
+ operationId: 'op-1',
+ token: 'unused-in-mux',
+ topicId: 'topic-1',
+ });
+
+ expect(action.resolveGatewayMux).toHaveBeenCalledWith({
+ agentShareId: 'share-1',
+ gatewayUrl: GATEWAY_URL,
+ });
+ expect(action.createMuxClient).toHaveBeenCalledWith(mux, 'op-1', {
+ executor: true,
+ resumeOnConnect: undefined,
+ });
+ expect(action.createClient).not.toHaveBeenCalled();
+ expect(muxClient.connect).toHaveBeenCalled();
+ expect(v1Client.connect).not.toHaveBeenCalled();
+ expect(state.gatewayConnections['op-1']).toEqual({ client: muxClient, status: 'connecting' });
+ });
+
it('resolves the page-wide registry mux by default', () => {
const { action } = createTestAction();
action.resolveGatewayMux = getGatewayMux;
diff --git a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
index 82cab2e0b17..927fc29bf49 100644
--- a/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
+++ b/src/store/chat/slices/agentRun/actions/transports/gateway/gateway.ts
@@ -359,11 +359,14 @@ export class GatewayActionImpl {
// Disconnect existing connection for this operation if any
this.disconnectFromGateway(operationId);
- // Read the lab flag once per connect (non-reactive, like the other prefs
- // `isGatewayModeEnabled` consults): a connection keeps the transport it
- // was opened with even if the toggle flips mid-run.
+ // Share visitors default to protocol v2 because the public surface does
+ // not inherit the creator's Labs preference. Owner runs keep the existing
+ // opt-in rollout: a connection keeps the transport it was opened with
+ // even if the toggle flips mid-run.
+ const useGatewayMux =
+ Boolean(agentShareId) || labPreferSelectors.enableGatewayMux(useUserStore.getState());
let muxClient: OperationClient | undefined;
- if (labPreferSelectors.enableGatewayMux(useUserStore.getState())) {
+ if (useGatewayMux) {
const mux = this.resolveGatewayMux({ agentShareId, gatewayUrl });
this.#attachGatewayFeed(mux);
// The mux mints its own token via `getToken` on every dial, so `token`