"use client"; import { useEffect, useState } from "react"; import { Clock3, FolderTree } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { useI18n } from "@/i18n/i18n-context"; import { normalizeExactFileMemoryScope } from "@/lib/file-scope-history"; import type { FileMemoryScope } from "@/types/file-memory"; const SCOPE_FIELDS = [ { key: "appId", label: "app", placeholder: "appPlaceholder" }, { key: "tenantId", label: "tenant", placeholder: "tenantPlaceholder" }, { key: "agentId", label: "agent", placeholder: "agentPlaceholder" }, { key: "runId", label: "run", placeholder: "runPlaceholder" }, ] as const; function editableScope(scope: Partial): FileMemoryScope { const visible = (value: string | undefined) => value && value !== "*" ? value : ""; return { appId: visible(scope.appId), tenantId: visible(scope.tenantId), agentId: visible(scope.agentId), runId: visible(scope.runId), }; } export function FileScopeOnboarding({ initialScope, recentScopes, onApply, }: { initialScope: Partial; recentScopes: FileMemoryScope[]; onApply: (scope: FileMemoryScope) => void; }) { const { t } = useI18n(); const [draft, setDraft] = useState(() => editableScope(initialScope)); const [error, setError] = useState(null); const { appId, tenantId, agentId, runId } = initialScope; useEffect(() => { setDraft(editableScope({ appId, tenantId, agentId, runId })); setError(null); }, [agentId, appId, runId, tenantId]); function submit(event: React.FormEvent) { event.preventDefault(); const scope = normalizeExactFileMemoryScope(draft); if (!scope) { setError(t("memory.files.scopeAllRequired")); return; } setError(null); onApply(scope); } return (

{t("memory.files.scopeOnboardingTitle")}

{t("memory.files.scopeOnboardingDescription")}

{recentScopes.length > 0 ? (
{t("memory.files.recentScopes")}
{recentScopes.map((scope) => { const label = [ scope.appId, scope.tenantId, scope.agentId, scope.runId, ].join(" / "); return ( ); })}

{t("memory.files.recentScopesLocalHint")}

) : null}
{SCOPE_FIELDS.map(({ key, label, placeholder }) => (
{ setDraft((previous) => ({ ...previous, [key]: event.target.value, })); setError(null); }} />
))}
{error ? ( {error} ) : ( t("memory.files.scopeIsolationHint") )}
); }