Browse Source

feat: add .gitignore for CodeGraph files and update useAgentChat to handle stale approvals

feat/ai-sdk-v6-upgrade
npmrun 4 hours ago
parent
commit
6f47ac5179
  1. 16
      .codegraph/.gitignore
  2. 6
      .codegraph/daemon.pid
  3. 3
      app/composables/useAgentChat.ts
  4. BIN
      packages/drizzle-pkg/db.sqlite
  5. 69
      server/api/agent/chat/index.post.ts

16
.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

6
.codegraph/daemon.pid

@ -0,0 +1,6 @@
{
"pid": 385650,
"version": "0.9.7",
"socketPath": "/home/dash/code/nuxt-app/.codegraph/daemon.sock",
"startedAt": 1786124270447
}

3
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) {

BIN
packages/drizzle-pkg/db.sqlite

Binary file not shown.

69
server/api/agent/chat/index.post.ts

@ -441,48 +441,59 @@ export default defineEventHandler(async (event) => {
const parts: Array<Record<string, unknown>> = [];
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<string, string>();
for (const cp of step.content as Array<Record<string, unknown>>) {
if (cp.type === "tool-approval-request" && cp.approvalId && cp.toolCall) {
const tc = cp.toolCall as Record<string, unknown>;
if (tc.toolCallId) {
approvalRequestMap.set(tc.toolCallId as string, cp.approvalId as string);
}
const contentArr = step.content as Array<Record<string, unknown>>;
const approvalToolCallIds = new Set<string>();
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) {

Loading…
Cancel
Save