diff --git a/.codegraph/.gitignore b/.codegraph/.gitignore new file mode 100644 index 0000000..9de0f16 --- /dev/null +++ b/.codegraph/.gitignore @@ -0,0 +1,16 @@ +# CodeGraph data files +# These are local to each machine and should not be committed + +# Database +*.db +*.db-wal +*.db-shm + +# Cache +cache/ + +# Logs +*.log + +# Hook markers +.dirty diff --git a/.codegraph/daemon.pid b/.codegraph/daemon.pid new file mode 100644 index 0000000..f5b924b --- /dev/null +++ b/.codegraph/daemon.pid @@ -0,0 +1,6 @@ +{ + "pid": 385650, + "version": "0.9.7", + "socketPath": "/home/dash/code/nuxt-app/.codegraph/daemon.sock", + "startedAt": 1786124270447 +} diff --git a/app/composables/useAgentChat.ts b/app/composables/useAgentChat.ts index 8165edd..c099d09 100644 --- a/app/composables/useAgentChat.ts +++ b/app/composables/useAgentChat.ts @@ -90,7 +90,6 @@ export function useAgentChat(options: UseAgentChatOptions) { ...m, parts: m.parts ? (typeof m.parts === "string" ? JSON.parse(m.parts) : m.parts) : undefined, })); - await cleanupStaleApprovals(); } catch { messages.value = []; } @@ -322,6 +321,8 @@ export function useAgentChat(options: UseAgentChatOptions) { isStopped.value = false; staleApprovalToolCallIds = new Set(); + await cleanupStaleApprovals(); + let userMsgIdx = -1; if (opts?.editMessageId) { diff --git a/packages/drizzle-pkg/db.sqlite b/packages/drizzle-pkg/db.sqlite index db1f11b..e0f01ed 100644 Binary files a/packages/drizzle-pkg/db.sqlite and b/packages/drizzle-pkg/db.sqlite differ diff --git a/server/api/agent/chat/index.post.ts b/server/api/agent/chat/index.post.ts index 97427e9..ba5bd8c 100644 --- a/server/api/agent/chat/index.post.ts +++ b/server/api/agent/chat/index.post.ts @@ -441,48 +441,59 @@ export default defineEventHandler(async (event) => { const parts: Array> = []; for (const step of steps) { - for (const r of step.reasoning) { - if (r.type === "reasoning" && r.text) { - parts.push({ id: `p_${parts.length}`, type: "reasoning", text: r.text }); - } - } const toolResultMap = new Map(step.toolResults.map((tr) => [tr.toolCallId, tr.output])); - const approvalRequestMap = new Map(); - for (const cp of step.content as Array>) { - if (cp.type === "tool-approval-request" && cp.approvalId && cp.toolCall) { - const tc = cp.toolCall as Record; - if (tc.toolCallId) { - approvalRequestMap.set(tc.toolCallId as string, cp.approvalId as string); - } + const contentArr = step.content as Array>; + const approvalToolCallIds = new Set(); + for (const cp of contentArr) { + if (cp.type === "tool-approval-request" && (cp as any).approvalId && (cp as any).toolCall) { + approvalToolCallIds.add((cp as any).toolCall.toolCallId); } } - for (const tc of step.toolCalls) { - const approvalId = approvalRequestMap.get(tc.toolCallId); - if (approvalId) { - parts.push({ - id: `p_${parts.length}`, - type: "tool-call", - toolCallId: tc.toolCallId, - toolName: tc.toolName, - args: tc.input, - state: "approval-requested", - approvalId, - }); - } else { + for (const cp of contentArr) { + if (cp.type === "reasoning" && (cp as any).text) { + parts.push({ id: `p_${parts.length}`, type: "reasoning", text: (cp as any).text }); + } else if (cp.type === "text" && (cp as any).text) { + parts.push({ id: `p_${parts.length}`, type: "text", text: (cp as any).text }); + } else if (cp.type === "tool-approval-request" && (cp as any).approvalId && (cp as any).toolCall) { + const tc = (cp as any).toolCall; + const toolResult = toolResultMap.get(tc.toolCallId); + if (toolResult === undefined) { + parts.push({ + id: `p_${parts.length}`, + type: "tool-call", + toolCallId: tc.toolCallId, + toolName: tc.toolName, + args: tc.input, + state: "approval-requested", + approvalId: (cp as any).approvalId, + }); + } else { + parts.push({ + id: `p_${parts.length}`, + type: "tool-call", + toolCallId: tc.toolCallId, + toolName: tc.toolName, + args: tc.input, + result: toolResult, + state: "result", + approvalId: (cp as any).approvalId, + }); + } + } else if (cp.type === "tool-call") { + const tc = cp as any; + if (approvalToolCallIds.has(tc.toolCallId)) continue; + const toolResult = toolResultMap.get(tc.toolCallId); parts.push({ id: `p_${parts.length}`, type: "tool-call", toolCallId: tc.toolCallId, toolName: tc.toolName, args: tc.input, - result: toolResultMap.get(tc.toolCallId), + result: toolResult, state: "result", }); } } - if (step.text) { - parts.push({ id: `p_${parts.length}`, type: "text", text: step.text }); - } } if (isApprovalContinue) {