Files
tutti/packages/agent/gui/shared/workspaceAgentToolCallAgentActivity.ts
agent-radar 2ed3415fb7
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
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

83 lines
2.2 KiB
TypeScript

import type { WorkspaceAgentActivityTimelineItem } from "./workspaceAgentTimelineTypes";
const AGENT_ACTIVITY_KINDS = new Set([
"thinking",
"responding",
"notification"
]);
export function isAgentActivityTimelineItem(
item: WorkspaceAgentActivityTimelineItem
): boolean {
const activityKey = activityPayloadKey(item);
if (activityKey.startsWith("agent.")) {
return true;
}
const metadata = recordValue(item.payload, "metadata");
const normalizedKind = normalizeToolToken(
firstPresentString(
stringRecordValue(item.payload, "activityKind"),
stringRecordValue(item.payload, "activity_kind"),
stringRecordValue(metadata, "activityKind"),
stringRecordValue(metadata, "activity_kind")
)
);
if (AGENT_ACTIVITY_KINDS.has(normalizedKind)) {
return true;
}
const normalizedName = (item.name ?? "")
.trim()
.toLowerCase()
.replace(/[.\-\s]+/gu, "_");
return normalizedName.startsWith("agent_");
}
function activityPayloadKey(item: WorkspaceAgentActivityTimelineItem): string {
const metadata = recordValue(item.payload, "metadata");
return firstPresentString(
stringRecordValue(item.payload, "activityKey"),
stringRecordValue(item.payload, "activity_key"),
stringRecordValue(metadata, "activityKey"),
stringRecordValue(metadata, "activity_key")
)
.trim()
.toLowerCase();
}
function normalizeToolToken(value: string | undefined): string {
return (
value
?.trim()
.toLowerCase()
.replace(/[-\s]+/gu, "_") ?? ""
);
}
function recordValue(
value: Record<string, unknown> | undefined,
key: string
): Record<string, unknown> | undefined {
const entry = value?.[key];
return typeof entry === "object" && entry !== null && !Array.isArray(entry)
? (entry as Record<string, unknown>)
: undefined;
}
function stringRecordValue(
value: Record<string, unknown> | undefined,
key: string
): string | undefined {
const entry = value?.[key];
return typeof entry === "string" ? entry : undefined;
}
function firstPresentString(...values: Array<string | undefined>): string {
return (
values.find(
(value) => typeof value === "string" && value.trim().length > 0
) ?? ""
);
}