Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This changelog covers all five packages, as they are (for now) updated as a whol

## UNRELEASED

- Agents, Skills and MCP servers are edited in a dialog again. Their lists stay
on the AI settings page, but creating or editing one opens a dialog with the
form and Cancel / Save buttons, instead of swapping the list for the form
inside the settings section. Save stays disabled until the required fields
are filled in.

- Pasting an agent secret that opens a different agent than the signed-in
account no longer signs that account out on its own. The app now says which
account is signed in, shows both agents, and lets the user stay signed in or
Expand Down
76 changes: 24 additions & 52 deletions browser/data-browser/src/chunks/AI/AIConfigurationSections.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,40 @@
import { useState, type ReactNode } from 'react';
import { SettingsSection } from '@components/Settings';
import { Column } from '@components/Row';
import { AgentConfigTab, useAIAgentConfig } from './AgentConfig';
import { SkillsConfigTab } from './SkillsConfigTab';
import { MCPConfigTab } from './MCPConfigTab';

interface EditorProps {
actionPortalElement: HTMLElement | null;
onActionsVisibleChange: (visible: boolean) => void;
}

function EditorSection({
label,
children,
keywords,
}: {
label: string;
keywords?: string;
children: (props: EditorProps) => ReactNode;
}) {
const [actions, setActions] = useState<HTMLDivElement | null>(null);
const [editing, setEditing] = useState(false);

return (
<SettingsSection label={label} childSearchKeywords={keywords}>
<Column>
{children({
actionPortalElement: actions,
onActionsVisibleChange: setEditing,
})}
<div ref={setActions} hidden={!editing} />
</Column>
</SettingsSection>
);
}

