Skip to content

Commit

Permalink
Update mention telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
RXminuS committed Sep 24, 2024
1 parent cdf985b commit b9204ba
Show file tree
Hide file tree
Showing 9 changed files with 1,222 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ describe('useCallMentionMenuData', () => {
mentionMenuData: () => promiseToObservable(dataPromise),
})

const { result } = renderHook(() => useCallMentionMenuData({ query: 'q', parentItem: null }))
const { result } = renderHook(() =>
useCallMentionMenuData({ query: 'q', parentItem: null, interactionID: null })
)

expect(result.current).toEqual<typeof result.current>({
done: false,
Expand Down
15 changes: 12 additions & 3 deletions lib/prompt-editor/src/mentions/mentionMenu/useMentionMenuData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { type UseObservableResult, useObservable } from '../../useObservable'

export interface MentionMenuParams {
query: string | null
interactionID?: number | null | undefined
parentItem: ContextMentionProviderMetadata | null
}

Expand All @@ -30,7 +31,11 @@ export function useMentionMenuParams(): {
updateMentionMenuParams: MentionMenuContextValue['updateMentionMenuParams']
} {
const mentionSettings = useContext(ChatMentionContext)
const [params, setParams] = useState<MentionMenuParams>({ query: null, parentItem: null })
const [params, setParams] = useState<MentionMenuParams>({
query: null,
parentItem: null,
interactionID: null,
})

const isRemoteLikeProviderActive =
mentionSettings.resolutionMode === 'remote' ||
Expand Down Expand Up @@ -74,7 +79,9 @@ export function useMentionMenuParams(): {
}

interface MentionMenuContextValue {
updateMentionMenuParams: (update: Partial<Pick<MentionMenuParams, 'parentItem'>>) => void
updateMentionMenuParams: (
update: Partial<Pick<MentionMenuParams, 'parentItem' | 'interactionID'>>
) => void
setEditorQuery: (query: string) => void
}

Expand Down Expand Up @@ -141,6 +148,7 @@ function prepareUserContextItem(item: ContextItem, remainingTokenBudget: number)
export function useCallMentionMenuData({
query,
parentItem: provider,
interactionID,
}: MentionMenuParams): UseObservableResult<MentionMenuData> {
const mentionSettings = useContext(ChatMentionContext)
const unmemoizedCall = useExtensionAPI().mentionMenuData
Expand All @@ -155,9 +163,10 @@ export function useCallMentionMenuData({
const mentionQuery: MentionQuery = useMemo(
() => ({
...parseMentionQuery(query ?? '', provider),
interactionID: interactionID ?? undefined,
contextRemoteRepositoriesNames: mentionSettings.remoteRepositoriesNames,
}),
[query, provider, mentionSettings]
[query, provider, interactionID, mentionSettings]
)

return useObservable(
Expand Down
11 changes: 9 additions & 2 deletions lib/prompt-editor/src/plugins/atMentions/atMentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,22 @@ export const MentionsPlugin: FunctionComponent<{ contextWindowSizeInTokens?: num
)
}, [editor])

// We use the interaction ID to differentiate between different
// invocations of the mention-menu. That way upstream we don't trigger
// duplicate telemetry events for the same view
const interactionID = useRef(0)
const onClose = useCallback(() => {
updateMentionMenuParams({ parentItem: null })
updateMentionMenuParams({ parentItem: null, interactionID: null })
}, [updateMentionMenuParams])
const onOpen = useCallback(() => {
updateMentionMenuParams({ interactionID: interactionID.current++ })
}, [updateMentionMenuParams])

return (
<LexicalTypeaheadMenuPlugin<MentionMenuOption>
onQueryChange={updateQuery}
onSelectOption={onSelectOption}
onClose={onClose}
onOpen={onOpen}
triggerFn={scanForMentionTriggerInLexicalInput}
options={DUMMY_OPTIONS}
commandPriority={
Expand Down
4 changes: 2 additions & 2 deletions lib/shared/src/configuration/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export type PickResolvedConfiguration<Keys extends KeysSpec> = {
async function resolveConfiguration(input: ConfigurationInput): Promise<ResolvedConfiguration> {
const serverEndpoint =
input.clientConfiguration.overrideServerEndpoint ??
input.clientState.lastUsedEndpoint ??
(input.clientConfiguration.serverEndpoint || DOTCOM_URL.toString())
(input.clientState.lastUsedEndpoint || DOTCOM_URL.toString())

// We must not throw here, because that would result in the `resolvedConfig` observable
// terminating and all callers receiving no further config updates.
Expand All @@ -76,6 +75,7 @@ async function resolveConfiguration(input: ConfigurationInput): Promise<Resolved
return null
})) ??
null

return {
configuration: input.clientConfiguration,
clientState: input.clientState,
Expand Down
8 changes: 8 additions & 0 deletions lib/shared/src/mentions/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import {
* The parsed representation of a user's (partial or complete) input of an @-mention query.
*/
export interface MentionQuery {
/**
* Interaction ID is used to indicate for what view instance this data will
* be used. This is primarily used to record telemetry events. If no
* Interaction ID is specified it is assumed that the data is not shown to
* the user.
*/
interactionID?: string | number | undefined | null

/**
* The type of context item to search for, or null to find suggested items across (possibly) all
* providers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
{
"key": "isPublicRepo",
"value": 1
"value": 0
},
{
"key": "mentions.URIs",
Expand Down Expand Up @@ -172,7 +172,6 @@
],
"privateMetadata": {
"chatModel": "<string>",
"gitMetadata": "<string>",
"promptText": "buzz.ts ",
"requestID": "<string>",
"sessionID": "<string>",
Expand Down Expand Up @@ -289,13 +288,6 @@
}
],
"privateMetadata": {
"gitMetadata": [
{
"isPublic": true,
"remoteID": "UmVwb3NpdG9yeTo2MTMyNTMyOA==",
"repoName": "github.com/sourcegraph/cody"
}
],
"traceId": "<string>"
},
"version": 0
Expand Down Expand Up @@ -343,7 +335,7 @@
],
"privateMetadata": {
"chatModel": "<string>",
"responseText": "Certainly! I'd be happy to discuss the `buzz.ts` file. This file contains a TypeScript implementation of the classic FizzBuzz problem. Here's a breakdown of what the code does:\n\n1. It exports a function called `fizzbuzz()`.\n2. Inside the function, an empty array called `fizzbuzz` is initialized.\n3. The function uses a for loop to iterate from 1 to 100.\n4. For each number, it applies the FizzBuzz rules:\n - If the number is divisible by both 3 and 5 (i.e., divisible by 15), it adds 'FizzBuzz' to the array.\n - If the number is only divisible by 3, it adds 'Fizz' to the array.\n - If the number is only divisible by 5, it adds 'Buzz' to the array.\n - For any other number, it adds the number itself (as a string) to the array.\n5. Finally, the function returns the completed `fizzbuzz` array.\n\nThis implementation is concise and follows the standard FizzBuzz rules. It's a good example of how to solve this common programming challenge in TypeScript. Would you like me to explain any specific part of the code in more detail or suggest any improvements?"
"responseText": "<string>"
},
"version": 2
},
Expand Down
Loading

0 comments on commit b9204ba

Please sign in to comment.