源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
This commit is contained in:
commit
2ed3415fb7
8018 files changed
+1936476
No files matched your search
@@ -0,0 +1,212 @@
|
||||
import { Info } from "lucide-react";
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type CSSProperties,
|
||||
type MouseEvent,
|
||||
type ReactNode
|
||||
} from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import type { DockAgentProbeTooltipLine } from "./desktopDockAgentProbeTooltipModel";
|
||||
|
||||
const POPOVER_MIN_VIEWPORT_INSET_PX = 16;
|
||||
const POPOVER_DEFAULT_WIDTH_PX = 260;
|
||||
|
||||
function dockAgentProbeLineKey(line: DockAgentProbeTooltipLine): string {
|
||||
return typeof line === "string"
|
||||
? line
|
||||
: `${line.label ?? ""}:${line.primary}:${line.secondary ?? ""}`;
|
||||
}
|
||||
|
||||
function renderDockAgentProbeLine(line: DockAgentProbeTooltipLine): ReactNode {
|
||||
if (typeof line === "string") {
|
||||
return line;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{line.primary}
|
||||
{line.secondary ? (
|
||||
<>
|
||||
{" "}
|
||||
<span className="desktop-dock-popup__agent-status-secondary">
|
||||
{line.secondary}
|
||||
</span>
|
||||
</>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function formatDockAgentProbeLineText(line: DockAgentProbeTooltipLine): string {
|
||||
if (typeof line === "string") {
|
||||
return line;
|
||||
}
|
||||
return line.secondary ? `${line.primary} ${line.secondary}` : line.primary;
|
||||
}
|
||||
|
||||
function getDockAgentProbeLineLabel(line: DockAgentProbeTooltipLine): string {
|
||||
return typeof line === "string" ? "" : (line.label ?? "");
|
||||
}
|
||||
|
||||
export function AgentProbeInfoPopover({
|
||||
lines,
|
||||
testId = "agent-probe-info",
|
||||
className,
|
||||
onOpen,
|
||||
onClose
|
||||
}: {
|
||||
lines: DockAgentProbeTooltipLine[];
|
||||
testId?: string;
|
||||
className?: string;
|
||||
onOpen?: () => void;
|
||||
onClose?: () => void;
|
||||
}): React.JSX.Element | null {
|
||||
"use memo";
|
||||
const anchorRef = useRef<HTMLDivElement | null>(null);
|
||||
const popoverRef = useRef<HTMLDivElement | null>(null);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [popoverStyle, setPopoverStyle] = useState<CSSProperties | null>(null);
|
||||
const openPopover = useCallback((): void => {
|
||||
if (!isOpen) {
|
||||
onOpen?.();
|
||||
}
|
||||
setIsOpen(true);
|
||||
}, [isOpen, onOpen]);
|
||||
const closePopover = useCallback((): void => {
|
||||
if (!isOpen) return;
|
||||
setIsOpen(false);
|
||||
onClose?.();
|
||||
}, [isOpen, onClose]);
|
||||
const closeIfPointerLeavesPopover = useCallback(
|
||||
(event: MouseEvent): void => {
|
||||
const nextTarget = event.relatedTarget;
|
||||
if (
|
||||
nextTarget instanceof Node &&
|
||||
(anchorRef.current?.contains(nextTarget) ||
|
||||
popoverRef.current?.contains(nextTarget))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
closePopover();
|
||||
},
|
||||
[closePopover]
|
||||
);
|
||||
const updatePopoverPosition = useCallback((): void => {
|
||||
const anchor = anchorRef.current;
|
||||
if (!anchor) {
|
||||
return;
|
||||
}
|
||||
const rect = anchor.getBoundingClientRect();
|
||||
const availableWidth = Math.max(
|
||||
0,
|
||||
window.innerWidth - POPOVER_MIN_VIEWPORT_INSET_PX * 2
|
||||
);
|
||||
const currentWidth = popoverRef.current?.offsetWidth;
|
||||
const measuredWidth = Math.min(
|
||||
currentWidth && currentWidth > 0
|
||||
? currentWidth
|
||||
: POPOVER_DEFAULT_WIDTH_PX,
|
||||
availableWidth
|
||||
);
|
||||
const centeredLeft = rect.left + rect.width / 2 - measuredWidth / 2;
|
||||
const maxLeft =
|
||||
window.innerWidth - measuredWidth - POPOVER_MIN_VIEWPORT_INSET_PX;
|
||||
setPopoverStyle({
|
||||
top: rect.bottom + 8,
|
||||
left: Math.max(
|
||||
POPOVER_MIN_VIEWPORT_INSET_PX,
|
||||
Math.min(centeredLeft, maxLeft)
|
||||
),
|
||||
maxWidth: availableWidth
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
updatePopoverPosition();
|
||||
}, [isOpen, lines, updatePopoverPosition]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!isOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
updatePopoverPosition();
|
||||
window.addEventListener("resize", updatePopoverPosition);
|
||||
window.addEventListener("scroll", updatePopoverPosition, true);
|
||||
return () => {
|
||||
window.removeEventListener("resize", updatePopoverPosition);
|
||||
window.removeEventListener("scroll", updatePopoverPosition, true);
|
||||
};
|
||||
}, [isOpen, updatePopoverPosition]);
|
||||
|
||||
if (lines.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const popover = (
|
||||
<div
|
||||
ref={popoverRef}
|
||||
className="desktop-dock-popup__agent-info-popover desktop-dock-popup__agent-info-popover--portal"
|
||||
role="status"
|
||||
style={popoverStyle ?? undefined}
|
||||
onMouseEnter={openPopover}
|
||||
onMouseLeave={closeIfPointerLeavesPopover}
|
||||
>
|
||||
<ul className="desktop-dock-popup__agent-info-list">
|
||||
{lines.map((line) => {
|
||||
const label = getDockAgentProbeLineLabel(line);
|
||||
const valueText = formatDockAgentProbeLineText(line);
|
||||
return (
|
||||
<li
|
||||
key={`probe-info-${dockAgentProbeLineKey(line)}`}
|
||||
className="desktop-dock-popup__agent-info-item"
|
||||
data-has-label={label ? "true" : "false"}
|
||||
>
|
||||
{label ? (
|
||||
<span className="desktop-dock-popup__agent-info-label">
|
||||
{label}
|
||||
</span>
|
||||
) : null}
|
||||
<span
|
||||
className="desktop-dock-popup__agent-info-value"
|
||||
title={valueText}
|
||||
>
|
||||
{renderDockAgentProbeLine(line)}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={anchorRef}
|
||||
className={`desktop-dock-popup__agent-info${className ? ` ${className}` : ""}`}
|
||||
tabIndex={0}
|
||||
role="button"
|
||||
aria-label={lines.map(formatDockAgentProbeLineText).join(",")}
|
||||
data-testid={testId}
|
||||
onMouseEnter={() => {
|
||||
updatePopoverPosition();
|
||||
openPopover();
|
||||
}}
|
||||
onMouseLeave={closeIfPointerLeavesPopover}
|
||||
onFocus={() => {
|
||||
updatePopoverPosition();
|
||||
openPopover();
|
||||
}}
|
||||
onBlur={closePopover}
|
||||
>
|
||||
<Info size={15} strokeWidth={2.1} aria-hidden="true" />
|
||||
{isOpen ? createPortal(popover, document.body) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { JSX, SVGProps } from "react";
|
||||
import { GridBottomLinedIcon } from "../../../app/renderer/components/icons/GridBottomLinedIcon";
|
||||
import { GridLeftLinedIcon } from "../../../app/renderer/components/icons/GridLeftLinedIcon";
|
||||
import { GridRightLinedIcon } from "../../../app/renderer/components/icons/GridRightLinedIcon";
|
||||
import { GridTopLinedIcon } from "../../../app/renderer/components/icons/GridTopLinedIcon";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger
|
||||
} from "@tutti-os/ui-system";
|
||||
import { Button } from "../../../app/renderer/components/ui/button";
|
||||
import { useTranslation } from "../../../i18n/index";
|
||||
import { CanvasNodeGhostIconButton } from "../../shared/CanvasNodeGhostIconButton";
|
||||
import {
|
||||
CanvasNodeLayoutLinedIcon,
|
||||
CanvasNodeMaximizeLinedIcon,
|
||||
CanvasNodeMinimizeLinedIcon
|
||||
} from "../../shared/canvasNodeChromeIcons";
|
||||
import { useDesktopStore } from "../store";
|
||||
import type { DesktopSize, WindowQuickLayoutTarget } from "../types";
|
||||
|
||||
const QUICK_LAYOUT_OPTIONS: Array<{
|
||||
target: WindowQuickLayoutTarget;
|
||||
icon: (props: SVGProps<SVGSVGElement>) => JSX.Element;
|
||||
labelKey: string;
|
||||
}> = [
|
||||
{
|
||||
target: "left",
|
||||
icon: GridLeftLinedIcon,
|
||||
labelKey: "workspaceWindowLayout.left"
|
||||
},
|
||||
{
|
||||
target: "right",
|
||||
icon: GridRightLinedIcon,
|
||||
labelKey: "workspaceWindowLayout.right"
|
||||
},
|
||||
{
|
||||
target: "top",
|
||||
icon: GridTopLinedIcon,
|
||||
labelKey: "workspaceWindowLayout.top"
|
||||
},
|
||||
{
|
||||
target: "bottom",
|
||||
icon: GridBottomLinedIcon,
|
||||
labelKey: "workspaceWindowLayout.bottom"
|
||||
}
|
||||
];
|
||||
|
||||
const WINDOW_LAYOUT_MENU_HOVER_OPEN_DELAY_MS = 300;
|
||||
|
||||
interface WindowLayoutMenuButtonProps {
|
||||
windowId: string;
|
||||
desktopSize: DesktopSize;
|
||||
className?: string;
|
||||
"data-window-header"?: string;
|
||||
}
|
||||
|
||||
export function WindowLayoutMenuButton({
|
||||
windowId,
|
||||
desktopSize,
|
||||
className,
|
||||
"data-window-header": windowHeader
|
||||
}: WindowLayoutMenuButtonProps): JSX.Element {
|
||||
"use memo";
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const hoverOpenTimeoutRef = useRef<number | null>(null);
|
||||
const applyQuickLayout = useDesktopStore((state) => state.applyQuickLayout);
|
||||
const enterFullscreenWindow = useDesktopStore(
|
||||
(state) => state.enterFullscreenWindow
|
||||
);
|
||||
const exitFullscreenWindow = useDesktopStore(
|
||||
(state) => state.exitFullscreenWindow
|
||||
);
|
||||
const isFullscreen = useDesktopStore(
|
||||
(state) =>
|
||||
state.windows.find((window) => window.id === windowId)?.displayMode ===
|
||||
"fullscreen"
|
||||
);
|
||||
const fullscreenLabelKey = isFullscreen
|
||||
? "workspaceWindowLayout.restore"
|
||||
: "workspaceWindowLayout.fullscreen";
|
||||
const fullscreenIconState = isFullscreen ? "restore" : "fullscreen";
|
||||
const FullscreenIcon = isFullscreen
|
||||
? CanvasNodeMinimizeLinedIcon
|
||||
: CanvasNodeMaximizeLinedIcon;
|
||||
|
||||
const applyLayout = (target: WindowQuickLayoutTarget) => {
|
||||
applyQuickLayout(windowId, target, desktopSize);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const clearHoverOpenTimeout = () => {
|
||||
if (hoverOpenTimeoutRef.current !== null) {
|
||||
window.clearTimeout(hoverOpenTimeoutRef.current);
|
||||
hoverOpenTimeoutRef.current = null;
|
||||
}
|
||||
};
|
||||
|
||||
const scheduleHoverOpen = () => {
|
||||
if (open || hoverOpenTimeoutRef.current !== null) {
|
||||
return;
|
||||
}
|
||||
hoverOpenTimeoutRef.current = window.setTimeout(() => {
|
||||
hoverOpenTimeoutRef.current = null;
|
||||
setOpen(true);
|
||||
}, WINDOW_LAYOUT_MENU_HOVER_OPEN_DELAY_MS);
|
||||
};
|
||||
|
||||
const toggleFullscreen = () => {
|
||||
if (isFullscreen) {
|
||||
exitFullscreenWindow(windowId, desktopSize);
|
||||
} else {
|
||||
enterFullscreenWindow(windowId, desktopSize);
|
||||
}
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
useEffect(() => clearHoverOpenTimeout, []);
|
||||
|
||||
return (
|
||||
<DropdownMenu
|
||||
open={open}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (!nextOpen) {
|
||||
clearHoverOpenTimeout();
|
||||
}
|
||||
setOpen(nextOpen);
|
||||
}}
|
||||
>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<CanvasNodeGhostIconButton
|
||||
className={className}
|
||||
data-window-header={windowHeader}
|
||||
data-window-layout-menu-trigger="true"
|
||||
data-menu-open={open ? "true" : undefined}
|
||||
data-testid="window-layout-menu-trigger"
|
||||
aria-label={t("workspaceWindowLayout.trigger")}
|
||||
title={t("workspaceWindowLayout.trigger")}
|
||||
onPointerEnter={scheduleHoverOpen}
|
||||
onPointerLeave={clearHoverOpenTimeout}
|
||||
>
|
||||
<CanvasNodeLayoutLinedIcon
|
||||
width={18}
|
||||
height={18}
|
||||
aria-hidden="true"
|
||||
data-testid="window-layout-menu-trigger-icon"
|
||||
/>
|
||||
</CanvasNodeGhostIconButton>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
sideOffset={10}
|
||||
className="t-dropdown is-open relative min-w-[160px] rounded-[var(--tutti-radius-xl)] border border-hairline bg-background-fronted p-0 text-foreground shadow-[var(--tsh-shell-shadow)]"
|
||||
data-origin="top-right"
|
||||
data-testid="window-layout-menu"
|
||||
>
|
||||
<div className="p-2">
|
||||
<div className="mx-1 mt-0.5 mb-1.5 px-1 text-[13px] leading-[20px] font-semibold text-[var(--text-primary)]">
|
||||
{t("workspaceWindowLayout.moveAndResize")}
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-1">
|
||||
{QUICK_LAYOUT_OPTIONS.map((option) => {
|
||||
const Icon = option.icon;
|
||||
return (
|
||||
<Button
|
||||
key={option.target}
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="iconClose"
|
||||
aria-label={t(option.labelKey)}
|
||||
title={t(option.labelKey)}
|
||||
data-testid={`window-layout-menu-quick-layout-${option.target}`}
|
||||
onClick={() => applyLayout(option.target)}
|
||||
>
|
||||
<Icon width={16} height={16} aria-hidden="true" />
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mx-1.5 my-1 border-t border-[var(--line-2)]" />
|
||||
<div className="px-1">
|
||||
<button
|
||||
className="inline-flex min-h-8 w-full items-center gap-2 whitespace-nowrap rounded-[6px] border border-transparent bg-transparent px-0 text-left text-[13px] leading-[20px] font-semibold text-[var(--text-primary)] transition-[background-color,color,border-color] duration-150 ease-in-out hover:bg-block focus-visible:bg-block focus-visible:outline-none"
|
||||
type="button"
|
||||
aria-label={t(fullscreenLabelKey)}
|
||||
title={t(fullscreenLabelKey)}
|
||||
onClick={toggleFullscreen}
|
||||
>
|
||||
<FullscreenIcon
|
||||
width={16}
|
||||
height={16}
|
||||
aria-hidden="true"
|
||||
data-testid="window-layout-menu-fullscreen-icon"
|
||||
data-window-layout-fullscreen-icon={fullscreenIconState}
|
||||
className="shrink-0"
|
||||
/>
|
||||
<span className="whitespace-nowrap">{t(fullscreenLabelKey)}</span>
|
||||
</button>
|
||||
</div>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { TranslateFn } from "../../../i18n/index";
|
||||
import { buildDockAgentProbeTooltipLines } from "./desktopDockAgentProbeTooltipModel";
|
||||
|
||||
const translate = ((key: string) => key) as TranslateFn;
|
||||
|
||||
describe("buildDockAgentProbeTooltipLines", () => {
|
||||
it("renders an exact credits balance instead of reducing it to a percentage", () => {
|
||||
const creditsTranslate = ((
|
||||
key: string,
|
||||
options?: Record<string, unknown>
|
||||
) => {
|
||||
if (key === "agentHost.workspaceAgentProbeQuotaCredits") return "Credits";
|
||||
if (key === "agentHost.workspaceAgentProbeQuotaCreditsRemaining") {
|
||||
return `${String(options?.amount)} Credits remaining`;
|
||||
}
|
||||
return key;
|
||||
}) as TranslateFn;
|
||||
const lines = buildDockAgentProbeTooltipLines(
|
||||
{
|
||||
provider: "acp:codebuddy",
|
||||
availability: { detailsVisible: false, status: "available" },
|
||||
usage: {
|
||||
billingMode: "provider_account",
|
||||
capturedAtUnixMs: 1,
|
||||
quotas: [
|
||||
{
|
||||
amountLimit: 2_100,
|
||||
amountRemaining: 2_100,
|
||||
amountUnit: "credits",
|
||||
percentRemaining: 100,
|
||||
quotaType: "credits"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
false,
|
||||
creditsTranslate,
|
||||
{ includeUsageLines: true }
|
||||
);
|
||||
|
||||
expect(lines).toContainEqual({
|
||||
label: "Credits",
|
||||
primary: "2,100 Credits remaining"
|
||||
});
|
||||
});
|
||||
|
||||
it("renders a stable subscription error instead of a generic empty-usage row", () => {
|
||||
const lines = buildDockAgentProbeTooltipLines(
|
||||
{
|
||||
provider: "acp:kimi-code",
|
||||
availability: {
|
||||
status: "unavailable",
|
||||
detailsVisible: false
|
||||
},
|
||||
lastError: {
|
||||
code: "subscription_required"
|
||||
}
|
||||
},
|
||||
false,
|
||||
translate,
|
||||
{ includeUsageLines: true }
|
||||
);
|
||||
|
||||
expect(lines).toContainEqual({
|
||||
label: "agentHost.workspaceAgentProbeDetailQuota",
|
||||
primary: "agentHost.workspaceAgentProbeErrorSubscriptionRequired"
|
||||
});
|
||||
});
|
||||
});
|
||||
+397
@@ -0,0 +1,397 @@
|
||||
import type { TranslateFn } from "../../../i18n/index";
|
||||
import { toLocalShortDateTime } from "../../../app/renderer/shell/utils/format";
|
||||
import type {
|
||||
AgentProbeProvider,
|
||||
AgentProbeSnapshot,
|
||||
AgentUsageQuota
|
||||
} from "../../../shared/contracts/dto";
|
||||
import type { AgentProvider } from "../../../contexts/settings/domain/agentSettings";
|
||||
import type { WorkspaceDesktopAgentProbesState } from "../types";
|
||||
|
||||
export function findWorkspaceAgentProbeForDockProvider(
|
||||
snapshot: AgentProbeSnapshot | null | undefined,
|
||||
provider: AgentProvider
|
||||
): AgentProbeProvider | null {
|
||||
if (!snapshot?.providers) {
|
||||
return null;
|
||||
}
|
||||
return snapshot.providers.find((p) => p.provider === provider) ?? null;
|
||||
}
|
||||
|
||||
function quotaRenderStateEquals(
|
||||
left: AgentUsageQuota | undefined,
|
||||
right: AgentUsageQuota | undefined
|
||||
): boolean {
|
||||
return (
|
||||
left?.quotaType === right?.quotaType &&
|
||||
left?.percentRemaining === right?.percentRemaining &&
|
||||
left?.amountRemaining === right?.amountRemaining &&
|
||||
left?.amountLimit === right?.amountLimit &&
|
||||
left?.amountUnit === right?.amountUnit &&
|
||||
left?.resetsAtUnixMs === right?.resetsAtUnixMs &&
|
||||
left?.resetText === right?.resetText &&
|
||||
left?.dollarRemaining === right?.dollarRemaining &&
|
||||
left?.modelName === right?.modelName
|
||||
);
|
||||
}
|
||||
|
||||
export function agentProbeProviderRenderStateEquals(
|
||||
left: AgentProbeProvider | null | undefined,
|
||||
right: AgentProbeProvider | null | undefined
|
||||
): boolean {
|
||||
if (left === right) {
|
||||
return true;
|
||||
}
|
||||
if (!left || !right) {
|
||||
return left === right;
|
||||
}
|
||||
return (
|
||||
left.provider === right.provider &&
|
||||
left.availability.status === right.availability.status &&
|
||||
left.availability.detailsVisible === right.availability.detailsVisible &&
|
||||
(left.availability.checks?.length ?? 0) ===
|
||||
(right.availability.checks?.length ?? 0) &&
|
||||
(left.availability.checks ?? []).every((check, index) => {
|
||||
const next = right.availability.checks?.[index];
|
||||
return (
|
||||
check.name === next?.name &&
|
||||
check.passed === next?.passed &&
|
||||
check.detail === next?.detail
|
||||
);
|
||||
}) &&
|
||||
(left.usage?.accountTier ?? null) === (right.usage?.accountTier ?? null) &&
|
||||
(left.usage?.costUsage?.dollarUsed ?? null) ===
|
||||
(right.usage?.costUsage?.dollarUsed ?? null) &&
|
||||
(left.usage?.costUsage?.dollarLimit ?? null) ===
|
||||
(right.usage?.costUsage?.dollarLimit ?? null) &&
|
||||
(left.usage?.quotas?.length ?? 0) === (right.usage?.quotas?.length ?? 0) &&
|
||||
(left.usage?.quotas ?? []).every((quota, index) =>
|
||||
quotaRenderStateEquals(quota, right.usage?.quotas?.[index])
|
||||
) &&
|
||||
(left.attempts?.length ?? 0) === (right.attempts?.length ?? 0) &&
|
||||
(left.attempts ?? []).every((attempt, index) => {
|
||||
const next = right.attempts?.[index];
|
||||
return (
|
||||
attempt.strategy === next?.strategy &&
|
||||
attempt.success === next?.success &&
|
||||
attempt.errorCode === next?.errorCode &&
|
||||
attempt.errorMessage === next?.errorMessage
|
||||
);
|
||||
}) &&
|
||||
left.lastError?.code === right.lastError?.code &&
|
||||
left.lastError?.message === right.lastError?.message
|
||||
);
|
||||
}
|
||||
|
||||
export function workspaceAgentProbeRenderStateEqualsForProvider(
|
||||
left: WorkspaceDesktopAgentProbesState | null | undefined,
|
||||
right: WorkspaceDesktopAgentProbesState | null | undefined,
|
||||
provider: AgentProvider
|
||||
): boolean {
|
||||
if (left === right) {
|
||||
return true;
|
||||
}
|
||||
return (
|
||||
(left?.isLoadingAvailability ?? false) ===
|
||||
(right?.isLoadingAvailability ?? false) &&
|
||||
(left?.isLoadingUsage ?? false) === (right?.isLoadingUsage ?? false) &&
|
||||
agentProbeProviderRenderStateEquals(
|
||||
findWorkspaceAgentProbeForDockProvider(left?.snapshot ?? null, provider),
|
||||
findWorkspaceAgentProbeForDockProvider(right?.snapshot ?? null, provider)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export interface DockAgentProbePopupLineOptions {
|
||||
/** Append usage / quota lines (requires `includeUsage` probe polling). */
|
||||
includeUsageLines?: boolean;
|
||||
isLoadingUsage?: boolean;
|
||||
}
|
||||
|
||||
export type DockAgentProbeTooltipLine =
|
||||
| string
|
||||
| {
|
||||
label?: string;
|
||||
primary: string;
|
||||
secondary?: string;
|
||||
};
|
||||
|
||||
export function agentProbeErrorLabel(
|
||||
code: string | null | undefined,
|
||||
t: TranslateFn
|
||||
): string {
|
||||
switch (code) {
|
||||
case "auth_required":
|
||||
return t("agentHost.workspaceAgentProbeErrorAuthRequired");
|
||||
case "session_expired":
|
||||
return t("agentHost.workspaceAgentProbeErrorSessionExpired");
|
||||
case "subscription_required":
|
||||
return t("agentHost.workspaceAgentProbeErrorSubscriptionRequired");
|
||||
case "parse_failed":
|
||||
return t("agentHost.workspaceAgentProbeErrorParseFailed");
|
||||
case "no_data":
|
||||
return t("agentHost.workspaceAgentProbeErrorNoData");
|
||||
case "timeout":
|
||||
return t("agentHost.workspaceAgentProbeErrorTimeout");
|
||||
default:
|
||||
return t("agentHost.workspaceAgentProbeErrorUnavailable");
|
||||
}
|
||||
}
|
||||
|
||||
/** Status text for dock popover / inline agent probe UI. */
|
||||
export function buildDockAgentProbeTooltipLines(
|
||||
probe: AgentProbeProvider | null,
|
||||
isLoadingAvailability: boolean,
|
||||
t: TranslateFn,
|
||||
popupOpts?: DockAgentProbePopupLineOptions
|
||||
): DockAgentProbeTooltipLine[] {
|
||||
if (isLoadingAvailability && !probe) {
|
||||
return [t("agentHost.workspaceAgentProbeDockChecking")];
|
||||
}
|
||||
if (!probe) {
|
||||
return [t("agentHost.workspaceAgentProbeDockNoData")];
|
||||
}
|
||||
|
||||
const lines: DockAgentProbeTooltipLine[] = [];
|
||||
switch (probe.availability.status) {
|
||||
case "available":
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailStatus"),
|
||||
primary: t("agentHost.workspaceAgentProbeDockAvailable")
|
||||
});
|
||||
break;
|
||||
case "unavailable":
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailStatus"),
|
||||
primary: t("agentHost.workspaceAgentProbeUnavailableAria")
|
||||
});
|
||||
break;
|
||||
default:
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailStatus"),
|
||||
primary: t("agentHost.workspaceAgentProbeUnknownAria")
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
probe.availability.status !== "available" &&
|
||||
probe.availability.detailsVisible
|
||||
) {
|
||||
for (const check of probe.availability.checks ?? []) {
|
||||
if (!check.passed) {
|
||||
const primary = check.detail?.trim() || check.name.trim();
|
||||
if (!primary) {
|
||||
continue;
|
||||
}
|
||||
lines.push({
|
||||
label: check.name,
|
||||
primary
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const errMsg = probe.lastError?.message?.trim();
|
||||
// Usage-aware dock popup: omit raw probe errors — they duplicate usage polling noise
|
||||
// ("could not find … quotas") while availability is often still fine via checks.
|
||||
if (errMsg && !popupOpts?.includeUsageLines) {
|
||||
lines.push(errMsg);
|
||||
}
|
||||
|
||||
if (!popupOpts?.includeUsageLines) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
appendDockProbeUsageLines(probe, lines, popupOpts.isLoadingUsage ?? false, t);
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
interface DockDisplayQuotaRow {
|
||||
label: string;
|
||||
amountRemaining?: number;
|
||||
amountUnit?: AgentUsageQuota["amountUnit"];
|
||||
percentRemaining?: number;
|
||||
dollarRemaining?: number;
|
||||
resetDisplay?: string;
|
||||
}
|
||||
|
||||
function formatQuotaResetDisplay(
|
||||
quota: AgentUsageQuota | undefined
|
||||
): string | undefined {
|
||||
if (!quota) {
|
||||
return undefined;
|
||||
}
|
||||
if (
|
||||
typeof quota.resetsAtUnixMs === "number" &&
|
||||
Number.isFinite(quota.resetsAtUnixMs)
|
||||
) {
|
||||
return toLocalShortDateTime(quota.resetsAtUnixMs);
|
||||
}
|
||||
return quota.resetText;
|
||||
}
|
||||
|
||||
function quotaTypeLabel(quotaType: string, t: TranslateFn): string {
|
||||
switch (quotaType) {
|
||||
case "session":
|
||||
return t("agentHost.workspaceAgentProbeQuotaSession");
|
||||
case "weekly":
|
||||
return t("agentHost.workspaceAgentProbeQuotaWeekly");
|
||||
case "monthly":
|
||||
return t("agentHost.workspaceAgentProbeQuotaMonthly");
|
||||
case "daily":
|
||||
return t("agentHost.workspaceAgentProbeQuotaDaily");
|
||||
case "cost":
|
||||
return t("agentHost.workspaceAgentProbeQuotaCost");
|
||||
case "credits":
|
||||
return t("agentHost.workspaceAgentProbeQuotaCredits");
|
||||
default:
|
||||
return quotaType;
|
||||
}
|
||||
}
|
||||
|
||||
function buildCompactDisplayQuotas(
|
||||
quotas: AgentUsageQuota[],
|
||||
t: TranslateFn
|
||||
): DockDisplayQuotaRow[] {
|
||||
const modelQuotas = quotas.filter(
|
||||
(quota) => quota.modelName || quota.quotaType === "model"
|
||||
);
|
||||
const nonModelQuotas = quotas.filter(
|
||||
(quota) => !quota.modelName && quota.quotaType !== "model"
|
||||
);
|
||||
const displayRows: DockDisplayQuotaRow[] = nonModelQuotas.map((quota) => ({
|
||||
amountRemaining: quota.amountRemaining,
|
||||
amountUnit: quota.amountUnit,
|
||||
label:
|
||||
quota.quotaType === "session" ? "" : quotaTypeLabel(quota.quotaType, t),
|
||||
percentRemaining: quota.percentRemaining,
|
||||
dollarRemaining: quota.dollarRemaining,
|
||||
resetDisplay: formatQuotaResetDisplay(quota)
|
||||
}));
|
||||
|
||||
if (modelQuotas.length === 0) {
|
||||
return displayRows;
|
||||
}
|
||||
|
||||
const percentQuota = modelQuotas
|
||||
.filter(
|
||||
(quota): quota is AgentUsageQuota & { percentRemaining: number } =>
|
||||
typeof quota.percentRemaining === "number"
|
||||
)
|
||||
.sort((left, right) => left.percentRemaining - right.percentRemaining)[0];
|
||||
const dollarQuota = modelQuotas
|
||||
.filter(
|
||||
(quota): quota is AgentUsageQuota & { dollarRemaining: number } =>
|
||||
typeof quota.dollarRemaining === "number"
|
||||
)
|
||||
.sort((left, right) => left.dollarRemaining - right.dollarRemaining)[0];
|
||||
|
||||
displayRows.push({
|
||||
label: t("agentHost.workspaceAgentProbeAgentUsage"),
|
||||
percentRemaining: percentQuota?.percentRemaining,
|
||||
dollarRemaining: dollarQuota?.dollarRemaining,
|
||||
resetDisplay: formatQuotaResetDisplay(percentQuota ?? dollarQuota)
|
||||
});
|
||||
return displayRows;
|
||||
}
|
||||
|
||||
function formatQuotaPrimaryLine(
|
||||
row: DockDisplayQuotaRow,
|
||||
t: TranslateFn
|
||||
): string | null {
|
||||
if (
|
||||
row.amountUnit === "credits" &&
|
||||
row.amountRemaining !== undefined &&
|
||||
Number.isFinite(row.amountRemaining)
|
||||
) {
|
||||
return t("agentHost.workspaceAgentProbeQuotaCreditsRemaining", {
|
||||
amount: formatQuotaAmount(row.amountRemaining)
|
||||
});
|
||||
}
|
||||
if (row.percentRemaining !== undefined) {
|
||||
return t("agentHost.workspaceAgentProbeQuotaRemaining", {
|
||||
percent: Math.round(row.percentRemaining)
|
||||
});
|
||||
}
|
||||
if (row.dollarRemaining !== undefined) {
|
||||
return t("agentHost.workspaceAgentProbeQuotaDollarRemaining", {
|
||||
amount: row.dollarRemaining.toFixed(2)
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function formatQuotaAmount(value: number): string {
|
||||
return Math.max(0, value).toLocaleString("en-US", {
|
||||
maximumFractionDigits: 2
|
||||
});
|
||||
}
|
||||
|
||||
function appendDockProbeUsageLines(
|
||||
probe: AgentProbeProvider,
|
||||
lines: DockAgentProbeTooltipLine[],
|
||||
isLoadingUsage: boolean,
|
||||
t: TranslateFn
|
||||
): void {
|
||||
if (probe.lastError?.code === "unsupported") {
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailQuota"),
|
||||
primary: t("agentHost.workspaceAgentProbeUsageUnsupported")
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (probe.lastError?.code) {
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailQuota"),
|
||||
primary: agentProbeErrorLabel(probe.lastError.code, t)
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLoadingUsage && !probe.usage) {
|
||||
lines.push(t("agentHost.workspaceAgentProbeLoadingUsage"));
|
||||
return;
|
||||
}
|
||||
|
||||
const quotas = probe.usage?.quotas ?? [];
|
||||
if (quotas.length === 0) {
|
||||
// Whether the probe came back with an empty quota list (usage isn't
|
||||
// wired up for this provider yet) or failed outright (e.g. the OAuth
|
||||
// usage fetch threw right after a fresh install, before credentials
|
||||
// finished propagating — see probeClaudeCodeProvider's lastError), the
|
||||
// user sees the same "no usage" placeholder here. Previously a genuine
|
||||
// fetch failure (probe.usage undefined, lastError set) rendered nothing
|
||||
// at all, so "usage isn't fetched" looked identical to "the popover is
|
||||
// still loading" — silently, with no indication anything had gone wrong
|
||||
// or would need a manual retry (reopening this popover already re-fetches;
|
||||
// see handleAgentProbeInfoOpen / handleAgentConfigMenuOpen).
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeDetailQuota"),
|
||||
primary: t("agentHost.workspaceAgentProbeUsageUnsupported")
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = buildCompactDisplayQuotas(quotas, t);
|
||||
for (const row of rows) {
|
||||
const primary = formatQuotaPrimaryLine(row, t);
|
||||
const labelTrim = row.label.trim();
|
||||
if (primary) {
|
||||
const label = labelTrim || t("agentHost.workspaceAgentProbeDetailQuota");
|
||||
lines.push({
|
||||
label,
|
||||
primary
|
||||
});
|
||||
if (row.resetDisplay) {
|
||||
lines.push({
|
||||
label: t("agentHost.workspaceAgentProbeQuotaResetTimeLabel", {
|
||||
label
|
||||
}),
|
||||
primary: row.resetDisplay
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user