This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
breakpilot-pwa/breakpilot-compliance-sdk/packages/vue/src/composables/useRAG.ts
Benjamin Admin bfdaf63ba9 fix: Restore all files lost during destructive rebase
A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.

This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).

Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 09:51:32 +01:00

137 lines
3.3 KiB
TypeScript

/**
* RAG (Retrieval-Augmented Generation) composable
*/
import { computed, type ComputedRef, type Ref, ref, reactive } from 'vue'
import { useComplianceStore } from '../plugin'
import type {
SearchResponse,
AssistantResponse,
ChatMessage,
LegalDocument,
} from '@breakpilot/compliance-sdk-types'
export interface UseRAGReturn {
// Search
search: (query: string, regulationCodes?: string[]) => Promise<SearchResponse>
searchResults: Ref<SearchResponse | null>
// Chat
ask: (question: string, context?: string) => Promise<AssistantResponse>
chatHistory: Ref<ChatMessage[]>
clearChat: () => void
isTyping: Ref<boolean>
// Documents
documents: ComputedRef<LegalDocument[]>
availableRegulations: ComputedRef<string[]>
// Loading state
isLoading: Ref<boolean>
error: Ref<Error | null>
}
export function useRAG(): UseRAGReturn {
const store = useComplianceStore()
const { state, rag } = store
const isLoading = ref(false)
const isTyping = ref(false)
const error = ref<Error | null>(null)
const searchResults = ref<SearchResponse | null>(null)
const chatHistory = ref<ChatMessage[]>([])
// Search
const search = async (query: string, regulationCodes?: string[]): Promise<SearchResponse> => {
isLoading.value = true
error.value = null
try {
const results = await rag.search(query, regulationCodes)
searchResults.value = results
return results
} catch (err) {
error.value = err instanceof Error ? err : new Error(String(err))
throw err
} finally {
isLoading.value = false
}
}
// Chat
const ask = async (question: string, context?: string): Promise<AssistantResponse> => {
isLoading.value = true
isTyping.value = true
error.value = null
// Add user message to history
chatHistory.value.push({
id: `msg_${Date.now()}`,
role: 'user',
content: question,
timestamp: new Date().toISOString(),
})
try {
const response = await rag.ask(question, context)
// Add assistant response to history
chatHistory.value.push({
id: `msg_${Date.now()}`,
role: 'assistant',
content: response.answer,
timestamp: new Date().toISOString(),
citations: response.citations,
})
return response
} catch (err) {
error.value = err instanceof Error ? err : new Error(String(err))
// Add error message to history
chatHistory.value.push({
id: `msg_${Date.now()}`,
role: 'assistant',
content: 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut.',
timestamp: new Date().toISOString(),
})
throw err
} finally {
isLoading.value = false
isTyping.value = false
}
}
const clearChat = (): void => {
chatHistory.value = []
rag.clearHistory()
}
// Documents
const documents = computed(() => state.legalDocuments)
const availableRegulations = computed(() => {
const codes = new Set<string>()
state.legalDocuments.forEach(doc => {
if (doc.regulationCode) {
codes.add(doc.regulationCode)
}
})
return Array.from(codes).sort()
})
return {
search,
searchResults,
ask,
chatHistory,
clearChat,
isTyping,
documents,
availableRegulations,
isLoading,
error,
}
}