|
| 1 | +import { useState } from "react"; |
| 2 | +import type { InterruptEvent } from "../../types/run"; |
| 3 | + |
| 4 | +interface Props { |
| 5 | + interrupt: InterruptEvent; |
| 6 | + onRespond: (data: Record<string, unknown>) => void; |
| 7 | +} |
| 8 | + |
| 9 | +export default function ChatInterrupt({ interrupt, onRespond }: Props) { |
| 10 | + const [responseText, setResponseText] = useState(""); |
| 11 | + |
| 12 | + if (interrupt.interrupt_type === "tool_call_confirmation") { |
| 13 | + return ( |
| 14 | + <div |
| 15 | + className="mx-3 my-2 rounded-lg overflow-hidden" |
| 16 | + style={{ border: "1px solid color-mix(in srgb, var(--warning) 40%, var(--border))" }} |
| 17 | + > |
| 18 | + <div |
| 19 | + className="px-3 py-2 flex items-center gap-2" |
| 20 | + style={{ |
| 21 | + background: "color-mix(in srgb, var(--warning) 10%, var(--bg-secondary))", |
| 22 | + }} |
| 23 | + > |
| 24 | + <span |
| 25 | + className="text-[10px] uppercase tracking-wider font-semibold" |
| 26 | + style={{ color: "var(--warning)" }} |
| 27 | + > |
| 28 | + Action Required |
| 29 | + </span> |
| 30 | + {interrupt.tool_name && ( |
| 31 | + <span |
| 32 | + className="text-[10px] font-mono px-1.5 py-0.5 rounded" |
| 33 | + style={{ |
| 34 | + background: "color-mix(in srgb, var(--warning) 15%, var(--bg-secondary))", |
| 35 | + color: "var(--text-primary)", |
| 36 | + }} |
| 37 | + > |
| 38 | + {interrupt.tool_name} |
| 39 | + </span> |
| 40 | + )} |
| 41 | + </div> |
| 42 | + {interrupt.input_value != null && ( |
| 43 | + <pre |
| 44 | + className="px-3 py-2 text-[11px] font-mono whitespace-pre-wrap break-words overflow-y-auto" |
| 45 | + style={{ |
| 46 | + background: "var(--bg-secondary)", |
| 47 | + color: "var(--text-secondary)", |
| 48 | + maxHeight: 200, |
| 49 | + }} |
| 50 | + > |
| 51 | + {typeof interrupt.input_value === "string" |
| 52 | + ? interrupt.input_value |
| 53 | + : JSON.stringify(interrupt.input_value, null, 2)} |
| 54 | + </pre> |
| 55 | + )} |
| 56 | + <div |
| 57 | + className="flex items-center gap-2 px-3 py-2" |
| 58 | + style={{ |
| 59 | + background: "var(--bg-secondary)", |
| 60 | + borderTop: "1px solid var(--border)", |
| 61 | + }} |
| 62 | + > |
| 63 | + <button |
| 64 | + onClick={() => onRespond({ approved: true })} |
| 65 | + className="text-[10px] uppercase tracking-wider font-semibold px-3 py-1 rounded cursor-pointer transition-colors" |
| 66 | + style={{ |
| 67 | + background: "color-mix(in srgb, var(--success) 15%, var(--bg-secondary))", |
| 68 | + color: "var(--success)", |
| 69 | + border: "1px solid color-mix(in srgb, var(--success) 30%, var(--border))", |
| 70 | + }} |
| 71 | + onMouseEnter={(e) => { |
| 72 | + e.currentTarget.style.background = "color-mix(in srgb, var(--success) 25%, var(--bg-secondary))"; |
| 73 | + }} |
| 74 | + onMouseLeave={(e) => { |
| 75 | + e.currentTarget.style.background = "color-mix(in srgb, var(--success) 15%, var(--bg-secondary))"; |
| 76 | + }} |
| 77 | + > |
| 78 | + Approve |
| 79 | + </button> |
| 80 | + <button |
| 81 | + onClick={() => onRespond({ approved: false })} |
| 82 | + className="text-[10px] uppercase tracking-wider font-semibold px-3 py-1 rounded cursor-pointer transition-colors" |
| 83 | + style={{ |
| 84 | + background: "color-mix(in srgb, var(--error) 15%, var(--bg-secondary))", |
| 85 | + color: "var(--error)", |
| 86 | + border: "1px solid color-mix(in srgb, var(--error) 30%, var(--border))", |
| 87 | + }} |
| 88 | + onMouseEnter={(e) => { |
| 89 | + e.currentTarget.style.background = "color-mix(in srgb, var(--error) 25%, var(--bg-secondary))"; |
| 90 | + }} |
| 91 | + onMouseLeave={(e) => { |
| 92 | + e.currentTarget.style.background = "color-mix(in srgb, var(--error) 15%, var(--bg-secondary))"; |
| 93 | + }} |
| 94 | + > |
| 95 | + Reject |
| 96 | + </button> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + // Generic interrupt |
| 103 | + return ( |
| 104 | + <div |
| 105 | + className="mx-3 my-2 rounded-lg overflow-hidden" |
| 106 | + style={{ border: "1px solid color-mix(in srgb, var(--accent) 40%, var(--border))" }} |
| 107 | + > |
| 108 | + <div |
| 109 | + className="px-3 py-2" |
| 110 | + style={{ |
| 111 | + background: "color-mix(in srgb, var(--accent) 10%, var(--bg-secondary))", |
| 112 | + }} |
| 113 | + > |
| 114 | + <span |
| 115 | + className="text-[10px] uppercase tracking-wider font-semibold" |
| 116 | + style={{ color: "var(--accent)" }} |
| 117 | + > |
| 118 | + Input Required |
| 119 | + </span> |
| 120 | + </div> |
| 121 | + {interrupt.content != null && ( |
| 122 | + <div |
| 123 | + className="px-3 py-2 text-xs" |
| 124 | + style={{ |
| 125 | + background: "var(--bg-secondary)", |
| 126 | + color: "var(--text-secondary)", |
| 127 | + }} |
| 128 | + > |
| 129 | + {typeof interrupt.content === "string" |
| 130 | + ? interrupt.content |
| 131 | + : JSON.stringify(interrupt.content, null, 2)} |
| 132 | + </div> |
| 133 | + )} |
| 134 | + <div |
| 135 | + className="flex items-center gap-2 px-3 py-2" |
| 136 | + style={{ |
| 137 | + background: "var(--bg-secondary)", |
| 138 | + borderTop: "1px solid var(--border)", |
| 139 | + }} |
| 140 | + > |
| 141 | + <input |
| 142 | + value={responseText} |
| 143 | + onChange={(e) => setResponseText(e.target.value)} |
| 144 | + onKeyDown={(e) => { |
| 145 | + if (e.key === "Enter" && !e.shiftKey && responseText.trim()) { |
| 146 | + e.preventDefault(); |
| 147 | + onRespond({ response: responseText.trim() }); |
| 148 | + } |
| 149 | + }} |
| 150 | + placeholder="Type your response..." |
| 151 | + className="flex-1 bg-transparent text-xs py-1 focus:outline-none placeholder:text-[var(--text-muted)]" |
| 152 | + style={{ color: "var(--text-primary)" }} |
| 153 | + /> |
| 154 | + <button |
| 155 | + onClick={() => { |
| 156 | + if (responseText.trim()) { |
| 157 | + onRespond({ response: responseText.trim() }); |
| 158 | + } |
| 159 | + }} |
| 160 | + disabled={!responseText.trim()} |
| 161 | + className="text-[10px] uppercase tracking-wider font-semibold px-2 py-1 rounded transition-colors cursor-pointer disabled:opacity-30 disabled:cursor-not-allowed" |
| 162 | + style={{ |
| 163 | + color: responseText.trim() ? "var(--accent)" : "var(--text-muted)", |
| 164 | + background: "transparent", |
| 165 | + }} |
| 166 | + > |
| 167 | + Send |
| 168 | + </button> |
| 169 | + </div> |
| 170 | + </div> |
| 171 | + ); |
| 172 | +} |
0 commit comments