Skip to content

Commit a77cb68

Browse files
committed
ads: include session id
1 parent 0402d42 commit a77cb68

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

cli/src/hooks/use-gravity-ad.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getAdsEnabled } from '../commands/ads'
55
import { useChatStore } from '../state/chat-store'
66
import { subscribeToActivity } from '../utils/activity-tracker'
77
import { getAuthToken } from '../utils/auth'
8-
import { logger, loggerContext } from '../utils/logger'
8+
import { logger } from '../utils/logger'
99

1010
const AD_ROTATION_INTERVAL_MS = 60 * 1000 // 60 seconds per ad
1111
const MAX_ADS_AFTER_ACTIVITY = 3 // Show up to 3 ads after last activity, then stop
@@ -155,7 +155,7 @@ export const useGravityAd = (): GravityAdState => {
155155
},
156156
body: JSON.stringify({
157157
messages: adMessages,
158-
sessionId: loggerContext.clientSessionId,
158+
sessionId: useChatStore.getState().chatSessionId,
159159
device: getDeviceInfo(),
160160
}),
161161
})

cli/src/state/chat-store.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export type SuggestedFollowupsState = {
9595
export type ClickedFollowupsMap = Map<string, Set<number>>
9696

9797
export type ChatStoreState = {
98+
/** Unique ID for this chat session, regenerated on /new */
99+
chatSessionId: string
98100
messages: ChatMessage[]
99101
streamingAgents: Set<string>
100102
focusedAgentId: string | null
@@ -204,7 +206,10 @@ type ChatStoreActions = {
204206

205207
type ChatStore = ChatStoreState & ChatStoreActions
206208

209+
const generateSessionId = () => crypto.randomUUID()
210+
207211
const initialState: ChatStoreState = {
212+
chatSessionId: generateSessionId(),
208213
messages: [],
209214
streamingAgents: new Set<string>(),
210215
focusedAgentId: null,
@@ -466,6 +471,7 @@ export const useChatStore = create<ChatStore>()(
466471

467472
reset: () =>
468473
set((state) => {
474+
state.chatSessionId = generateSessionId()
469475
state.messages = initialState.messages.slice()
470476
state.streamingAgents = new Set(initialState.streamingAgents)
471477
state.focusedAgentId = initialState.focusedAgentId

web/src/app/api/v1/ads/_post.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ export async function postAds(params: {
152152
renderContext: {
153153
placements: [{ placement: 'below_response' }],
154154
max_ad_length: 200,
155+
supports_links: true,
156+
supports_markdown: false,
155157
},
156158
...(device ? { device } : {}),
157159
testAd: serverEnv.CB_ENVIRONMENT !== 'prod',
160+
numAds: 1,
158161
}
159162
// Call Gravity API
160163
const response = await fetch('https://server.trygravity.ai/ad', {

0 commit comments

Comments
 (0)