From 65d5bf9c28b009c00167fbfd3204133bb2da166c Mon Sep 17 00:00:00 2001 From: Ariel Weinberger Date: Thu, 17 Jul 2025 00:13:48 -0500 Subject: [PATCH] progress --- ai-service/Dockerfile | 1 - ai-service/src/handlers/chat/route.ts | 5 +- .../lib/ai/mastra/workflows/code-workflow.ts | 68 +++++++------------ 3 files changed, 27 insertions(+), 47 deletions(-) diff --git a/ai-service/Dockerfile b/ai-service/Dockerfile index d38448449..735c18000 100644 --- a/ai-service/Dockerfile +++ b/ai-service/Dockerfile @@ -10,7 +10,6 @@ ENV PATH="$PNPM_HOME:$PATH" RUN npm i -g corepack@latest RUN corepack enable RUN corepack prepare pnpm@10.0.0 --activate -RUN pnpm install -g bun ADD ./package.json /app/package.json ADD ./pnpm-lock.yaml /app/pnpm-lock.yaml diff --git a/ai-service/src/handlers/chat/route.ts b/ai-service/src/handlers/chat/route.ts index 96813d941..979532c36 100644 --- a/ai-service/src/handlers/chat/route.ts +++ b/ai-service/src/handlers/chat/route.ts @@ -50,8 +50,7 @@ export const handleChatRequest = async (c: Context) => { projectId, token // TODO: use the token from the request }); - const convos = await imagineClient.listConversations(artifactId); - const imagineConvo = convos.conversations[0]; + const imagineConvo = await imagineClient.getConversation(artifactId, conversationId); const convertedMessages = convertToModelMessages(messages); const latestMessage = convertedMessages[convertedMessages.length - 1]; @@ -75,8 +74,6 @@ export const handleChatRequest = async (c: Context) => { await exec(`pnpx degit appwrite/templates-for-frameworks/base-vite-template .`, { cwd: workspaceDir }); - console.log('Installing dependencies...'); - await exec(`bun install`, { cwd: workspaceDir }); } } else { console.log('Not a new conversation, skipping workspace clone'); diff --git a/ai-service/src/lib/ai/mastra/workflows/code-workflow.ts b/ai-service/src/lib/ai/mastra/workflows/code-workflow.ts index 92f4e38ac..ab7746dc0 100644 --- a/ai-service/src/lib/ai/mastra/workflows/code-workflow.ts +++ b/ai-service/src/lib/ai/mastra/workflows/code-workflow.ts @@ -80,11 +80,6 @@ const planStep = createStep({ const id = createIdGenerator({ size: 10 })(); - // writer.write({ - // type: "reasoning-start", - // id, - // }); - const thinkingId = createIdGenerator({ size: 10 })(); writer.write({ @@ -99,11 +94,10 @@ const planStep = createStep({ const startTime = Date.now(); - const stream = await architectAgent.stream( - [ - cacheSystemMessage({ - role: "system", - content: ` + const messages = [ + cacheSystemMessage({ + role: "system", + content: ` Here is the current file layout and dependencies in the project: ${currentCodeContext.content} @@ -133,26 +127,30 @@ Examples of when a UI developer IS NOT needed: - Adding an endpoint - Pure logic changes - Moving files around, renaming files, etc. - `, - }), - ...restMessages.map((m: any) => ({ - role: m.role, - content: m.content, - })), - { - role: "user", - content: ` + `, + }), + ...restMessages.map((m: any) => ({ + role: m.role, + content: m.content, + })), + { + role: "user", + content: ` Here is the product manager's request: ${userPrompt} - `, - }, - ], + `, + }, + ]; + + console.log("messages", messages); + + const stream = await architectAgent.stream( + messages, { runtimeContext, - maxSteps: 20, maxOutputTokens: 1000, experimental_output: outputSchema, toolChoice: "none", @@ -172,12 +170,6 @@ ${userPrompt} const delta = partialObject.plan.slice(previousPlan.length); previousPlan = partialObject.plan; - // writer.write({ - // type: "reasoning-delta", - // id, - // delta, - // }); - writer.write({ type: "data-thinking", id: thinkingId, @@ -189,6 +181,8 @@ ${userPrompt} }); } + console.log("resp", await stream.response) + console.log("[planStep] postStream", latestPartialObject); if (!latestPartialObject) { @@ -207,16 +201,6 @@ ${userPrompt} } }); - // writer.write({ - // type: "reasoning-end", - // id, - // providerMetadata: { - // imagine: { - // durationInMs: timeTaken, - // } - // } as any, - // }); - const { plan, shouldInvolveUIDeveloper } = latestPartialObject; return { plan, @@ -334,8 +318,8 @@ const implementStep = createStep({ console.log(`Generating commit message`); const { object } = await generateObject({ - model: openai("gpt-4.1-mini"), - // model: anthropic("claude-3-7-sonnet-20250219"), + // model: openai("gpt-4.1-mini"), + model: anthropic("claude-3-7-sonnet-20250219"), schema: z.object({ commitMessage: z.string(), }), @@ -472,7 +456,7 @@ Example of invalid requests: writer.write({ type: "text-end", id, - }); + }); const toolsUsed = await stream.toolCalls; const hasUsedProceedTool = toolsUsed.some(