Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,17 @@ describe('RelayConnection', () => {
conn.close();
});

test('updates the mode getter', () => {
test('updates the mode accessor', () => {
const cbs = makeCallbacks();
const conn = makeConn(
{ kind: 'self-hosted', baseUrl: 'http://127.0.0.1:7830', token: 't' },
cbs,
);
conn.start();
expect(conn.mode.kind).toBe('self-hosted');
expect(conn.getCurrentMode().kind).toBe('self-hosted');

conn.setMode({ kind: 'cloud', baseUrl: 'https://api.vellum.ai', token: 'c' });
expect(conn.mode.kind).toBe('cloud');
expect(conn.getCurrentMode().kind).toBe('cloud');

conn.close();
});
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('RelayConnection', () => {
expect(newSocket.url).toBe(
'wss://api.vellum.ai/v1/browser-relay?token=cloud-jwt',
);
expect(conn.mode.kind).toBe('cloud');
expect(conn.getCurrentMode().kind).toBe('cloud');

// Now simulate the asynchronous close event that socket A fires
// after setMode already re-pointed this.ws at socket B. The
Expand Down
9 changes: 4 additions & 5 deletions clients/chrome-extension/background/relay-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ export class RelayConnection {
this.deps = deps;
}

/** Current connection mode (read-only; use `setMode` to switch). */
get mode(): RelayMode {
return this.deps.mode;
}

/**
* Return the live connection mode. Callers must invoke this right
* before each use — after a reconnect-with-refresh cycle the
Expand All @@ -96,6 +91,10 @@ export class RelayConnection {
* mode through this accessor per-POST so that result envelopes sent
* after a WebSocket drop authenticate with the new bearer token
* instead of silently 401/403ing.
*
* This is the ONLY public accessor for the mode — there is
* deliberately no `get mode()` getter, because a property-style
* access reads as a static field and invites callers to cache it.
*/
getCurrentMode(): RelayMode {
return this.deps.mode;
Expand Down