'use client';
import { Metadata } from "next";
import { Spinner, Textarea, Button, Dropdown, DropdownMenu, DropdownItem, DropdownTrigger, Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Input, useDisclosure, Divider } from "@nextui-org/react";
import { ReactNode, useEffect, useState, useCallback } from "react";
import { getProjectConfig, updateProjectName, updateWebhookUrl, createApiKey, deleteApiKey, listApiKeys, deleteProject, rotateSecret } from "@/app/actions/project_actions";
import { CopyButton } from "@/app/lib/components/copy-button";
import { EditableField } from "@/app/lib/components/editable-field";
import { EyeIcon, EyeOffIcon, CopyIcon, MoreVerticalIcon, PlusIcon, EllipsisVerticalIcon } from "lucide-react";
import { WithStringId, ApiKey } from "@/app/lib/types";
import { z } from "zod";
import { RelativeTime } from "@primer/react";
import { Label } from "@/app/lib/components/label";
export const metadata: Metadata = {
title: "Project config",
};
export function Section({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) {
return
{title}
{children}
;
}
export function SectionRow({
children,
}: {
children: ReactNode;
}) {
return {children}
;
}
export function LeftLabel({
label,
}: {
label: string;
}) {
return ;
}
export function RightContent({
children,
}: {
children: React.ReactNode;
}) {
return {children}
;
}
export function BasicSettingsSection({
projectId,
}: {
projectId: string;
}) {
const [loading, setLoading] = useState(false);
const [projectName, setProjectName] = useState(null);
useEffect(() => {
setLoading(true);
getProjectConfig(projectId).then((project) => {
setProjectName(project?.name);
setLoading(false);
});
}, [projectId]);
async function updateName(name: string) {
setLoading(true);
await updateProjectName(projectId, name);
setProjectName(name);
setLoading(false);
}
return
{loading && }
{!loading && }
{projectId}
{
navigator.clipboard.writeText(projectId);
}}
label="Copy"
successLabel="Copied"
/>
;
}
function ApiKeyDisplay({ apiKey }: { apiKey: string }) {
const [isVisible, setIsVisible] = useState(false);
const formattedKey = isVisible ? apiKey : `${apiKey.slice(0, 2)}${'•'.repeat(5)}${apiKey.slice(-2)}`;
return (
{formattedKey}
{
navigator.clipboard.writeText(apiKey);
}}
label="Copy"
successLabel="Copied"
/>
);
}
export function ApiKeysSection({
projectId,
}: {
projectId: string;
}) {
const [keys, setKeys] = useState>[]>([]);
const [loading, setLoading] = useState(true);
const [message, setMessage] = useState<{
type: 'success' | 'error' | 'info';
text: string;
} | null>(null);
useEffect(() => {
const loadKeys = async () => {
const keys = await listApiKeys(projectId);
setKeys(keys);
setLoading(false);
};
loadKeys();
}, [projectId]);
const handleCreateKey = async () => {
setLoading(true);
setMessage(null);
try {
const key = await createApiKey(projectId);
setLoading(false);
setMessage({
type: 'success',
text: 'API key created successfully',
});
setKeys([...keys, key]);
setTimeout(() => {
setMessage(null);
}, 2000);
} catch (error) {
setLoading(false);
setMessage({
type: 'error',
text: error instanceof Error ? error.message : "Failed to create API key",
});
}
};
const handleDeleteKey = async (id: string) => {
if (!window.confirm("Are you sure you want to delete this API key? This action cannot be undone.")) {
return;
}
try {
setLoading(true);
setMessage(null);
await deleteApiKey(projectId, id);
setKeys(keys.filter((k) => k._id !== id));
setLoading(false);
setMessage({
type: 'info',
text: 'API key deleted successfully',
});
setTimeout(() => {
setMessage(null);
}, 2000);
} catch (error) {
setLoading(false);
setMessage({
type: 'error',
text: error instanceof Error ? error.message : "Failed to delete API key",
});
}
};
return
API keys are used to authenticate requests to the Rowboat API.
}
variant="flat"
isDisabled={loading}
>
Create API key
{loading &&
}
{!loading &&
API Key
Created
Last Used
{message?.type === 'success' &&
}
{message?.type === 'error' &&
}
{message?.type === 'info' &&
}
{keys.map((key) => (
{key.lastUsedAt ? : 'Never'}
handleDeleteKey(key._id)}
>
Delete
))}
{keys.length === 0 && (
No API keys created yet
)}
}
;
}
export function SecretSection({
projectId,
}: {
projectId: string;
}) {
const [loading, setLoading] = useState(false);
const [hidden, setHidden] = useState(true);
const [secret, setSecret] = useState(null);
const formattedSecret = hidden ? `${secret?.slice(0, 2)}${'•'.repeat(5)}${secret?.slice(-2)}` : secret;
useEffect(() => {
setLoading(true);
getProjectConfig(projectId).then((project) => {
setSecret(project.secret);
setLoading(false);
});
}, [projectId]);
const handleRotateSecret = async () => {
if (!confirm("Are you sure you want to rotate the secret? All existing signatures will become invalid.")) {
return;
}
setLoading(true);
try {
const newSecret = await rotateSecret(projectId);
setSecret(newSecret);
} catch (error) {
console.error('Failed to rotate secret:', error);
} finally {
setLoading(false);
}
};
return
The project secret is used for signing tool-call requests sent to your webhook
{loading &&
}
{!loading && secret &&
{formattedSecret}
{
navigator.clipboard.writeText(secret);
}}
label="Copy"
successLabel="Copied"
/>
}
;
}
export function WebhookUrlSection({
projectId,
}: {
projectId: string;
}) {
const [loading, setLoading] = useState(false);
const [webhookUrl, setWebhookUrl] = useState(null);
useEffect(() => {
setLoading(true);
getProjectConfig(projectId).then((project) => {
setWebhookUrl(project.webhookUrl || null);
setLoading(false);
});
}, [projectId]);
async function update(url: string) {
setLoading(true);
await updateWebhookUrl(projectId, url);
setWebhookUrl(url);
setLoading(false);
}
function validate(url: string) {
try {
new URL(url);
return { valid: true };
} catch {
return { valid: false, errorMessage: 'Please enter a valid URL' };
}
}
return
In workflow editor, tool calls will be posted to this URL, unless they are mocked.
{loading && }
{!loading && }
;
}
export function ChatWidgetSection({
projectId,
}: {
projectId: string;
}) {
const [loading, setLoading] = useState(false);
const [chatClientId, setChatClientId] = useState(null);
useEffect(() => {
setLoading(true);
getProjectConfig(projectId).then((project) => {
setChatClientId(project.chatClientId);
setLoading(false);
});
}, [projectId]);
const code = `
`;
return
To use the chat widget, copy and paste this code snippet just before the closing </body> tag of your website:
{loading && }
{!loading && ;
}
export function DeleteProjectSection({
projectId,
}: {
projectId: string;
}) {
const [loading, setLoading] = useState(false);
const { isOpen, onOpen, onClose } = useDisclosure();
const [projectName, setProjectName] = useState("");
const [projectNameInput, setProjectNameInput] = useState("");
const [confirmationInput, setConfirmationInput] = useState("");
const isValid = projectNameInput === projectName && confirmationInput === "delete project";
useEffect(() => {
setLoading(true);
getProjectConfig(projectId).then((project) => {
setProjectName(project.name);
setLoading(false);
});
}, [projectId]);
const handleDelete = async () => {
if (!isValid) return;
setLoading(true);
await deleteProject(projectId);
setLoading(false);
};
return (
{loading && }
{!loading &&
Deleting a project will permanently remove all associated data, including workflows, sources, and API keys.
This action cannot be undone.
Delete Project
}
);
}
export default function App({
projectId,
}: {
projectId: string;
}) {
return ;
}