@elevenlabs/convai-cli
Version:
CLI tool to manage ElevenLabs conversational AI agents
82 lines • 4.2 kB
JavaScript
import React, { useState } from 'react';
import { Box, Text, useApp } from 'ink';
import SelectInput from 'ink-select-input';
import App from '../App.js';
import StatusCard from '../components/StatusCard.js';
import theme from '../themes/elevenlabs.js';
import { setResidency, getResidency, LOCATIONS } from '../../config.js';
export const ResidencyView = ({ initialResidency, onComplete }) => {
const { exit } = useApp();
const [currentResidency, setCurrentResidency] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
const [success, setSuccess] = useState(false);
const [error, setError] = useState(null);
React.useEffect(() => {
const loadCurrentResidency = async () => {
try {
const residency = await getResidency();
setCurrentResidency(residency);
setIsLoading(false);
}
catch (err) {
setError('Failed to load current residency');
setIsLoading(false);
}
};
if (!initialResidency) {
loadCurrentResidency();
}
else {
setIsLoading(false);
handleResidencySelect({ value: initialResidency });
}
}, [initialResidency]);
const handleResidencySelect = async (item) => {
setIsSaving(true);
setError(null);
try {
await setResidency(item.value);
setCurrentResidency(item.value);
setSuccess(true);
setTimeout(() => {
if (onComplete) {
onComplete();
}
else {
exit();
}
}, 1500);
}
catch (err) {
setError(err instanceof Error ? err.message : 'Failed to set residency');
setIsSaving(false);
}
};
const locationItems = LOCATIONS.map(location => ({
label: location.charAt(0).toUpperCase() + location.slice(1),
value: location
}));
return (React.createElement(App, { title: "ElevenLabs Conversational AI", subtitle: "API Residency Configuration", showOverlay: !success },
React.createElement(Box, { flexDirection: "column", gap: 1 }, isLoading ? (React.createElement(StatusCard, { title: "Loading", status: "loading", message: "Fetching current residency..." })) : success ? (React.createElement(React.Fragment, null,
React.createElement(StatusCard, { title: "Residency Updated", status: "success", message: `API residency set to: ${currentResidency}` }),
React.createElement(Box, { marginTop: 1 },
React.createElement(Text, { color: theme.colors.text.secondary },
"Your API calls will now be routed through the ",
currentResidency,
" region")))) : isSaving ? (React.createElement(StatusCard, { title: "Updating Residency", status: "loading", message: "Saving your selection..." })) : (React.createElement(React.Fragment, null,
currentResidency && (React.createElement(Box, { marginBottom: 1 },
React.createElement(StatusCard, { title: "Current Residency", status: "idle", message: currentResidency || 'Not set (using default)' }))),
React.createElement(Box, { flexDirection: "column", gap: 1 },
React.createElement(Text, { color: theme.colors.text.primary, bold: true }, "Select API Residency Location:"),
React.createElement(Box, { marginTop: 1 },
React.createElement(SelectInput, { items: locationItems, onSelect: handleResidencySelect })),
React.createElement(Box, { marginTop: 1 },
React.createElement(Text, { color: theme.colors.text.muted }, "Choose the region closest to you for optimal performance"))),
error && (React.createElement(Box, { marginTop: 1 },
React.createElement(Text, { color: theme.colors.error },
"\u2717 ",
error))))))));
};
export default ResidencyView;
//# sourceMappingURL=ResidencyView.js.map