// --------------------------------------------------------------------------- // customer-grid / FieldAgentChat.tsx — owner item 10's chat (W36-T07, R6, R11). // // ⛔ NOTHING IS CREATED UNTIL THE USER ACCEPTS, and that is the ticket's own `done-when`. The // proposal is a PROPOSAL: it sits on screen with its reasoning, the user may correct it in // another turn, and only the acceptance button reaches `onAccept`. A chat that created a column on // the first sentence would be faster and would be the wrong product — the owner asked for this // precisely so they *"can further align request"* first. // // ⚠ ITS OWN MODULE because `ColumnMenu.tsx` is 180k and pulls the whole // grid, so node probes emit this surface and inject its history transport. // ⚠ The composer wears the `cg-agent-*` classes W36-T05 already introduced. That is deliberate // reuse of ONE shape (bordered card, foot row inside the border, circular send) rather than a // second chat look — the same parity D-16 measured between the Assistant and the agent chat. // --------------------------------------------------------------------------- import { useMemo, useState } from "react"; import { logExchange } from "../assistant/dockClient"; import { proposalReady, proposeField } from "./fieldAgent"; import type { AgentKind, FieldAgentTarget, FieldProposal } from "./fieldAgent"; import type { Field } from "./types"; /** Plain words for the kinds this agent proposes, so the card never shows an internal key. */ const KIND_WORDS: Partial> = { text: "Free text", currency: "Money", pct: "Percentage", int: "Whole number", date: "Date", checkbox: "Yes or no", rating: "Rating", email: "Email", phone: "Phone", url: "Web address", link: "Link to another record", select: "One choice from a list", multiselect: "Several choices from a list", user: "Person", measure: "Metric", }; export function kindWord(kind: AgentKind): string { return KIND_WORDS[kind] ?? String(kind); } export function fieldProposalSummary(proposal: FieldProposal): string { const label = proposal.label.replace(/\s+/g, " "); const target = proposal.linkTarget?.label.replace(/\s+/g, " "); return proposal.existingField ? `Use existing field: "${label}" (${kindWord(proposal.kind)}).` : `Proposed column: "${label}" (${kindWord(proposal.kind)})${target ? `, linked to "${target}"` : ""}.`; } export function FieldAgentChat({ existing = [], linkTargets = [], database, onAccept, onCancel, }: { existing?: readonly Field[]; linkTargets?: readonly FieldAgentTarget[]; database?: string; onAccept: (proposal: FieldProposal) => void; onCancel: () => void; }) { const [turns, setTurns] = useState([]); const [draft, setDraft] = useState(""); const proposal = useMemo(() => (turns.length ? proposeField(turns, existing, linkTargets) : null), [turns, existing, linkTargets]); const ready = proposal !== null && proposalReady(proposal); const send = () => { const said = draft.trim(); if (!said) return; const next = proposeField([...turns, said], existing, linkTargets); setTurns((t) => [...t, said]); setDraft(""); // History failure must leave the proposal available for review and acceptance. try { void logExchange({ question: said, answer: [...next.why, ...next.missing, fieldProposalSummary(next)].join("\n"), context: { surface: "field", ...(database ? { database } : {}) }, }).catch(() => {}); } catch { /* A synchronous transport failure is best effort too. */ } }; return (
{turns.length === 0 ? (
) : (
    {turns.map((turn, i) => (
  1. {turn}
  2. ))}
)} {proposal !== null && (

{proposal.existingField ? "Existing field" : "Proposed column"}

Name
{proposal.label}
Kind
{kindWord(proposal.kind)}
{proposal.linkTarget ?
Database
: null} {proposal.linkTarget ?
{proposal.linkTarget.label}
: null} {proposal.options ?
Values
: null} {proposal.options ?
{proposal.options.join(", ")}
: null}
{proposal.why.length > 0 ? (
    {proposal.why.map((line, i) =>
  • {line}
  • )}
) : null} {proposal.missing.length > 0 ? (
    {proposal.missing.map((line, i) =>
  • {line}
  • )}
) : null}
{/* ⛔ THE ONLY PATH TO CREATION. Disabled while anything is still open, so the agent asks rather than inventing an answer nobody gave it. */}
)}