-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add gen ai org and project settings to Compass for CompassWeb u…
…sage COMPASS-8377 (#6434) * limit increased and message improved for PROMPT_TOO_LONG * updating prompt_too_long error msg * updating test * initial ticket changes * entrypoint changed * prefProps for atlas org and atlas proj prefs * function name change * fixing base values * changing ui default back * comment nit * moving prop defs so defaults get set as part of userpreferences * updating tests * updating tests
- Loading branch information
1 parent
d3ae895
commit 5bc3fe9
Showing
5 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/compass-preferences-model/src/compass-web-preferences-access.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { createNoopLogger } from '@mongodb-js/compass-logging/provider'; | ||
import { Preferences, type PreferencesAccess } from './preferences'; | ||
import type { UserPreferences } from './preferences-schema'; | ||
import { type AllPreferences } from './preferences-schema'; | ||
import { InMemoryStorage } from './preferences-in-memory-storage'; | ||
import { getActiveUser } from './utils'; | ||
|
||
export class CompassWebPreferencesAccess implements PreferencesAccess { | ||
private _preferences: Preferences; | ||
constructor(preferencesOverrides?: Partial<AllPreferences>) { | ||
this._preferences = new Preferences({ | ||
logger: createNoopLogger(), | ||
preferencesStorage: new InMemoryStorage(preferencesOverrides), | ||
}); | ||
} | ||
|
||
savePreferences(_attributes: Partial<UserPreferences>) { | ||
// Only allow saving the optInDataExplorerGenAIFeatures preference. | ||
if ( | ||
Object.keys(_attributes).length === 1 && | ||
'optInDataExplorerGenAIFeatures' in _attributes | ||
) { | ||
return Promise.resolve(this._preferences.savePreferences(_attributes)); | ||
} | ||
return Promise.resolve(this._preferences.getPreferences()); | ||
} | ||
|
||
refreshPreferences() { | ||
return Promise.resolve(this._preferences.getPreferences()); | ||
} | ||
|
||
getPreferences() { | ||
return this._preferences.getPreferences(); | ||
} | ||
|
||
ensureDefaultConfigurableUserPreferences() { | ||
return this._preferences.ensureDefaultConfigurableUserPreferences(); | ||
} | ||
|
||
getConfigurableUserPreferences() { | ||
return Promise.resolve(this._preferences.getConfigurableUserPreferences()); | ||
} | ||
|
||
getPreferenceStates() { | ||
return Promise.resolve(this._preferences.getPreferenceStates()); | ||
} | ||
|
||
onPreferenceValueChanged<K extends keyof AllPreferences>( | ||
preferenceName: K, | ||
callback: (value: AllPreferences[K]) => void | ||
) { | ||
return ( | ||
this._preferences?.onPreferencesChanged?.( | ||
(preferences: Partial<AllPreferences>) => { | ||
if (Object.keys(preferences).includes(preferenceName)) { | ||
return callback((preferences as AllPreferences)[preferenceName]); | ||
} | ||
} | ||
) ?? | ||
(() => { | ||
/* no fallback */ | ||
}) | ||
); | ||
} | ||
|
||
createSandbox() { | ||
return Promise.resolve( | ||
new CompassWebPreferencesAccess(this.getPreferences()) | ||
); | ||
} | ||
|
||
getPreferencesUser() { | ||
return getActiveUser(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters