Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: addressed feedback

Sheen Capadngan8404a2edf446
diff --git a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.test.ts b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.test.ts
index 2a286a34de..cadefb26a9 100644
--- a/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.test.ts
+++ b/backend/src/ee/services/agent-vault-oauth/agent-vault-oauth-service.test.ts
@@ -753,6 +753,7 @@ describe("using an authorization", () => {
const oauthConfig = (overrides: Partial<TAgentVaultOauthConfig> = {}): TAgentVaultOauthConfig => ({
type: AgentVaultCredentialType.OAuth,
grantType: "authorization_code",
+ serverUrl: SERVER_URL,
issuer: "https://mcp.linear.app",
authorizationEndpoint: "https://mcp.linear.app/authorize",
tokenEndpoint: "https://mcp.linear.app/token",
diff --git a/frontend/src/components/agent-vault/ServiceTemplateSelect.tsx b/frontend/src/components/agent-vault/ServiceTemplateSelect.tsx
index 967834b1b0..bd8fb5c925 100644
--- a/frontend/src/components/agent-vault/ServiceTemplateSelect.tsx
+++ b/frontend/src/components/agent-vault/ServiceTemplateSelect.tsx
@@ -7,10 +7,15 @@ import {
CardTitle,
InputGroup,
InputGroupAddon,
- InputGroupInput
+ InputGroupInput,
+ Item,
+ ItemContent,
+ ItemDescription,
+ ItemHeader,
+ ItemMedia,
+ ItemTitle
} from "@app/components/v3";
import { ProviderIcon } from "@app/components/v3/platform/ProviderIcon";
-import { cn } from "@app/components/v3/utils";
import {
AGENT_VAULT_MCP_TEMPLATES,
AGENT_VAULT_TEMPLATES,
@@ -45,6 +50,33 @@ const TYPE_FILTERS: { value: TypeFilter; label: string; count: number }[] = [
const templateTag = (template: AgentVaultTemplate) =>
template.serviceType === AgentVaultServiceType.Mcp ? "MCP Server" : template.category;
+const SelectableCard = ({
+ media,
+ tag,
+ name,
+ description,
+ onSelect
+}: {
+ media: ReactNode;
+ tag?: string;
+ name: string;
+ description: string;
+ onSelect: () => void;
+}) => (
+ <Item asChild variant="outline" className="cursor-pointer hover:bg-container-hover">
+ <button type="button" onClick={onSelect}>
+ <ItemHeader>
+ <ItemMedia variant="image">{media}</ItemMedia>
+ {tag && <Badge variant="outline">{tag}</Badge>}
+ </ItemHeader>
+ <ItemContent>
+ <ItemTitle>{name}</ItemTitle>
+ <ItemDescription>{description}</ItemDescription>
+ </ItemContent>
+ </button>
+ </Item>
+);
+
const TemplateCard = ({
template,
onSelect
@@ -55,32 +87,23 @@ const TemplateCard = ({
const [hasImageError, setHasImageError] = useState(false);
return (
- <Button
- type="button"
- variant="outline"
- onClick={() => onSelect(template)}
- className="group h-auto w-full flex-col items-stretch gap-3 bg-card p-4 text-left whitespace-normal hover:bg-container-hover"
- >
- <div className="flex items-start justify-between gap-2">
- <div className="flex size-9 items-center justify-center rounded-md bg-container">
- {hasImageError ? (
- <GlobeIcon className="size-5 text-muted" />
- ) : (
- <ProviderIcon
- icon={template.image}
- alt={`${template.name} logo`}
- className="size-6 object-contain"
- onError={() => setHasImageError(true)}
- />
- )}
- </div>
- <Badge variant="outline">{templateTag(template)}</Badge>
- </div>
- <div className="flex flex-col gap-1">
- <CardTitle className="text-sm leading-snug">{template.name}</CardTitle>
- <p className="text-xs leading-relaxed text-muted">{template.description}</p>
- </div>
- </Button>
+ <SelectableCard
+ media={
+ hasImageError ? (
+ <GlobeIcon />
+ ) : (
+ <ProviderIcon
+ icon={template.image}
+ alt={`${template.name} logo`}
+ onError={() => setHasImageError(true)}
+ />
+ )
+ }
+ tag={templateTag(template)}
+ name={template.name}
+ description={template.description}
+ onSelect={() => onSelect(template)}
+ />
);
};
@@ -93,22 +116,7 @@ const CustomCard = ({
description: string;
onSelect: () => void;
}) => (
- <Button
- type="button"
- variant="outline"
- onClick={onSelect}
- className="group h-auto w-full flex-col items-stretch gap-3 border-dashed bg-card p-4 text-left whitespace-normal hover:bg-container-hover"
- >
- <div className="flex items-start gap-2">
- <div className="flex size-9 items-center justify-center rounded-md bg-container">
- <PlusIcon className="size-5 text-muted" />
- </div>
- </div>
- <div className="flex flex-col gap-1">
- <CardTitle className="text-sm leading-snug">{name}</CardTitle>
- <p className="text-xs leading-relaxed text-muted">{description}</p>
- </div>
- </Button>
+ <SelectableCard media={<PlusIcon />} name={name} description={description} onSelect={onSelect} />
);
const Grid = ({ children }: { children: ReactNode }) => (
@@ -253,15 +261,11 @@ export const ServiceTemplateSelect = ({ onSelect }: Props) => {
<Button
key={filter.value}
type="button"
- variant="ghost"
+ variant={isActive ? "outline" : "ghost"}
+ isFullWidth
aria-pressed={isActive}
onClick={() => setTypeFilter(filter.value)}
- className={cn(
- "w-full justify-between text-left",
- isActive
- ? "bg-container-hover text-foreground"
- : "text-muted hover:bg-container-hover/50 hover:text-foreground"
- )}
+ className="justify-between"
>
{filter.label}
<span className="text-xs text-muted tabular-nums">{filter.count}</span>
diff --git a/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx b/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
index edb87b5acf..3f546e8e3f 100644
--- a/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
+++ b/frontend/src/components/agent-vault/service-sheet/OAuthAuthorizeCard.tsx
@@ -1,4 +1,4 @@
-import { useId } from "react";
+import { useId, useState } from "react";
import { useFormContext, useWatch } from "react-hook-form";
import { format } from "date-fns";
import { CheckIcon, CircleAlertIcon, ShieldCheckIcon } from "lucide-react";
@@ -91,6 +91,9 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service }: Props) => {
});
const clientIdInputId = useId();
const clientSecretInputId = useId();
+ // The server reuses a stored client on reauthorization, so a rotated or expired one can only be
+ // replaced by entering it here.
+ const [isReplacingClient, setIsReplacingClient] = useState(false);
const trimmedUrl = serverUrl.trim();
const host = hostOf(trimmedUrl);
@@ -116,13 +119,20 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service }: Props) => {
});
const isWaiting = state.status === "starting" || state.status === "pending";
+ const isClientEntered = isClientRequired || isReplacingClient;
+
+ const keepSavedClient = () => {
+ setIsReplacingClient(false);
+ setValue("oauthClientId", "");
+ setValue("oauthClientSecret", "");
+ };
const handleAuthorize = () =>
authorize({
accessBundleId,
serverUrl: trimmedUrl,
...(stored && service ? { serviceId: service.id } : {}),
- ...(isClientRequired
+ ...(isClientEntered
? { clientId: clientId.trim(), clientSecret: clientSecret || undefined }
: {})
});
@@ -228,9 +238,16 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service }: Props) => {
<div className="min-w-0 flex-1">{renderStatus()}</div>
</div>
- {isClientRequired && redirectUri && !isNewlyAuthorized && (
+ {isClientEntered && !isNewlyAuthorized && (
<div className="flex flex-col gap-4 border-t border-border pt-4">
- {registrationError ? (
+ {!isClientRequired && (
+ <p className="text-sm text-muted">
+ Enter the client ID and secret of the OAuth app to use from now on. They replace
+ the saved client when you reauthorize. Its redirect URI must point to this
+ Infisical instance.
+ </p>
+ )}
+ {isClientRequired && registrationError && (
<>
<Alert variant="warning">
<CircleAlertIcon />
@@ -241,24 +258,27 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service }: Props) => {
then enter its client ID and secret.
</p>
</>
- ) : (
+ )}
+ {isClientRequired && !registrationError && (
<p className="text-sm text-muted">
{host} doesn&apos;t let Infisical register itself as a client. Create an OAuth app
with the provider, set its redirect URI to the one below, then enter its client ID
and secret.
</p>
)}
- <Field>
- <FieldLabel>Redirect URI</FieldLabel>
- <FieldContent>
- <div className="flex items-center gap-2">
- <code className="min-w-0 flex-1 truncate rounded-md border border-border bg-card px-2 py-1.5 font-mono text-xs">
- {redirectUri}
- </code>
- <CopyButton value={redirectUri} ariaLabel="Copy redirect URI" />
- </div>
- </FieldContent>
- </Field>
+ {redirectUri && (
+ <Field>
+ <FieldLabel>Redirect URI</FieldLabel>
+ <FieldContent>
+ <div className="flex items-center gap-2">
+ <code className="min-w-0 flex-1 truncate rounded-md border border-border bg-card px-2 py-1.5 font-mono text-xs">
+ {redirectUri}
+ </code>
+ <CopyButton value={redirectUri} ariaLabel="Copy redirect URI" />
+ </div>
+ </FieldContent>
+ </Field>
+ )}
<div className="flex flex-col gap-3 md:flex-row">
<Field className="flex-1">
<FieldLabel htmlFor={clientIdInputId}>Client ID</FieldLabel>
@@ -315,16 +335,26 @@ export const OAuthAuthorizeCard = ({ accessBundleId, service }: Props) => {
</Button>
</div>
) : (
- <div>
+ <div className="flex flex-wrap items-center gap-2">
<Button
type="button"
variant={hasAuthorization ? "outline" : "av"}
size="sm"
onClick={handleAuthorize}
- isDisabled={!trimmedUrl || (isClientRequired && !clientId.trim())}
+ isDisabled={!trimmedUrl || (isClientEntered && !clientId.trim())}
>
{state.status === "failed" ? "Try Again" : authorizeLabel}
</Button>
+ {stored && !isClientRequired && !isNewlyAuthorized && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={isReplacingClient ? keepSavedClient : () => setIsReplacingClient(true)}
+ >
+ {isReplacingClient ? "Keep Saved Client" : "Use a Different Client"}
+ </Button>
+ )}
</div>
)}
</div>
diff --git a/frontend/src/hooks/api/agentVault/sessionLogDecrypt.test.ts b/frontend/src/hooks/api/agentVault/sessionLogDecrypt.test.ts
index b5d4738405..7aafef475a 100644
--- a/frontend/src/hooks/api/agentVault/sessionLogDecrypt.test.ts
+++ b/frontend/src/hooks/api/agentVault/sessionLogDecrypt.test.ts
@@ -56,6 +56,17 @@ describe("parseSessionLogRecords", () => {
assert.deepEqual(parseSessionLogRecords([mcpRecord]), [mcpRecord]);
});
+ it("keeps the flag on a batch the proxy cut short", () => {
+ const [parsed] = parseSessionLogRecords([
+ {
+ ...record,
+ serviceType: "mcp",
+ mcp: { calls: [{ method: "ping" }], parsed: true, truncated: true }
+ }
+ ])!;
+ assert.equal(parsed.mcp?.truncated, true);
+ });
+
it("drops a malformed MCP detail rather than the whole chunk", () => {
const [parsed] = parseSessionLogRecords([
{ ...record, serviceType: "mcp", mcp: { calls: "tools/call" } }
diff --git a/frontend/src/hooks/api/agentVault/sessionLogDecrypt.ts b/frontend/src/hooks/api/agentVault/sessionLogDecrypt.ts
index a419e256ef..ebb1239791 100644
--- a/frontend/src/hooks/api/agentVault/sessionLogDecrypt.ts
+++ b/frontend/src/hooks/api/agentVault/sessionLogDecrypt.ts
@@ -71,7 +71,8 @@ const SessionLogRecordsSchema = z.array(
mcp: z
.object({
calls: z.array(z.object({ method: z.string(), tool: z.string().nullish() })),
- parsed: z.boolean()
+ parsed: z.boolean(),
+ truncated: z.boolean().optional()
})
.optional()
.catch(undefined)
diff --git a/frontend/src/hooks/api/agentVault/types.ts b/frontend/src/hooks/api/agentVault/types.ts
index cc918321e8..68e01dbb57 100644
--- a/frontend/src/hooks/api/agentVault/types.ts
+++ b/frontend/src/hooks/api/agentVault/types.ts
@@ -448,6 +448,8 @@ export type TAgentVaultSessionLogMcpDetail = {
calls: TAgentVaultSessionLogMcpCall[];
// False when the proxy could not read the body, as for one over its size limit.
parsed: boolean;
+ // True when the batch held more calls than the proxy keeps in one record.
+ truncated?: boolean;
};
export type TAgentVaultSessionLogRecord = {
diff --git a/frontend/src/pages/agent-vault/AgentVaultOAuthCallbackPage/AgentVaultOAuthCallbackPage.tsx b/frontend/src/pages/agent-vault/AgentVaultOAuthCallbackPage/AgentVaultOAuthCallbackPage.tsx
index 09b574c6f0..a2cd0fe7fb 100644
--- a/frontend/src/pages/agent-vault/AgentVaultOAuthCallbackPage/AgentVaultOAuthCallbackPage.tsx
+++ b/frontend/src/pages/agent-vault/AgentVaultOAuthCallbackPage/AgentVaultOAuthCallbackPage.tsx
@@ -2,10 +2,19 @@ import { useEffect, useRef, useState } from "react";
import { Helmet } from "react-helmet";
import { useSearch } from "@tanstack/react-router";
import axios from "axios";
+import { CircleAlertIcon } from "lucide-react";
import { AuthPageLayout } from "@app/components/auth/AuthPageLayout";
import { AuthPagePanel } from "@app/components/auth/AuthPagePanel";
-import { Button, CardContent, CardDescription, CardHeader, CardTitle } from "@app/components/v3";
+import {
+ Alert,
+ AlertDescription,
+ Button,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle
+} from "@app/components/v3";
import {
AgentVaultOAuthAuthorizationStatus,
useCompleteAgentVaultOAuthAuthorization
@@ -85,7 +94,7 @@ export const AgentVaultOAuthCallbackPage = () => {
"This window closes on its own. Return to Infisical to finish adding the service.";
} else if (outcome.status === "failed") {
title = "Authorization Failed";
- description = outcome.message;
+ description = "This window closes on its own. Return to Infisical and select Authorize again.";
}
return (
@@ -94,23 +103,23 @@ export const AgentVaultOAuthCallbackPage = () => {
<title>Agent Vault Authorization</title>
</Helmet>
<AuthPagePanel>
- <CardHeader className="mb-6 gap-2">
- <CardTitle
- className={
- outcome.status === "failed"
- ? "font-alliance text-2xl font-normal text-danger"
- : "font-alliance text-2xl font-normal"
- }
- >
- {title}
- </CardTitle>
- <CardDescription className="text-base">{description}</CardDescription>
+ <CardHeader>
+ <CardTitle>{title}</CardTitle>
+ <CardDescription>{description}</CardDescription>
</CardHeader>
{outcome.status !== "working" && (
- <CardContent>
- <Button type="button" variant="outline" onClick={() => window.close()}>
- Close Window
- </Button>
+ <CardContent className="flex flex-col gap-4">
+ {outcome.status === "failed" && (
+ <Alert variant="danger">
+ <CircleAlertIcon />
+ <AlertDescription>{outcome.message}</AlertDescription>
+ </Alert>
+ )}
+ <div>
+ <Button type="button" variant="outline" onClick={() => window.close()}>
+ Close Window
+ </Button>
+ </div>
</CardContent>
)}
</AuthPagePanel>
diff --git a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogRow.tsx b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogRow.tsx
index 29c397366f..c7741aa08f 100644
--- a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogRow.tsx
+++ b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogRow.tsx
@@ -28,7 +28,13 @@ import {
TAgentVaultSessionLogRecord
} from "@app/hooks/api/agentVault/types";
-import { httpStatusLabel, mcpCallLabel, sessionLogMcpCalls } from "./SessionLogsPanel.utils";
+import {
+ groupRepeatedMcpCalls,
+ httpStatusLabel,
+ mcpMoreCallsLabel,
+ sessionLogMcpCalls,
+ sessionLogMcpCallsTruncated
+} from "./SessionLogsPanel.utils";
const ARRIVAL_HOLD_MS = 1200;
@@ -117,6 +123,7 @@ const McpCallText = ({ call }: { call: TAgentVaultSessionLogMcpCall }) =>
const McpDetail = ({ record }: { record: TAgentVaultSessionLogRecord }) => {
const [first, ...rest] = sessionLogMcpCalls(record);
+ const truncated = sessionLogMcpCallsTruncated(record);
return (
<span className="flex min-w-0 items-center gap-1.5">
@@ -133,16 +140,28 @@ const McpDetail = ({ record }: { record: TAgentVaultSessionLogRecord }) => {
{record.path}
</span>
)}
- {rest.length > 0 && (
+ {(rest.length > 0 || truncated) && (
<Tooltip>
- <TooltipTrigger className="shrink-0 text-xs text-muted">+{rest.length}</TooltipTrigger>
- <TooltipContent>
- <div className="flex flex-col font-mono text-xs">
- {rest.map((call, index) => (
- // eslint-disable-next-line react/no-array-index-key
- <span key={index}>{mcpCallLabel(call)}</span>
- ))}
- </div>
+ <TooltipTrigger className="shrink-0 text-xs text-muted">
+ {mcpMoreCallsLabel(rest.length, truncated)}
+ </TooltipTrigger>
+ <TooltipContent className="max-w-sm">
+ {rest.length > 0 && (
+ <div className="flex flex-col font-mono text-xs">
+ {groupRepeatedMcpCalls(rest).map(({ label, count }, index) => (
+ // eslint-disable-next-line react/no-array-index-key
+ <span key={index}>
+ {label}
+ {count > 1 && <span className="text-muted"> ×{count}</span>}
+ </span>
+ ))}
+ </div>
+ )}
+ {truncated && (
+ <p className={twMerge("text-xs text-muted", rest.length > 0 && "mt-1.5")}>
+ More calls in this batch weren&apos;t recorded.
+ </p>
+ )}
</TooltipContent>
</Tooltip>
)}
diff --git a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.test.ts b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.test.ts
index 32fbe4ac85..5bf1f90b1f 100644
--- a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.test.ts
+++ b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.test.ts
@@ -10,11 +10,14 @@ import { TAgentVaultSessionLogRecord } from "@app/hooks/api/agentVault/types";
import {
chunkIdTime,
findRowShift,
+ groupRepeatedMcpCalls,
groupSessionLogGaps,
matchesSessionLogSearch,
matchesSessionLogType,
mcpCallLabel,
- sessionLogMcpCalls
+ mcpMoreCallsLabel,
+ sessionLogMcpCalls,
+ sessionLogMcpCallsTruncated
} from "./SessionLogsPanel.utils";
const record = (seq: number): TAgentVaultSessionLogRecord => ({
@@ -201,6 +204,85 @@ describe("sessionLogMcpCalls", () => {
});
});
+describe("sessionLogMcpCallsTruncated", () => {
+ const calls = [{ method: "tools/call", tool: "search" }];
+ const mcpRecord = (mcp: TAgentVaultSessionLogRecord["mcp"]): TAgentVaultSessionLogRecord => ({
+ ...record(1),
+ serviceType: AgentVaultServiceType.Mcp,
+ mcp
+ });
+
+ it("is true for a parsed MCP batch the proxy cut short", () => {
+ assert.equal(
+ sessionLogMcpCallsTruncated(mcpRecord({ parsed: true, truncated: true, calls })),
+ true
+ );
+ });
+
+ it("is false when the batch was kept whole or the flag is absent", () => {
+ assert.equal(
+ sessionLogMcpCallsTruncated(mcpRecord({ parsed: true, truncated: false, calls })),
+ false
+ );
+ assert.equal(sessionLogMcpCallsTruncated(mcpRecord({ parsed: true, calls })), false);
+ });
+
+ it("is false when there are no calls to show it beside", () => {
+ assert.equal(
+ sessionLogMcpCallsTruncated(mcpRecord({ parsed: false, truncated: true, calls })),
+ false
+ );
+ assert.equal(
+ sessionLogMcpCallsTruncated(mcpRecord({ parsed: true, truncated: true, calls: [] })),
+ false
+ );
+ assert.equal(
+ sessionLogMcpCallsTruncated({
+ ...record(1),
+ serviceType: AgentVaultServiceType.Http,
+ mcp: { parsed: true, truncated: true, calls }
+ }),
+ false
+ );
+ });
+});
+
+describe("groupRepeatedMcpCalls", () => {
+ it("merges neighbouring repeats and keeps the order", () => {
+ assert.deepEqual(
+ groupRepeatedMcpCalls([
+ { method: "ping" },
+ { method: "ping" },
+ { method: "tools/call", tool: "search" },
+ { method: "tools/call", tool: "search" },
+ { method: "tools/call", tool: "lookup" },
+ { method: "ping" }
+ ]),
+ [
+ { label: "ping", count: 2 },
+ { label: "search (tools/call)", count: 2 },
+ { label: "lookup (tools/call)", count: 1 },
+ { label: "ping", count: 1 }
+ ]
+ );
+ });
+
+ it("returns nothing for no calls", () => {
+ assert.deepEqual(groupRepeatedMcpCalls([]), []);
+ });
+});
+
+describe("mcpMoreCallsLabel", () => {
+ it("counts the calls not shown in the row", () => {
+ assert.equal(mcpMoreCallsLabel(31, false), "+31 more");
+ });
+
+ it("gives a floor when the batch was cut short", () => {
+ assert.equal(mcpMoreCallsLabel(31, true), "32+ more");
+ assert.equal(mcpMoreCallsLabel(0, true), "1+ more");
+ });
+});
+
describe("mcpCallLabel", () => {
it("leads with the tool name of a tool call", () => {
assert.equal(mcpCallLabel({ method: "tools/call", tool: "search" }), "search (tools/call)");
diff --git a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.ts b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.ts
index d14869960d..baa42b5216 100644
--- a/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.ts
+++ b/frontend/src/pages/agent-vault/AgentVaultSessionsPage/components/SessionLogsPanel.utils.ts
@@ -138,5 +138,25 @@ export const sessionLogMcpCalls = (
return record.mcp.calls;
};
+export const sessionLogMcpCallsTruncated = (record: TAgentVaultSessionLogRecord) =>
+ sessionLogMcpCalls(record).length > 0 && record.mcp?.truncated === true;
+
export const mcpCallLabel = (call: TAgentVaultSessionLogMcpCall) =>
call.tool ? `${call.tool} (${call.method})` : call.method;
+
+// Only neighbours are merged, so the list still reads in the order the agent sent the calls.
+export const groupRepeatedMcpCalls = (calls: TAgentVaultSessionLogMcpCall[]) =>
+ calls.reduce<{ label: string; count: number }[]>((groups, call) => {
+ const label = mcpCallLabel(call);
+ const last = groups.at(-1);
+ if (last?.label === label) {
+ last.count += 1;
+ } else {
+ groups.push({ label, count: 1 });
+ }
+ return groups;
+ }, []);
+
+// A truncated batch held at least one call past the recorded ones, so the count is a floor.
+export const mcpMoreCallsLabel = (shown: number, truncated: boolean) =>
+ truncated ? `${shown + 1}+ more` : `+${shown} more`;