(entry: DiffEntry)
| 149 | * @param entry Diff entry to index |
| 150 | */ |
| 151 | export async function indexDiffEntry(entry: DiffEntry): Promise<void> { |
| 152 | try { |
| 153 | // If OpenAI client is not available, use mock implementation |
| 154 | if (!openai) { |
| 155 | console.debug("Vector store: Indexing diff entry (mock)", entry.id, entry.file); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | // Ensure vector store is initialized |
| 160 | const storeId = await initializeVectorStore(); |
| 161 | |
| 162 | // Create a text file with the diff entry |
| 163 | const content = `Diff Entry (${entry.id}) |
| 164 | File: ${entry.file} |
| 165 | Diff: |
| 166 | ${entry.diff} |
| 167 | Metadata: ${JSON.stringify(entry.metadata || {}, null, 2)}`; |
| 168 | |
| 169 | const file = new File( |
| 170 | [content], |
| 171 | `diff-${entry.id}.txt`, |
| 172 | { type: "text/plain" }, |
| 173 | ); |
| 174 | |
| 175 | // Upload the file to OpenAI |
| 176 | const uploadedFile = await openai.files.create({ |
| 177 | file, |
| 178 | purpose: "assistants", |
| 179 | }); |
| 180 | |
| 181 | // Add the file to the vector store |
| 182 | await openai.vectorStores.files.create(storeId, { |
| 183 | file_id: uploadedFile.id, |
| 184 | }); |
| 185 | |
| 186 | console.debug("Diff entry indexed in vector database", { |
| 187 | id: entry.id, |
| 188 | file: entry.file, |
| 189 | diffPreview: entry.diff.substring(0, 50) + (entry.diff.length > 50 ? "..." : ""), |
| 190 | }); |
| 191 | } catch (error: unknown) { |
| 192 | console.debug("Failed to index diff entry in vector database, using mock", { |
| 193 | error: String(error), |
| 194 | }); |
| 195 | console.debug("Vector store: Indexing diff entry (mock)", entry.id, entry.file); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Search for diff entries similar to the query |
no test coverage detected