Upgrade to AI sdk with codemod (#1000)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ipcMain } from "electron";
|
||||
import {
|
||||
CoreMessage,
|
||||
ModelMessage,
|
||||
TextPart,
|
||||
ImagePart,
|
||||
streamText,
|
||||
@@ -134,14 +134,14 @@ async function processStreamChunks({
|
||||
chunk = "</think>";
|
||||
inThinkingBlock = false;
|
||||
}
|
||||
chunk += part.textDelta;
|
||||
} else if (part.type === "reasoning") {
|
||||
chunk += part.text;
|
||||
} else if (part.type === "reasoning-delta") {
|
||||
if (!inThinkingBlock) {
|
||||
chunk = "<think>";
|
||||
inThinkingBlock = true;
|
||||
}
|
||||
|
||||
chunk += escapeDyadTags(part.textDelta);
|
||||
chunk += escapeDyadTags(part.text);
|
||||
}
|
||||
|
||||
if (!chunk) {
|
||||
@@ -603,7 +603,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
] as const)
|
||||
: [];
|
||||
|
||||
let chatMessages: CoreMessage[] = [
|
||||
let chatMessages: ModelMessage[] = [
|
||||
...codebasePrefix,
|
||||
...otherCodebasePrefix,
|
||||
...limitedMessageHistory.map((msg) => ({
|
||||
@@ -647,7 +647,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
content:
|
||||
"Summarize the following chat: " +
|
||||
formatMessagesForSummary(previousChat?.messages ?? []),
|
||||
} satisfies CoreMessage,
|
||||
} satisfies ModelMessage,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
chatMessages,
|
||||
modelClient,
|
||||
}: {
|
||||
chatMessages: CoreMessage[];
|
||||
chatMessages: ModelMessage[];
|
||||
modelClient: ModelClient;
|
||||
}) => {
|
||||
const dyadRequestId = uuidv4();
|
||||
@@ -668,7 +668,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
logger.log("sending AI request");
|
||||
}
|
||||
return streamText({
|
||||
maxTokens: await getMaxTokens(settings.selectedModel),
|
||||
maxOutputTokens: await getMaxTokens(settings.selectedModel),
|
||||
temperature: await getTemperature(settings.selectedModel),
|
||||
maxRetries: 2,
|
||||
model: modelClient.model,
|
||||
@@ -798,7 +798,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
break;
|
||||
}
|
||||
if (part.type !== "text-delta") continue; // ignore reasoning for continuation
|
||||
fullResponse += part.textDelta;
|
||||
fullResponse += part.text;
|
||||
fullResponse = cleanFullResponse(fullResponse);
|
||||
fullResponse = await processResponseChunkUpdate({
|
||||
fullResponse,
|
||||
@@ -825,7 +825,7 @@ This conversation includes one or more image attachments. When the user uploads
|
||||
|
||||
let autoFixAttempts = 0;
|
||||
const originalFullResponse = fullResponse;
|
||||
const previousAttempts: CoreMessage[] = [];
|
||||
const previousAttempts: ModelMessage[] = [];
|
||||
while (
|
||||
problemReport.problems.length > 0 &&
|
||||
autoFixAttempts < 2 &&
|
||||
@@ -1161,9 +1161,9 @@ async function replaceTextAttachmentWithContent(
|
||||
|
||||
// Helper function to convert traditional message to one with proper image attachments
|
||||
async function prepareMessageWithAttachments(
|
||||
message: CoreMessage,
|
||||
message: ModelMessage,
|
||||
attachmentPaths: string[],
|
||||
): Promise<CoreMessage> {
|
||||
): Promise<ModelMessage> {
|
||||
let textContent = message.content;
|
||||
// Get the original text content
|
||||
if (typeof textContent !== "string") {
|
||||
|
||||
Reference in New Issue
Block a user