fix: remove manual sender selection in agent comms
This commit is contained in:
parent
008bba4afb
commit
bae278304b
|
|
@ -105,7 +105,6 @@ export function AgentCommsPanel() {
|
||||||
const [filter, setFilter] = useState<string>('all')
|
const [filter, setFilter] = useState<string>('all')
|
||||||
const [view, setView] = useState<'chat' | 'graph'>('chat')
|
const [view, setView] = useState<'chat' | 'graph'>('chat')
|
||||||
const [agentOptions, setAgentOptions] = useState<AgentOption[]>([])
|
const [agentOptions, setAgentOptions] = useState<AgentOption[]>([])
|
||||||
const [fromAgent, setFromAgent] = useState('')
|
|
||||||
const [toAgent, setToAgent] = useState('')
|
const [toAgent, setToAgent] = useState('')
|
||||||
const [draft, setDraft] = useState('')
|
const [draft, setDraft] = useState('')
|
||||||
const [sending, setSending] = useState(false)
|
const [sending, setSending] = useState(false)
|
||||||
|
|
@ -155,32 +154,28 @@ export function AgentCommsPanel() {
|
||||||
])).sort()
|
])).sort()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!fromAgent && allAgents.length > 0) {
|
if (!toAgent && allAgents.length > 0) {
|
||||||
setFromAgent(allAgents[0])
|
const firstTarget = allAgents.find((name) => name !== COORDINATOR_AGENT) || allAgents[0]
|
||||||
|
setToAgent(firstTarget)
|
||||||
}
|
}
|
||||||
if (!toAgent && allAgents.length > 1) {
|
}, [allAgents, toAgent])
|
||||||
setToAgent(allAgents[1])
|
|
||||||
}
|
|
||||||
}, [allAgents, fromAgent, toAgent])
|
|
||||||
|
|
||||||
async function sendComposedMessage() {
|
async function sendComposedMessage() {
|
||||||
const content = draft.trim()
|
const content = draft.trim()
|
||||||
if (!content || sending) return
|
if (!content || sending) return
|
||||||
|
|
||||||
const isCoordinator = composerMode === 'coordinator'
|
const isCoordinator = composerMode === 'coordinator'
|
||||||
const from = isCoordinator
|
const from = currentUser?.username || currentUser?.display_name || 'operator'
|
||||||
? (currentUser?.username || currentUser?.display_name || 'operator')
|
|
||||||
: fromAgent
|
|
||||||
const to = isCoordinator ? COORDINATOR_AGENT : toAgent
|
const to = isCoordinator ? COORDINATOR_AGENT : toAgent
|
||||||
|
|
||||||
if (!from || !to || (!isCoordinator && from === to)) return
|
if (!to) return
|
||||||
|
|
||||||
setSending(true)
|
setSending(true)
|
||||||
setSendError(null)
|
setSendError(null)
|
||||||
try {
|
try {
|
||||||
const conversation_id = isCoordinator
|
const conversation_id = isCoordinator
|
||||||
? `coord:${from}:${COORDINATOR_AGENT}`
|
? `coord:${from}:${COORDINATOR_AGENT}`
|
||||||
: `a2a:${from}:${to}`
|
: `user:${from}:${to}`
|
||||||
|
|
||||||
const res = await fetch('/api/chat/messages', {
|
const res = await fetch('/api/chat/messages', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
@ -362,23 +357,16 @@ export function AgentCommsPanel() {
|
||||||
|
|
||||||
{composerMode === 'agent' ? (
|
{composerMode === 'agent' ? (
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<span className="text-xs text-muted-foreground">Write as</span>
|
<span className="text-xs text-muted-foreground">
|
||||||
<select
|
You ({currentUser?.display_name || currentUser?.username || 'operator'}) →
|
||||||
value={fromAgent}
|
</span>
|
||||||
onChange={(e) => setFromAgent(e.target.value)}
|
|
||||||
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
|
||||||
>
|
|
||||||
<option value="">from...</option>
|
|
||||||
{allAgents.map(a => <option key={`from-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>)}
|
|
||||||
</select>
|
|
||||||
<span className="text-xs text-muted-foreground">to</span>
|
|
||||||
<select
|
<select
|
||||||
value={toAgent}
|
value={toAgent}
|
||||||
onChange={(e) => setToAgent(e.target.value)}
|
onChange={(e) => setToAgent(e.target.value)}
|
||||||
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
||||||
>
|
>
|
||||||
<option value="">to...</option>
|
<option value="">choose agent...</option>
|
||||||
{allAgents.filter(a => a !== fromAgent).map(a => (
|
{allAgents.filter(a => a !== COORDINATOR_AGENT).map(a => (
|
||||||
<option key={`to-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>
|
<option key={`to-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -410,7 +398,7 @@ export function AgentCommsPanel() {
|
||||||
disabled={
|
disabled={
|
||||||
sending ||
|
sending ||
|
||||||
!draft.trim() ||
|
!draft.trim() ||
|
||||||
(composerMode === 'agent' && (!fromAgent || !toAgent || fromAgent === toAgent))
|
(composerMode === 'agent' && !toAgent)
|
||||||
}
|
}
|
||||||
className="h-9 px-3 rounded-md bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed"
|
className="h-9 px-3 rounded-md bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue