Skip to content

Commit

Permalink
addin editor serialization in the span too
Browse files Browse the repository at this point in the history
  • Loading branch information
arafatkatze committed Nov 21, 2024
1 parent 826c229 commit e2505cb
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,9 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
const humanEditorRef = useRef<PromptEditorRefAPI | null>(null)
useImperativeHandle(parentEditorRef, () => humanEditorRef.current)

const startSpanAndSubmit = (
action: 'edit' | 'submit',
editorValue: SerializedPromptEditorValue,
intentFromSubmit?: ChatMessage['intent']
) => {
const onUserAction = (action: 'edit' | 'submit', intentFromSubmit?: ChatMessage['intent']) => {
// Start the span as soon as the user initiates the action
const startMark = performance.mark('startSubmit')

// Start the span as soon as the user clicks the submit button
const spanManager = new SpanManager('cody-webview')
const span = spanManager.startSpan('chat-interaction', {
attributes: {
Expand All @@ -295,6 +290,13 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
const spanContext = trace.setSpan(context.active(), span)
setActiveChatContext(spanContext)

// Serialize the editor value after starting the span
const editorValue = humanEditorRef.current?.getSerializedValue()
if (!editorValue) {
console.error('Failed to serialize editor value')
return
}

const commonProps = {
editorValue,
intent: intentFromSubmit || intentResults.current?.intent,
Expand All @@ -315,17 +317,17 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
}

const onEditSubmit = useCallback(
(editorValue: SerializedPromptEditorValue, intentFromSubmit?: ChatMessage['intent']): void => {
startSpanAndSubmit('edit', editorValue, intentFromSubmit)
(intentFromSubmit?: ChatMessage['intent']): void => {
onUserAction('edit', intentFromSubmit)
},
[startSpanAndSubmit]
[onUserAction]
)

const onFollowupSubmit = useCallback(
(editorValue: SerializedPromptEditorValue, intentFromSubmit?: ChatMessage['intent']): void => {
startSpanAndSubmit('submit', editorValue, intentFromSubmit)
(intentFromSubmit?: ChatMessage['intent']): void => {
onUserAction('submit', intentFromSubmit)
},
[startSpanAndSubmit]
[onUserAction]
)

const extensionAPI = useExtensionAPI()
Expand Down Expand Up @@ -494,7 +496,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
(intent: ChatMessage['intent']) => {
const editorState = humanEditorRef.current?.getSerializedValue()
if (editorState) {
onEditSubmit(editorState, intent)
onEditSubmit(intent)
telemetryRecorder.recordEvent('onebox.intentCorrection', 'clicked', {
metadata: {
recordsPrivateMetadataTranscript: 1,
Expand All @@ -519,10 +521,7 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
return
}
await editor.addMentions(corpusContextItems, 'before', ' ')
const newEditorState = humanEditorRef.current?.getSerializedValue()
if (newEditorState) {
onEditSubmit(newEditorState, 'chat')
}
onEditSubmit('chat')
}
}, [corpusContextItems, onEditSubmit])

Expand Down Expand Up @@ -560,7 +559,9 @@ const TranscriptInteraction: FC<TranscriptInteractionProps> = memo(props => {
isSent={!humanMessage.isUnsentFollowup}
isPendingPriorResponse={priorAssistantMessageIsLoading}
onChange={onChange}
onSubmit={humanMessage.isUnsentFollowup ? onFollowupSubmit : onEditSubmit}
onSubmit={
humanMessage.isUnsentFollowup ? () => onFollowupSubmit() : () => onEditSubmit()
}
onStop={onStop}
isFirstInteraction={isFirstInteraction}
isLastInteraction={isLastInteraction}
Expand Down

0 comments on commit e2505cb

Please sign in to comment.