"use client" import * as React from 'react' import { Input } from '@open-mercato/ui/primitives/input' import { Textarea } from '@open-mercato/ui/primitives/textarea' import { RadioGroup, Radio } from '@open-mercato/ui/primitives/radio' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@open-mercato/ui/primitives/select' import { apiCall } from '@open-mercato/ui/backend/utils/apiCall' import { useT } from '@open-mercato/shared/lib/i18n/context' import { mapAgent, type AgentView } from './types' type AgentsResponse = { items?: Array> } /** * The `onResult` config frozen by area 02. Either auto-approve above a * confidence threshold, or always route to a human. */ export type InvokeAgentOnResult = | { autoApproveThreshold: number } | { alwaysAsk: true } export type InvokeAgentNodeConfigValue = { agentId: string input: string onResult: InvokeAgentOnResult } export type InvokeAgentNodeConfigProps = { value: InvokeAgentNodeConfigValue onChange: (value: InvokeAgentNodeConfigValue) => void } /** * Controlled 3-field config panel for an `INVOKE_AGENT` node. Stateless about * persistence — area 02's visual editor owns reading/writing the node config. * Brand-violet header + focus rings flag this as an AI step (ds-rules: brand * violet only on AI touchpoints). */ export function InvokeAgentNodeConfig({ value, onChange }: InvokeAgentNodeConfigProps) { const t = useT() const [agents, setAgents] = React.useState([]) React.useEffect(() => { let cancelled = false async function load() { const call = await apiCall('/api/agent_orchestrator/agents', undefined, { fallback: { items: [] }, }) if (cancelled || !call.ok) return const items = Array.isArray(call.result?.items) ? call.result!.items : [] setAgents( items .map((item) => mapAgent(item as Record)) .filter((agent): agent is AgentView => !!agent), ) } load() return () => { cancelled = true } }, []) const mode: 'auto' | 'ask' = 'autoApproveThreshold' in value.onResult ? 'auto' : 'ask' const threshold = 'autoApproveThreshold' in value.onResult ? value.onResult.autoApproveThreshold : 0.8 const setMode = (next: 'auto' | 'ask') => { if (next === 'auto') { onChange({ ...value, onResult: { autoApproveThreshold: threshold } }) } else { onChange({ ...value, onResult: { alwaysAsk: true } }) } } return (
{t('agent_orchestrator.proposal.proposes', undefined, { agent: 'Invoke Agent' })}