Fix profile agent delete and subview routes

This commit is contained in:
klopez4212
2026-06-22 08:04:59 +01:00
parent b25d074a55
commit 690781f4a9
7 changed files with 72 additions and 15 deletions

View File

@@ -1,13 +1,17 @@
import * as React from "react";
import { createFileRoute } from "@tanstack/react-router";
import {
parseProfilePanelView,
type ProfilePanelView,
} from "@/features/profile/ui/UserProfilePanelUtils";
import { ViewLoadingFallback } from "@/shared/ui/ViewLoadingFallback";
type ChannelRouteSearch = {
agentSession?: string;
messageId?: string;
profile?: string;
profileView?: "memories" | "channels";
profileView?: Exclude<ProfilePanelView, "summary">;
thread?: string;
threadRootId?: string;
};
@@ -16,8 +20,11 @@ function nonEmptyString(value: unknown): string | undefined {
return typeof value === "string" && value.length > 0 ? value : undefined;
}
function profileViewValue(value: unknown): "memories" | "channels" | undefined {
return value === "memories" || value === "channels" ? value : undefined;
function profileViewValue(
value: unknown,
): Exclude<ProfilePanelView, "summary"> | undefined {
const view = parseProfilePanelView(value);
return view && view !== "summary" ? view : undefined;
}
function validateChannelSearch(

View File

@@ -1,6 +1,10 @@
import * as React from "react";
import { createFileRoute } from "@tanstack/react-router";
import {
parseProfilePanelView,
type ProfilePanelView,
} from "@/features/profile/ui/UserProfilePanelUtils";
import { usePreviewFeatureWarning } from "@/shared/features";
import { ViewLoadingFallback } from "@/shared/ui/ViewLoadingFallback";
@@ -11,9 +15,16 @@ const PulseScreen = React.lazy(async () => {
type PulseRouteSearch = {
profile?: string;
profileView?: "memories" | "channels";
profileView?: Exclude<ProfilePanelView, "summary">;
};
function profileViewValue(
value: unknown,
): Exclude<ProfilePanelView, "summary"> | undefined {
const view = parseProfilePanelView(value);
return view && view !== "summary" ? view : undefined;
}
function validatePulseSearch(
search: Record<string, unknown>,
): PulseRouteSearch {
@@ -22,10 +33,7 @@ function validatePulseSearch(
typeof search.profile === "string" && search.profile.length > 0
? search.profile
: undefined,
profileView:
search.profileView === "memories" || search.profileView === "channels"
? search.profileView
: undefined,
profileView: profileViewValue(search.profileView),
};
}

View File

@@ -1,6 +1,7 @@
import * as React from "react";
import type { ProfilePanelView } from "@/features/profile/ui/UserProfilePanel";
import { profilePanelViewFromSearch } from "@/features/profile/ui/UserProfilePanelUtils";
import {
type HistorySearchSetterOptions,
useHistorySearchState,
@@ -33,7 +34,7 @@ const CHANNEL_SEARCH_KEYS = [
] as const;
function asProfilePanelView(value: string | null): ProfilePanelView {
return value === "memories" || value === "channels" ? value : "summary";
return profilePanelViewFromSearch(value);
}
export function useChannelPanelHistoryState() {

View File

@@ -321,7 +321,7 @@ export function ProfileSummaryView({
<UserProfileAgentActions
isPending={isAgentActionPending}
managedAgent={managedAgent}
onDelete={persona ? handleDeletePersona : handleDeleteAgent}
onDelete={handleDeleteAgent}
onDuplicatePersona={handleDuplicatePersona}
onExportPersona={handleExportPersona}
personaActionKey={personaActionKey}

View File

@@ -1,7 +1,11 @@
import assert from "node:assert/strict";
import test from "node:test";
import { personaManagedAgentUpdate } from "./UserProfilePanelUtils.ts";
import {
parseProfilePanelView,
personaManagedAgentUpdate,
profilePanelViewFromSearch,
} from "./UserProfilePanelUtils.ts";
function agent(overrides = {}) {
return {
@@ -148,3 +152,25 @@ test("personaManagedAgentUpdate leaves runtime fields alone when runtime is unch
null,
);
});
test("parseProfilePanelView accepts all profile panel subviews", () => {
for (const view of [
"summary",
"info",
"settings",
"diagnostics",
"model",
"instructions",
"memories",
"channels",
"logs",
]) {
assert.equal(parseProfilePanelView(view), view);
}
});
test("profilePanelViewFromSearch falls back to summary for invalid values", () => {
assert.equal(parseProfilePanelView("missing"), null);
assert.equal(profilePanelViewFromSearch("missing"), "summary");
assert.equal(profilePanelViewFromSearch(null), "summary");
});

View File

@@ -38,6 +38,21 @@ export const PROFILE_PANEL_VIEW_TITLES: Record<ProfilePanelView, string> = {
logs: "Harness log",
};
const PROFILE_PANEL_VIEWS = new Set<ProfilePanelView>(
Object.keys(PROFILE_PANEL_VIEW_TITLES) as ProfilePanelView[],
);
export function parseProfilePanelView(value: unknown): ProfilePanelView | null {
return typeof value === "string" &&
PROFILE_PANEL_VIEWS.has(value as ProfilePanelView)
? (value as ProfilePanelView)
: null;
}
export function profilePanelViewFromSearch(value: unknown): ProfilePanelView {
return parseProfilePanelView(value) ?? "summary";
}
export type UserProfilePanelProps = {
canResetWidth?: boolean;
currentPubkey?: string;

View File

@@ -6,6 +6,7 @@ import {
type ProfilePanelView,
UserProfilePanel,
} from "@/features/profile/ui/UserProfilePanel";
import { profilePanelViewFromSearch } from "@/features/profile/ui/UserProfilePanelUtils";
import { PulseView } from "@/features/pulse/ui/PulseView";
import { useIdentityQuery } from "@/shared/api/hooks";
import { ProfilePanelProvider } from "@/shared/context/ProfilePanelContext";
@@ -18,10 +19,9 @@ export function PulseScreen() {
const identityQuery = useIdentityQuery();
const { applyPatch, values } = useHistorySearchState(PULSE_PANEL_SEARCH_KEYS);
const profilePanelPubkey = values.profile;
const profilePanelView: ProfilePanelView =
values.profileView === "memories" || values.profileView === "channels"
? values.profileView
: "summary";
const profilePanelView: ProfilePanelView = profilePanelViewFromSearch(
values.profileView,
);
const handleOpenProfilePanel = React.useCallback(
(pubkey: string) => applyPatch({ profile: pubkey, profileView: null }),
[applyPatch],