feat: let chat run demo timeline
This commit is contained in:
@@ -157,7 +157,76 @@ describe("OperatorChat", () => {
|
||||
expect(screen.getByText("provider failed")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders prepared run tool calls as workflow handoffs", () => {
|
||||
it("shows a chat-owned run prepared workflow action", async () => {
|
||||
const user = userEvent.setup();
|
||||
const runPreparedWorkflow = vi.fn(async () => {});
|
||||
|
||||
render(
|
||||
<OperatorChat
|
||||
state={initialPresentationState}
|
||||
timelineAgent={{
|
||||
messages: [],
|
||||
canRun: true,
|
||||
runLabel: "Run prepared workflow",
|
||||
runPreparedWorkflow,
|
||||
submitSelectedIssues: vi.fn(async () => {}),
|
||||
cancelReview: vi.fn(async () => {}),
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: /run prepared workflow/i }));
|
||||
expect(runPreparedWorkflow).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("routes schema approval submit and cancel through the timeline agent when present", async () => {
|
||||
const user = userEvent.setup();
|
||||
const submitSelectedIssues = vi.fn(async () => {});
|
||||
const cancelReview = vi.fn(async () => {});
|
||||
const messages: ReadonlyArray<AgentMessage> = [
|
||||
{
|
||||
id: "approval",
|
||||
role: "assistant",
|
||||
parts: [
|
||||
{
|
||||
type: "approval-request",
|
||||
callId: "call-1",
|
||||
name: "resumeIssueReview",
|
||||
prompt: "Submit resume request?",
|
||||
contract: {
|
||||
kind: "issue_review",
|
||||
outcomes: ["submitted", "cancelled"],
|
||||
resumeSchema: { type: "object" },
|
||||
resumePayloadPreview: { selected_issue_ids: ["risk-1"] },
|
||||
runId: "run_recorded_lda_report",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
render(
|
||||
<OperatorChat
|
||||
state={initialPresentationState}
|
||||
messages={messages}
|
||||
timelineAgent={{
|
||||
messages: [],
|
||||
canRun: false,
|
||||
runLabel: "Run prepared workflow",
|
||||
runPreparedWorkflow: vi.fn(async () => {}),
|
||||
submitSelectedIssues,
|
||||
cancelReview,
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByRole("button", { name: /submit/i }));
|
||||
await user.click(screen.getByRole("button", { name: /cancel/i }));
|
||||
expect(submitSelectedIssues).toHaveBeenCalledTimes(1);
|
||||
expect(cancelReview).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("renders prepared run tool calls as workflow handoffs", () => {
|
||||
const messages: ReadonlyArray<AgentMessage> = [
|
||||
{
|
||||
id: "start",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { m } from "motion/react";
|
||||
import { PREPARE_THESIS_REPORT_RECIPE } from "../demo/agent/recipes.js";
|
||||
import type { AgentMessage, AgentMessagePart } from "../demo/agent/events.js";
|
||||
import type { TimelineAgentController } from "../demo/agent/timelineAgent.js";
|
||||
import type { PresentationState } from "./presentation-state.js";
|
||||
import { compositionForState } from "./presentation-state.js";
|
||||
import { SchemaApprovalSurface } from "./approval/SchemaApprovalSurface.js";
|
||||
@@ -8,6 +9,7 @@ import { SchemaApprovalSurface } from "./approval/SchemaApprovalSurface.js";
|
||||
type OperatorChatProps = {
|
||||
readonly state: PresentationState;
|
||||
readonly messages?: ReadonlyArray<AgentMessage> | undefined;
|
||||
readonly timelineAgent?: TimelineAgentController | undefined;
|
||||
readonly onApprove?: (() => void) | undefined;
|
||||
readonly onDeny?: (() => void) | undefined;
|
||||
};
|
||||
@@ -121,8 +123,14 @@ const partKey = (messageId: string, part: AgentMessagePart): string => {
|
||||
}
|
||||
};
|
||||
|
||||
export const OperatorChat = ({ state, messages, onApprove, onDeny }: OperatorChatProps) => {
|
||||
const visibleMessages = messages && messages.length > 0 ? messages : fallbackMessages(state);
|
||||
export const OperatorChat = ({ state, messages, timelineAgent, onApprove, onDeny }: OperatorChatProps) => {
|
||||
const visibleMessages = messages && messages.length > 0
|
||||
? messages
|
||||
: timelineAgent && timelineAgent.messages.length > 0
|
||||
? timelineAgent.messages
|
||||
: fallbackMessages(state);
|
||||
const submit = timelineAgent?.submitSelectedIssues ?? onApprove;
|
||||
const cancel = timelineAgent?.cancelReview ?? onDeny;
|
||||
const composition = compositionForState(state);
|
||||
const presentationSurface = composition.chatTheme === "light" ? "editorial" : "night";
|
||||
return (
|
||||
@@ -133,10 +141,21 @@ export const OperatorChat = ({ state, messages, onApprove, onDeny }: OperatorCha
|
||||
data-presentation-surface={presentationSurface}
|
||||
aria-label="scripted operator chat"
|
||||
>
|
||||
{timelineAgent ? (
|
||||
<div className="operator-chat__action">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void timelineAgent.runPreparedWorkflow()}
|
||||
disabled={!timelineAgent.canRun}
|
||||
>
|
||||
{timelineAgent.runLabel}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{visibleMessages.map((message) => (
|
||||
<div key={message.id} className={`chat-message chat-message--${message.role === "user" ? "operator" : "system"}`}>
|
||||
<strong>{message.role === "user" ? "Operator" : "lda.chat"}</strong>
|
||||
{message.parts.map((part) => renderPart(part, partKey(message.id, part), onApprove, onDeny))}
|
||||
{message.parts.map((part) => renderPart(part, partKey(message.id, part), submit, cancel))}
|
||||
</div>
|
||||
))}
|
||||
</aside>
|
||||
|
||||
@@ -1307,3 +1307,24 @@
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.operator-chat__action {
|
||||
display: flex;
|
||||
padding: 0.65rem;
|
||||
border-bottom: 1px solid var(--stage-line);
|
||||
}
|
||||
|
||||
.operator-chat__action button {
|
||||
width: 100%;
|
||||
border: 1px solid color-mix(in oklch, var(--accent-cyan) 56%, var(--stage-line));
|
||||
border-radius: 0.55rem;
|
||||
padding: 0.6rem 0.75rem;
|
||||
background: color-mix(in oklch, var(--accent-cyan) 18%, var(--stage-surface));
|
||||
color: var(--text-primary);
|
||||
font: 700 0.8rem/1 var(--font-mono);
|
||||
}
|
||||
|
||||
.operator-chat__action button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user