Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tavro_app/src/components/AgentHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ const AgentHeader: React.FC<AgentHeaderProps> = ({
)}
</div>
</div>
</div>
);
};

Expand Down
39 changes: 38 additions & 1 deletion tavro_app/src/pages/AgentViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,45 @@ const AgentViewPage: React.FC = () => {
useEffect(() => {
if (!agent?.identification?.agent_id) return;
if (agent.identification.governance_status !== 'Risk Assessment is running') return;
const handleWorkflowUpdate = () => { fetchAgent(); };

const handleWorkflowUpdate = () => {
// Invalidate the MCP detail cache so fetchAgent() always gets fresh
// governance_status from the server rather than a stale cached response.
mcpClient.invalidateCache();
fetchAgent();
};
window.addEventListener('tavro_temporal_workflow_update', handleWorkflowUpdate);

// If the workflow already completed before the user navigated to this page,
// the tavro_temporal_workflow_update event may never fire again (snapshot is
// stable). Check the current snapshot now and proactively re-fetch if there
// is no running workflow for this agent.
try {
const raw = localStorage.getItem('tavro_temporal_workflows');
if (raw !== null) {
const norm = (v: unknown) => String(v ?? '').trim().toLowerCase();
const agentId = agent.identification.agent_id;
const agentName = agent.name ?? '';
const workflows = JSON.parse(raw) as Array<{
status: string;
agent_id?: string;
agent_internal_id?: string;
name?: string;
}>;
const hasRunning = workflows.some(
w =>
w.status === 'running' &&
(norm(w.agent_id) === norm(agentId) ||
norm(w.agent_internal_id) === norm(agentId) ||
norm(w.name) === norm(agentName)),
);
if (!hasRunning) {
mcpClient.invalidateCache();
fetchAgent();
}
}
} catch { /* ignore */ }

return () => window.removeEventListener('tavro_temporal_workflow_update', handleWorkflowUpdate);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [agent?.identification?.agent_id, agent?.identification?.governance_status]);
Expand Down
27 changes: 27 additions & 0 deletions tavro_app/src/pages/SparkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,33 @@ const IdeaModal: React.FC<{
const agentId = extractStringByKeys(agent, ['agent_id', 'agent_catalog_id', 'id']);
if (agentId) {
await mcpClient.createAiUseCaseAgentRelationship(useCaseId, agentId);

// Register the agent as locally pending so CatalogContext can track
// the workflow completion and clear the badge on the agent detail page.
// Without this, mcpClient.createAgent() does not fire tavro:agent-created,
// so the workflow completion event would be missed by AgentViewPage.
try {
const pendingRaw = localStorage.getItem('tavro_pending_assessment_agents');
const pending = pendingRaw ? (JSON.parse(pendingRaw) as string[]) : [];
localStorage.setItem(
'tavro_pending_assessment_agents',
JSON.stringify(Array.from(new Set([...pending, agentId]))),
);
const metaRaw = localStorage.getItem('tavro_pending_assessment_agent_meta');
const meta = metaRaw
? (JSON.parse(metaRaw) as Array<{ agent_id: string; name: string; description: string; created_at: string }>)
: [];
const filtered = meta.filter(item => item.agent_id !== agentId);
filtered.unshift({
agent_id: agentId,
name: agentName,
description: asNonEmptyString(agentRec?.description) ?? agentName,
created_at: new Date().toISOString(),
});
localStorage.setItem('tavro_pending_assessment_agent_meta', JSON.stringify(filtered));
} catch {
// localStorage writes are best-effort
}
}
} catch {
// Agent creation is best-effort; use case was created successfully
Expand Down