-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathads.ts
More file actions
52 lines (42 loc) · 1.35 KB
/
ads.ts
File metadata and controls
52 lines (42 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useChatStore } from '../state/chat-store'
import { IS_FREEBUFF } from '../utils/constants'
import { logger } from '../utils/logger'
import { getSystemMessage } from '../utils/message-history'
import { saveSettings, loadSettings } from '../utils/settings'
import type { ChatMessage } from '../types/chat'
export const handleAdsEnable = (): {
postUserMessage: (messages: ChatMessage[]) => ChatMessage[]
} => {
logger.info('[gravity] Enabling ads')
saveSettings({ adsEnabled: true })
return {
postUserMessage: (messages) => [
...messages,
getSystemMessage('Ads enabled. You will see contextual ads above the input.'),
],
}
}
export const handleAdsDisable = (): {
postUserMessage: (messages: ChatMessage[]) => ChatMessage[]
} => {
logger.info('[gravity] Disabling ads')
saveSettings({ adsEnabled: false })
return {
postUserMessage: (messages) => [
...messages,
getSystemMessage('Ads disabled.'),
],
}
}
export const getAdsEnabled = (): boolean => {
if (IS_FREEBUFF) return true
// If no mode provided, get it from the store
const mode = useChatStore.getState().agentMode
// In FREE mode, ads are always enabled regardless of saved setting
if (mode === 'FREE') {
return true
}
// Otherwise, use the saved setting
const settings = loadSettings()
return settings.adsEnabled ?? false
}