Merge pull request #73 from langchain-ai/brace/improve-hitl-rendering
fix: Allow for human interrupt to be passed without array
This commit is contained in:
@@ -100,6 +100,7 @@ export function ThreadActionsView({
|
|||||||
|
|
||||||
const threadTitle = interrupt.action_request.action || "Unknown";
|
const threadTitle = interrupt.action_request.action || "Unknown";
|
||||||
const actionsDisabled = loading || streaming;
|
const actionsDisabled = loading || streaming;
|
||||||
|
const ignoreAllowed = interrupt.config.allow_ignore;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col min-h-full w-full gap-9">
|
<div className="flex flex-col min-h-full w-full gap-9">
|
||||||
@@ -138,14 +139,16 @@ export function ThreadActionsView({
|
|||||||
>
|
>
|
||||||
Mark as Resolved
|
Mark as Resolved
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
{ignoreAllowed && (
|
||||||
variant="outline"
|
<Button
|
||||||
className="text-gray-800 border-gray-500 font-normal bg-white"
|
variant="outline"
|
||||||
onClick={handleIgnore}
|
className="text-gray-800 border-gray-500 font-normal bg-white"
|
||||||
disabled={actionsDisabled}
|
onClick={handleIgnore}
|
||||||
>
|
disabled={actionsDisabled}
|
||||||
Ignore
|
>
|
||||||
</Button>
|
Ignore
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import { HumanInterrupt } from "@langchain/langgraph/prebuilt";
|
|||||||
import { useStreamContext } from "@/providers/Stream";
|
import { useStreamContext } from "@/providers/Stream";
|
||||||
|
|
||||||
interface ThreadViewProps {
|
interface ThreadViewProps {
|
||||||
interrupt: HumanInterrupt;
|
interrupt: HumanInterrupt | HumanInterrupt[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ThreadView({ interrupt }: ThreadViewProps) {
|
export function ThreadView({ interrupt }: ThreadViewProps) {
|
||||||
|
const interruptObj = Array.isArray(interrupt) ? interrupt[0] : interrupt;
|
||||||
const thread = useStreamContext();
|
const thread = useStreamContext();
|
||||||
const [showDescription, setShowDescription] = useState(false);
|
const [showDescription, setShowDescription] = useState(false);
|
||||||
const [showState, setShowState] = useState(false);
|
const [showState, setShowState] = useState(false);
|
||||||
@@ -39,13 +40,13 @@ export function ThreadView({ interrupt }: ThreadViewProps) {
|
|||||||
{showSidePanel ? (
|
{showSidePanel ? (
|
||||||
<StateView
|
<StateView
|
||||||
handleShowSidePanel={handleShowSidePanel}
|
handleShowSidePanel={handleShowSidePanel}
|
||||||
description={interrupt.description}
|
description={interruptObj.description}
|
||||||
values={thread.values}
|
values={thread.values}
|
||||||
view={showState ? "state" : "description"}
|
view={showState ? "state" : "description"}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<ThreadActionsView
|
<ThreadActionsView
|
||||||
interrupt={interrupt}
|
interrupt={interruptObj}
|
||||||
handleShowSidePanel={handleShowSidePanel}
|
handleShowSidePanel={handleShowSidePanel}
|
||||||
showState={showState}
|
showState={showState}
|
||||||
showDescription={showDescription}
|
showDescription={showDescription}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export function AssistantMessage({
|
|||||||
|
|
||||||
<CustomComponent message={message} thread={thread} />
|
<CustomComponent message={message} thread={thread} />
|
||||||
{isAgentInboxInterruptSchema(interrupt?.value) && isLastMessage && (
|
{isAgentInboxInterruptSchema(interrupt?.value) && isLastMessage && (
|
||||||
<ThreadView interrupt={interrupt.value[0]} />
|
<ThreadView interrupt={interrupt.value} />
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ import { HumanInterrupt } from "@langchain/langgraph/prebuilt";
|
|||||||
|
|
||||||
export function isAgentInboxInterruptSchema(
|
export function isAgentInboxInterruptSchema(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
): value is HumanInterrupt[] {
|
): value is HumanInterrupt | HumanInterrupt[] {
|
||||||
|
const valueAsObject = Array.isArray(value) ? value[0] : value;
|
||||||
return (
|
return (
|
||||||
Array.isArray(value) &&
|
valueAsObject &&
|
||||||
"action_request" in value[0] &&
|
"action_request" in valueAsObject &&
|
||||||
typeof value[0].action_request === "object" &&
|
typeof valueAsObject.action_request === "object" &&
|
||||||
"config" in value[0] &&
|
"config" in valueAsObject &&
|
||||||
typeof value[0].config === "object" &&
|
typeof valueAsObject.config === "object" &&
|
||||||
"allow_respond" in value[0].config &&
|
"allow_respond" in valueAsObject.config &&
|
||||||
"allow_accept" in value[0].config &&
|
"allow_accept" in valueAsObject.config &&
|
||||||
"allow_edit" in value[0].config &&
|
"allow_edit" in valueAsObject.config &&
|
||||||
"allow_ignore" in value[0].config
|
"allow_ignore" in valueAsObject.config
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user