Open walt93 opened 1 month ago
I had the same issue and was able to solve it by removing cases where null's could be attempted to be stored in the pg database.
I sanitized the null values out of embed_files.ts. Here is the refactored file: `"use server"
import { InsertEmbeddedFile } from "@/db/schema" import { BUILDWARE_EMBEDDING_DIMENSIONS, BUILDWARE_EMBEDDING_MODEL } from "@/lib/constants/buildware-config" import { GitHubFileContent } from "@/types/github" import { encode } from "gpt-tokenizer" import OpenAI from "openai"
const openai = new OpenAI()
function sanitizeContent(content: string): string { return content.replace(/\0/g, ''); // Remove null bytes }
export async function embedFiles(filesContent: GitHubFileContent[]) { let embeddings: number[][] = []
try {
const response = await openai.embeddings.create({
model: BUILDWARE_EMBEDDING_MODEL,
dimensions: BUILDWARE_EMBEDDING_DIMENSIONS,
// embed path + content
input: filesContent.map(file => ${file.path}\n${sanitizeContent(file.content)}
)
})
if (response && response.data) {
embeddings = response.data.map(item => item.embedding)
} else {
console.error("OpenAI API call failed, response is undefined.")
}
} catch (error) { console.error("Error calling OpenAI API:", error) }
const preparedFiles: Omit< InsertEmbeddedFile, "userId" | "projectId" | "embeddedBranchId" | "githubRepoFullName"
[] = filesContent.map((file, index) => ({ path: file.path, content: sanitizeContent(file.content), tokenCount: encode(file.content).length, embedding: embeddings[index] }))
return preparedFiles }`
I also sanitized issue-messages-queries.ts. Here is the refactored file: `"use server"
import { and, desc, eq } from "drizzle-orm" import { revalidatePath } from "next/cache" import { db } from "../db" import { InsertIssueMessage, SelectIssueMessage, issueMessagesTable } from "../schema/issue-messages-schema"
function sanitizeContent(content: string): string { return content.replace(/\0/g, ''); // Remove null bytes }
export async function createIssueMessageRecord(
data: InsertIssueMessage
): Promise
export async function getIssueMessageById(
id: string
): Promise<SelectIssueMessage | undefined> {
try {
return db.query.issueMessages.findFirst({
where: eq(issueMessagesTable.id, id)
})
} catch (error) {
console.error(Error getting issue message by id ${id}:
, error)
throw error
}
}
export async function getIssueMessagesByIssueId(
issueId: string
): Promise<SelectIssueMessage[]> {
try {
return db.query.issueMessages.findMany({
where: eq(issueMessagesTable.issueId, issueId),
orderBy: desc(issueMessagesTable.createdAt)
})
} catch (error) {
console.error(Error getting issue messages for issue ${issueId}:
, error)
throw error
}
}
export async function updateIssueMessage(
id: string,
data: PartialError updating issue message ${id}:
, error)
throw error
}
}
export async function deleteIssueMessage(id: string): PromiseError deleting issue message ${id}:
, error)
throw error
}
}
export async function deleteIssueMessagesByIssueId(
issueId: string
): PromiseError deleting issue messages for issue ${issueId}:
, error)
throw error
}
}`
On a similar note, I also sanitized the generate-prs.ts script, since there are conventions for naming branches, and your issue names could violate them.:
const sanitizeBranchName = (name: string) => { return name .toLowerCase() .replace(/[^a-z0-9-]/g, '-') // Replace any non-alphanumeric characters with hyphens .replace(/-+/g, '-') // Replace multiple consecutive hyphens with a single hyphen .replace(/^-|-$/g, '') // Remove leading and trailing hyphens .slice(0, 50); // Limit the length to 50 characters };
After making these changes, the project worked for me. Good luck!
Installed, configured Postgres and keys and PAT, wrote my first issue for the AI to handle, and it failed with an exception. In the UI we see:
"Error: Failed to run issue: Error: invalid byte sequence for encoding "UTF8": 0x00"
Note: did absolute minimum configuration on Supabase & took defaults for everything except password, so probably, user error
There seem to be rather a lot of Postgress issues leading up to the failure, attaching all in case it is helpful.