Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(conversations): correct approval countdown to use remaining time

Steven Enamakelde16494e717d
diff --git a/app/src/features/conversations/aui/approvalCountdown.ts b/app/src/features/conversations/aui/approvalCountdown.ts
new file mode 100644
index 0000000000..27277e1312
--- /dev/null
+++ b/app/src/features/conversations/aui/approvalCountdown.ts
@@ -0,0 +1,35 @@
+import { useEffect, useState } from 'react';
+
+/**
+ * Live "expires in Ns" text for a parked approval's TTL, ticking once a
+ * second. Shared by every approval surface (in-thread gated tool call,
+ * out-of-thread flow/unrouted/flow-run banners) so the countdown format never
+ * drifts between them.
+ *
+ * Returns `null` once expired or when `expiresAt` is absent/unparseable —
+ * callers render nothing in that case rather than a negative countdown; the
+ * `approval_decided` socket event (`resolvePendingApprovalForThread`) is what
+ * actually resolves an expired gate, not this timer.
+ */
+export function useApprovalExpirySeconds(expiresAt: string | null | undefined): number | null {
+ const [now, setNow] = useState(() => Date.now());
+
+ useEffect(() => {
+ if (!expiresAt) return;
+ const id = window.setInterval(() => setNow(Date.now()), 1_000);
+ return () => window.clearInterval(id);
+ }, [expiresAt]);
+
+ if (!expiresAt) return null;
+ const expiresAtMs = Date.parse(expiresAt);
+ if (Number.isNaN(expiresAtMs)) return null;
+ const remaining = Math.round((expiresAtMs - now) / 1_000);
+ return remaining > 0 ? remaining : null;
+}
+
+/** `125` -> `2:05`; `45` -> `0:45`. Locale-neutral (digits + `:` only). */
+export function formatCountdown(seconds: number): string {
+ const minutes = Math.floor(seconds / 60);
+ const rest = seconds % 60;
+ return `${minutes}:${String(rest).padStart(2, '0')}`;
+}
diff --git a/app/src/features/conversations/components/aui/ChatSources.tsx b/app/src/features/conversations/components/aui/ChatSources.tsx
index 8838501425..cbe0bae689 100644
--- a/app/src/features/conversations/components/aui/ChatSources.tsx
+++ b/app/src/features/conversations/components/aui/ChatSources.tsx
@@ -14,10 +14,24 @@
* `components/ai-elements/Sources.tsx` disclosure — every source shows as a
* badge/link inline, nothing hidden behind a click.
*/
-import { Sources } from '../../../../components/assistant-ui/elements/sources.aui';
+import { Badge } from '../../../../components/assistant-ui/badge';
+import {
+ DocumentSourceIcon,
+ Source,
+ SourceIcon,
+ SourceTitle,
+} from '../../../../components/assistant-ui/elements/sources.aui';
import type { SourceItemPart } from '../../../../components/assistant-ui/thread';
import { useT } from '../../../../lib/i18n/I18nContext';
+/**
+ * Composes the vendored `sources.aui` primitives (`Source`/`SourceIcon`/
+ * `SourceTitle`/`DocumentSourceIcon`/`Badge`) directly rather than calling its
+ * `Sources` message-part component: that component's prop type is the full
+ * assistant-ui `SourceMessagePartProps` (part `status`, `mediaType`, ...),
+ * which this app's `SourceItemPart` (derived from `extractAgentSources` /
+ * memory citations, not a live message-part subscription) does not carry.
+ */
export function ChatSources({ sources }: { sources: readonly SourceItemPart[] }) {
const { t } = useT();
if (sources.length === 0) return null;
@@ -29,13 +43,19 @@ export function ChatSources({ sources }: { sources: readonly SourceItemPart[] })
className="mt-1 flex flex-wrap items-center gap-1.5">
{sources.map(source =>
source.sourceType === 'url' ? (
- <Sources key={source.id} sourceType="url" url={source.url} title={source.title} />
+ <Source key={source.id} href={source.url} data-testid="agent-source-row">
+ <SourceIcon url={source.url} />
+ <SourceTitle>{source.title || source.url}</SourceTitle>
+ </Source>
) : (
- <Sources
- key={source.id}
- sourceType="document"
- title={source.title ?? t('conversations.agentTaskInsights.memoryCitationFallbackTitle')}
- />
+ <Badge key={source.id} variant="secondary" data-testid="agent-memory-source-row">
+ <span className="inline-flex items-center gap-1.5">
+ <DocumentSourceIcon />
+ <SourceTitle>
+ {source.title ?? t('conversations.agentTaskInsights.memoryCitationFallbackTitle')}
+ </SourceTitle>
+ </span>
+ </Badge>
)
)}
</section>