Spaces:
Runtime error
Runtime error
Nyk commited on
Commit ·
ff5a7aa
1
Parent(s): 03a699e
fix: remove manual sender selection in agent comms
Browse files
src/components/panels/agent-comms-panel.tsx
CHANGED
|
@@ -105,7 +105,6 @@ export function AgentCommsPanel() {
|
|
| 105 |
const [filter, setFilter] = useState<string>('all')
|
| 106 |
const [view, setView] = useState<'chat' | 'graph'>('chat')
|
| 107 |
const [agentOptions, setAgentOptions] = useState<AgentOption[]>([])
|
| 108 |
-
const [fromAgent, setFromAgent] = useState('')
|
| 109 |
const [toAgent, setToAgent] = useState('')
|
| 110 |
const [draft, setDraft] = useState('')
|
| 111 |
const [sending, setSending] = useState(false)
|
|
@@ -155,32 +154,28 @@ export function AgentCommsPanel() {
|
|
| 155 |
])).sort()
|
| 156 |
|
| 157 |
useEffect(() => {
|
| 158 |
-
if (!
|
| 159 |
-
|
|
|
|
| 160 |
}
|
| 161 |
-
|
| 162 |
-
setToAgent(allAgents[1])
|
| 163 |
-
}
|
| 164 |
-
}, [allAgents, fromAgent, toAgent])
|
| 165 |
|
| 166 |
async function sendComposedMessage() {
|
| 167 |
const content = draft.trim()
|
| 168 |
if (!content || sending) return
|
| 169 |
|
| 170 |
const isCoordinator = composerMode === 'coordinator'
|
| 171 |
-
const from =
|
| 172 |
-
? (currentUser?.username || currentUser?.display_name || 'operator')
|
| 173 |
-
: fromAgent
|
| 174 |
const to = isCoordinator ? COORDINATOR_AGENT : toAgent
|
| 175 |
|
| 176 |
-
if (!
|
| 177 |
|
| 178 |
setSending(true)
|
| 179 |
setSendError(null)
|
| 180 |
try {
|
| 181 |
const conversation_id = isCoordinator
|
| 182 |
? `coord:${from}:${COORDINATOR_AGENT}`
|
| 183 |
-
: `
|
| 184 |
|
| 185 |
const res = await fetch('/api/chat/messages', {
|
| 186 |
method: 'POST',
|
|
@@ -362,23 +357,16 @@ export function AgentCommsPanel() {
|
|
| 362 |
|
| 363 |
{composerMode === 'agent' ? (
|
| 364 |
<div className="flex items-center gap-2 mb-2">
|
| 365 |
-
<span className="text-xs text-muted-foreground">
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
onChange={(e) => setFromAgent(e.target.value)}
|
| 369 |
-
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
| 370 |
-
>
|
| 371 |
-
<option value="">from...</option>
|
| 372 |
-
{allAgents.map(a => <option key={`from-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>)}
|
| 373 |
-
</select>
|
| 374 |
-
<span className="text-xs text-muted-foreground">to</span>
|
| 375 |
<select
|
| 376 |
value={toAgent}
|
| 377 |
onChange={(e) => setToAgent(e.target.value)}
|
| 378 |
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
| 379 |
>
|
| 380 |
-
<option value="">
|
| 381 |
-
{allAgents.filter(a => a !==
|
| 382 |
<option key={`to-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>
|
| 383 |
))}
|
| 384 |
</select>
|
|
@@ -410,7 +398,7 @@ export function AgentCommsPanel() {
|
|
| 410 |
disabled={
|
| 411 |
sending ||
|
| 412 |
!draft.trim() ||
|
| 413 |
-
(composerMode === 'agent' &&
|
| 414 |
}
|
| 415 |
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"
|
| 416 |
>
|
|
|
|
| 105 |
const [filter, setFilter] = useState<string>('all')
|
| 106 |
const [view, setView] = useState<'chat' | 'graph'>('chat')
|
| 107 |
const [agentOptions, setAgentOptions] = useState<AgentOption[]>([])
|
|
|
|
| 108 |
const [toAgent, setToAgent] = useState('')
|
| 109 |
const [draft, setDraft] = useState('')
|
| 110 |
const [sending, setSending] = useState(false)
|
|
|
|
| 154 |
])).sort()
|
| 155 |
|
| 156 |
useEffect(() => {
|
| 157 |
+
if (!toAgent && allAgents.length > 0) {
|
| 158 |
+
const firstTarget = allAgents.find((name) => name !== COORDINATOR_AGENT) || allAgents[0]
|
| 159 |
+
setToAgent(firstTarget)
|
| 160 |
}
|
| 161 |
+
}, [allAgents, toAgent])
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
async function sendComposedMessage() {
|
| 164 |
const content = draft.trim()
|
| 165 |
if (!content || sending) return
|
| 166 |
|
| 167 |
const isCoordinator = composerMode === 'coordinator'
|
| 168 |
+
const from = currentUser?.username || currentUser?.display_name || 'operator'
|
|
|
|
|
|
|
| 169 |
const to = isCoordinator ? COORDINATOR_AGENT : toAgent
|
| 170 |
|
| 171 |
+
if (!to) return
|
| 172 |
|
| 173 |
setSending(true)
|
| 174 |
setSendError(null)
|
| 175 |
try {
|
| 176 |
const conversation_id = isCoordinator
|
| 177 |
? `coord:${from}:${COORDINATOR_AGENT}`
|
| 178 |
+
: `user:${from}:${to}`
|
| 179 |
|
| 180 |
const res = await fetch('/api/chat/messages', {
|
| 181 |
method: 'POST',
|
|
|
|
| 357 |
|
| 358 |
{composerMode === 'agent' ? (
|
| 359 |
<div className="flex items-center gap-2 mb-2">
|
| 360 |
+
<span className="text-xs text-muted-foreground">
|
| 361 |
+
You ({currentUser?.display_name || currentUser?.username || 'operator'}) →
|
| 362 |
+
</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
<select
|
| 364 |
value={toAgent}
|
| 365 |
onChange={(e) => setToAgent(e.target.value)}
|
| 366 |
className="bg-card border border-border/50 rounded-md px-2 py-1 text-xs text-foreground"
|
| 367 |
>
|
| 368 |
+
<option value="">choose agent...</option>
|
| 369 |
+
{allAgents.filter(a => a !== COORDINATOR_AGENT).map(a => (
|
| 370 |
<option key={`to-${a}`} value={a}>{getIdentity(a).emoji} {getIdentity(a).label}</option>
|
| 371 |
))}
|
| 372 |
</select>
|
|
|
|
| 398 |
disabled={
|
| 399 |
sending ||
|
| 400 |
!draft.trim() ||
|
| 401 |
+
(composerMode === 'agent' && !toAgent)
|
| 402 |
}
|
| 403 |
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"
|
| 404 |
>
|