Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions electron/pinecone-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PineconeService {
*/
async connect(profile: ConnectionProfile): Promise<void> {
try {
this.assistantService = null
this.client = new Pinecone({
apiKey: profile.apiKey,
})
Expand All @@ -81,6 +82,7 @@ class PineconeService {
} catch (error) {
this.client = null
this.embeddingService = null
this.assistantService = null
this.profile = null
throw error
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ function renderContentWithCitations(content: string, citations?: Citation[]) {
return content
}

// Sort citations by position (descending) to insert from end to avoid offset issues
const sortedCitations = [...citations].sort((a, b) => b.position - a.position)
// Sort citations by position (descending) with original indices preserved
const sortedCitations = citations
.map((c, i) => ({ citation: c, originalIndex: i }))
.sort((a, b) => b.citation.position - a.citation.position)

// Create segments with citation markers
const segments: Array<{ text: string; citationIndex?: number }> = []
let remainingContent = content
let currentOffset = content.length

for (const citation of sortedCitations) {
for (const { citation, originalIndex } of sortedCitations) {
const pos = citation.position
if (pos >= 0 && pos <= currentOffset) {
// Text after this citation position
Expand All @@ -90,7 +92,7 @@ function renderContentWithCitations(content: string, citations?: Citation[]) {
// Add citation marker
segments.unshift({
text: '',
citationIndex: citations.indexOf(citation)
citationIndex: originalIndex
})
currentOffset = pos
remainingContent = remainingContent.slice(0, pos)
Expand Down
2 changes: 2 additions & 0 deletions src/components/chat/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export function ChatView({ assistantName }: ChatViewProps) {

const handleKeyDown = useCallback(
(e: KeyboardEvent<HTMLTextAreaElement>) => {
// Don't submit during IME composition (CJK input)
if (e.nativeEvent.isComposing) return
// Submit on Enter (without Shift) or Cmd/Ctrl+Enter
if (e.key === 'Enter' && (!e.shiftKey || e.metaKey || e.ctrlKey)) {
e.preventDefault()
Expand Down
11 changes: 1 addition & 10 deletions src/components/chat/CitationPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import {
PopoverTrigger,
} from '@/components/ui/popover'
import { Button } from '@/components/ui/button'

interface CitationReference {
file: { name: string; id: string }
pages?: number[]
}

interface Citation {
position: number
references: CitationReference[]
}
import type { Citation, CitationReference } from '../../../electron/types'

interface CitationPopoverProps {
citation: Citation
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useChatStream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useCallback, useRef, useEffect } from 'react'
import { usePinecone } from '../providers/PineconeProvider'
import type { ChatMessage, Citation, ChatUsage, ChatStreamChunk } from '../../electron/types'

export interface ChatMessageWithMeta extends ChatMessage {
id?: string
Expand Down