"use client"; import { useEffect, useId, useState } from "react"; import { useTranslation } from "react-i18next"; import { FolderOpen } from "lucide-react"; import { getPartnerWorkspaces } from "@/lib/partners-api"; import { listWorkspaces, workspaceLabel, type ChatWorkspaceRegistration, } from "@/lib/workspaces-api"; export default function PartnerWorkspacePicker({ value, onChange, disabled = false, partnerId, }: { value: string; onChange: (id: string, label: string) => void; disabled?: boolean; partnerId?: string; }) { const { t, i18n } = useTranslation(); const id = useId(); const [rows, setRows] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [attempt, setAttempt] = useState(0); const zh = i18n.language.startsWith("zh"); useEffect(() => { let active = true; void (partnerId ? getPartnerWorkspaces(partnerId) : listWorkspaces(true)) .then((result) => { if (active) { setError(""); setRows( result.filter( (row) => row.kind !== "system" && !row.archived && row.status === "ready", ), ); } }) .catch((e) => { if (active) setError( e instanceof Error ? e.message : t("Failed to load workspaces"), ); }) .finally(() => { if (active) setLoading(false); }); return () => { active = false; }; }, [attempt, partnerId, t]); return (

{value ? t( "This partner shares the workspace's files, knowledge bases, skills, and notebooks. Changes stay in sync; generated files go to its outputs folder.", ) : t( "Use a private workspace, or bind an existing workspace to share its latest resources.", )}

{error && (

{error}{" "}

)}
); }