export default function AIConfigurationSections() {
const { agents, defaultAgentId, setDefaultAgentId } = useAIAgentConfig();

return (
<Column gap='0'>
<EditorSection
<SettingsSection
label='Agents'
keywords='agent default system prompt temperature context tools model'
childSearchKeywords='agent default system prompt temperature context tools model'
>
<Column>
<p>Choose the default agent for new chats.</p>
<AgentConfigTab
selectedAgent={
agents.find(agent => agent.id === defaultAgentId) ?? agents[0]
}
onSelectAgent={agent => setDefaultAgentId(agent.id)}
/>
</Column>
</SettingsSection>
<SettingsSection
label='Skills'
childSearchKeywords='skills content references'
>
<SkillsConfigTab />
</SettingsSection>
<SettingsSection
label='MCP'
childSearchKeywords='mcp server url transport headers'
>
{props => (
<Column>
<p>Choose the default agent for new chats.</p>
<AgentConfigTab
{...props}
selectedAgent={
agents.find(agent => agent.id === defaultAgentId) ?? agents[0]
}
onSelectAgent={agent => setDefaultAgentId(agent.id)}
/>
</Column>
)}
</EditorSection>
<EditorSection label='Skills' keywords='skills content references'>
{props => <SkillsConfigTab {...props} />}
</EditorSection>
<EditorSection label='MCP' keywords='mcp server url transport headers'>
{props => <MCPConfigTab {...props} />}
</EditorSection>
<MCPConfigTab />
</SettingsSection>
</Column>
);
}
92 changes: 34 additions & 58 deletions browser/data-browser/src/chunks/AI/AgentConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import { styled } from 'styled-components';
import { Column } from '@components/Row';
import { FaPlus } from 'react-icons/fa6';
import { ModelSelect } from './ModelSelect/ModelSelect';
import { type AIAgent, type AIModelIdentifier } from './types';
import { useLocalStorage } from '@hooks/useLocalStorage';
import { Button } from '@components/Button';
import { SkeletonButton } from '@components/SkeletonButton';
import { MarkdownInput } from '@components/forms/MarkdownInput';
import { Checkbox, CheckboxLabel } from '@components/forms/Checkbox';
import { Input } from '@components/forms/InputStyles';
import { SliderInput } from '@components/forms/SliderInput';
import { useAISettings } from '@components/AI/AISettingsContext';
import { AgentConfigItem } from './AgentConfigItem';
import { ConfigEditorDialog } from './ConfigEditorDialog';
import atomicAgentPrompt from './system-prompts/atomic-agent.md?raw';
import Field from '@components/forms/Field';
import Markdown from '@components/datatypes/Markdown';
Expand All @@ -34,8 +33,6 @@ const generateId = () => {
interface AgentConfigTabProps {
selectedAgent: AIAgent;
onSelectAgent: (agent: AIAgent) => void;
actionPortalElement: HTMLElement | null;
onActionsVisibleChange: (visible: boolean) => void;
}

const defaultNewAgent: Omit<AIAgent, 'id'> = {
Expand Down Expand Up @@ -157,18 +154,12 @@ export const useAIAgentConfig = () => {
export const AgentConfigTab = ({
selectedAgent,
onSelectAgent,
actionPortalElement,
onActionsVisibleChange,
}: AgentConfigTabProps) => {
const { agents, saveAgents } = useAIAgentConfig();
const { defaultChatModel } = useAISettings();
const [editingAgent, setEditingAgent] = useState<AIAgent | null>(null);
const [isCreating, setIsCreating] = useState(false);

useEffect(() => {
return () => onActionsVisibleChange(false);
}, [onActionsVisibleChange]);

const handleSaveAgent = () => {
if (!editingAgent) return;

Expand All @@ -186,10 +177,6 @@ export const AgentConfigTab = ({
if (selectedAgent.id === savedAgent.id || isCreating) {
onSelectAgent(savedAgent);
}

setEditingAgent(null);
setIsCreating(false);
onActionsVisibleChange(false);
};

const handleDeleteAgent = (agentToDelete: AIAgent) => {
Expand Down Expand Up @@ -229,68 +216,57 @@ export const AgentConfigTab = ({
model: defaultChatModel,
});
setIsCreating(true);
onActionsVisibleChange(true);
};

const handleEditAgent = (agent: AIAgent) => {
setEditingAgent({ ...agent });
setIsCreating(false);
onActionsVisibleChange(true);
};

const handleCancel = () => {
const handleDialogClosed = () => {
setEditingAgent(null);
setIsCreating(false);
onActionsVisibleChange(false);
};

return (
<>
{editingAgent ? (
<Column>
<Column>
<AgentsList role='radiogroup' aria-label='AI Agents'>
{agents.map((agent: AIAgent) => (
<AgentConfigItem
key={agent.id}
agent={agent}
selected={selectedAgent.id === agent.id}
onSelect={onSelectAgent}
onEdit={handleEditAgent}
onDelete={handleDeleteAgent}
onDuplicate={handleDuplicateAgent}
canDelete={!getDefaultAgent(agent.id)}
/>
))}
</AgentsList>

<CreateButton onClick={handleCreateNewAgent}>
<FaPlus title='' />
<span>Create New Agent</span>
</CreateButton>

<ConfigEditorDialog
open={!!editingAgent}
title={isCreating ? 'New Agent' : 'Edit Agent'}
saveLabel={isCreating ? 'Create Agent' : 'Save Changes'}
canSave={!!editingAgent?.name.trim()}
onSave={handleSaveAgent}
onClosed={handleDialogClosed}
>
{editingAgent && (
<AgentForm
agent={editingAgent}
isDefaultAgent={!!getDefaultAgent(editingAgent.id)}
onChange={setEditingAgent}
/>
</Column>
) : (
<Column>
<AgentsList role='radiogroup' aria-label='AI Agents'>
{agents.map((agent: AIAgent) => (
<AgentConfigItem
key={agent.id}
agent={agent}
selected={selectedAgent.id === agent.id}
onSelect={onSelectAgent}
onEdit={handleEditAgent}
onDelete={handleDeleteAgent}
onDuplicate={handleDuplicateAgent}
canDelete={!getDefaultAgent(agent.id)}
/>
))}
</AgentsList>

<CreateButton onClick={handleCreateNewAgent}>
<FaPlus title='' />
<span>Create New Agent</span>
</CreateButton>
</Column>
)}
{editingAgent &&
actionPortalElement &&
createPortal(
<>
<Button subtle onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleSaveAgent}>
{isCreating ? 'Create Agent' : 'Save Changes'}
</Button>
</>,
actionPortalElement,
)}
</>
</ConfigEditorDialog>
</Column>
);
};

Expand Down
77 changes: 77 additions & 0 deletions browser/data-browser/src/chunks/AI/ConfigEditorDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { useEffect, type ReactNode } from 'react';
import {
Dialog,
DialogActions,
DialogContent,
DialogTitle,
useDialog,
} from '@components/Dialog';
import { Button } from '@components/Button';

interface ConfigEditorDialogProps {
/** Opens the dialog when true. Stays true until `onClosed` runs. */
open: boolean;
title: string;
saveLabel: string;
canSave: boolean;
/** Persists the edited item. The dialog closes afterwards. */
onSave: () => void;
/** Runs once the dialog has fully closed, after a save or a cancel. */
onClosed: () => void;
children: ReactNode;
}

/**
* Dialog used to create or edit an agent, skill or MCP server from the AI
* settings. The list stays on the settings page; the form lives in here.
*/
export function ConfigEditorDialog({
open,
title,
saveLabel,
canSave,
onSave,
onClosed,
children,
}: ConfigEditorDialogProps) {
const [dialogProps, showDialog, hideDialog, dialogVisible] = useDialog({
onCancel: onClosed,
onSuccess: onClosed,
});

useEffect(() => {
if (open) {
showDialog();
} else {
hideDialog();
}
}, [open, showDialog, hideDialog]);

const handleSave = () => {
if (!canSave) return;

onSave();
hideDialog(true);
};

return (
<Dialog {...dialogProps} width='70ch'>
{dialogVisible && (
<>
<DialogTitle>
<h1>{title}</h1>
</DialogTitle>
<DialogContent>{children}</DialogContent>
<DialogActions>
<Button subtle onClick={() => hideDialog(false)}>
Cancel
</Button>
<Button onClick={handleSave} disabled={!canSave}>
{saveLabel}
</Button>
</DialogActions>
</>
)}
</Dialog>
);
}
Loading