fix: Aktivitäts-Liste — grüner Puls-Punkt bleibt nicht mehr hängen
Tool-Start und Tool-End hatten unterschiedliche IDs: tool-start generierte eine zufällige UUID, tool-end suchte nach der Backend-ID → kein Match → alle Tool-Calls blieben ewig auf "running" mit pulsierendem grünen Punkt. Fix: Backend-ID wird jetzt bei tool-start durchgereicht + Fallback auf letzten laufenden Tool-Call wenn ID nicht matcht. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
50c92072f5
commit
94c7b9358d
2 changed files with 30 additions and 17 deletions
|
|
@ -246,8 +246,8 @@ export function updateAgentStatus(id: string, status: Agent['status']) {
|
|||
);
|
||||
}
|
||||
|
||||
export function addToolCall(agentId: string, tool: string, args: Record<string, unknown>): string {
|
||||
const id = crypto.randomUUID();
|
||||
export function addToolCall(agentId: string, tool: string, args: Record<string, unknown>, fixedId?: string): string {
|
||||
const id = fixedId || crypto.randomUUID();
|
||||
const call: ToolCall = {
|
||||
id,
|
||||
agentId,
|
||||
|
|
@ -270,18 +270,30 @@ export function addToolCall(agentId: string, tool: string, args: Record<string,
|
|||
}
|
||||
|
||||
export function completeToolCall(id: string, result: unknown, failed = false) {
|
||||
toolCalls.update((calls) =>
|
||||
calls.map((c) =>
|
||||
c.id === id
|
||||
? {
|
||||
...c,
|
||||
status: failed ? 'failed' : 'completed',
|
||||
completedAt: new Date(),
|
||||
result
|
||||
}
|
||||
: c
|
||||
)
|
||||
);
|
||||
toolCalls.update((calls) => {
|
||||
// Exakte ID-Suche
|
||||
let found = calls.some((c) => c.id === id);
|
||||
|
||||
if (found) {
|
||||
return calls.map((c) =>
|
||||
c.id === id
|
||||
? { ...c, status: (failed ? 'failed' : 'completed') as ToolCall['status'], completedAt: new Date(), result }
|
||||
: c
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback: Letzten laufenden Tool-Call abschließen (für Events ohne passende ID)
|
||||
const lastRunning = [...calls].reverse().find((c) => c.status === 'running');
|
||||
if (lastRunning) {
|
||||
return calls.map((c) =>
|
||||
c.id === lastRunning.id
|
||||
? { ...c, status: (failed ? 'failed' : 'completed') as ToolCall['status'], completedAt: new Date(), result }
|
||||
: c
|
||||
);
|
||||
}
|
||||
|
||||
return calls;
|
||||
});
|
||||
}
|
||||
|
||||
export function clearAll() {
|
||||
|
|
|
|||
|
|
@ -226,8 +226,8 @@ export async function initEventListeners(): Promise<void> {
|
|||
// Tool Start
|
||||
listeners.push(
|
||||
await listen<ToolEvent>('tool-start', async (event) => {
|
||||
const { tool, input } = event.payload;
|
||||
console.log('🔧 Tool Start:', tool);
|
||||
const { id, tool, input } = event.payload;
|
||||
console.log('🔧 Tool Start:', tool, id);
|
||||
|
||||
// Inline-Aktivitätsanzeige aktualisieren
|
||||
currentTool.set({ tool: tool || 'unknown', input: input || {} });
|
||||
|
|
@ -236,7 +236,8 @@ export async function initEventListeners(): Promise<void> {
|
|||
agents.update((ags) => {
|
||||
const activeAgent = ags.find((a) => a.status === 'active');
|
||||
if (activeAgent) {
|
||||
addToolCall(activeAgent.id, tool || 'unknown', input || {});
|
||||
// Backend-ID durchreichen damit tool-end den Call matchen kann
|
||||
addToolCall(activeAgent.id, tool || 'unknown', input || {}, id);
|
||||
}
|
||||
return ags;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue