feat(ui): add views for Responses (#2293)

# What does this PR do?
* Add responses list and detail views
* Refactored components to be shared as much as possible between chat
completions and responses

## Test Plan
<img width="2014" alt="image"
src="https://github.com/user-attachments/assets/6dee12ea-8876-4351-a6eb-2338058466ef"
/>
<img width="2021" alt="image"
src="https://github.com/user-attachments/assets/6c7c71b8-25b7-4199-9c57-6960be5580c8"
/>

added tests
This commit is contained in:
ehhuang 2025-05-28 09:51:22 -07:00 committed by GitHub
parent 6352078e4b
commit 56e5ddb39f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 3282 additions and 380 deletions

View file

@ -0,0 +1,29 @@
import {
MessageBlock,
ToolCallBlock,
} from "@/components/ui/message-components";
import { FunctionCallItem } from "../utils/item-types";
interface FunctionCallItemProps {
item: FunctionCallItem;
index: number;
keyPrefix: string;
}
export function FunctionCallItemComponent({
item,
index,
keyPrefix,
}: FunctionCallItemProps) {
const name = item.name || "unknown";
const args = item.arguments || "{}";
const formattedFunctionCall = `${name}(${args})`;
return (
<MessageBlock
key={`${keyPrefix}-${index}`}
label="Function Call"
content={<ToolCallBlock>{formattedFunctionCall}</ToolCallBlock>}
/>
);
}

View file

@ -0,0 +1,37 @@
import {
MessageBlock,
ToolCallBlock,
} from "@/components/ui/message-components";
import { BaseItem } from "../utils/item-types";
interface GenericItemProps {
item: BaseItem;
index: number;
keyPrefix: string;
}
export function GenericItemComponent({
item,
index,
keyPrefix,
}: GenericItemProps) {
// Handle other types like function calls, tool outputs, etc.
const itemData = item as Record<string, unknown>;
const content = itemData.content
? typeof itemData.content === "string"
? itemData.content
: JSON.stringify(itemData.content, null, 2)
: JSON.stringify(itemData, null, 2);
const label = keyPrefix === "input" ? "Input" : "Output";
return (
<MessageBlock
key={`${keyPrefix}-${index}`}
label={label}
labelDetail={`(${itemData.type})`}
content={<ToolCallBlock>{content}</ToolCallBlock>}
/>
);
}

View file

@ -0,0 +1,54 @@
import {
MessageBlock,
ToolCallBlock,
} from "@/components/ui/message-components";
import { FunctionCallItem, FunctionCallOutputItem } from "../utils/item-types";
interface GroupedFunctionCallItemProps {
functionCall: FunctionCallItem;
output: FunctionCallOutputItem;
index: number;
keyPrefix: string;
}
export function GroupedFunctionCallItemComponent({
functionCall,
output,
index,
keyPrefix,
}: GroupedFunctionCallItemProps) {
const name = functionCall.name || "unknown";
const args = functionCall.arguments || "{}";
// Extract the output content from function_call_output
let outputContent = "";
if (output.output) {
outputContent =
typeof output.output === "string"
? output.output
: JSON.stringify(output.output);
} else {
outputContent = JSON.stringify(output, null, 2);
}
const functionCallContent = (
<div>
<div className="mb-2">
<span className="text-sm text-gray-600">Arguments</span>
<ToolCallBlock>{`${name}(${args})`}</ToolCallBlock>
</div>
<div>
<span className="text-sm text-gray-600">Output</span>
<ToolCallBlock>{outputContent}</ToolCallBlock>
</div>
</div>
);
return (
<MessageBlock
key={`${keyPrefix}-${index}`}
label="Function Call"
content={functionCallContent}
/>
);
}

View file

@ -0,0 +1,6 @@
export { MessageItemComponent } from "./message-item";
export { FunctionCallItemComponent } from "./function-call-item";
export { WebSearchItemComponent } from "./web-search-item";
export { GenericItemComponent } from "./generic-item";
export { GroupedFunctionCallItemComponent } from "./grouped-function-call-item";
export { ItemRenderer } from "./item-renderer";

View file

@ -0,0 +1,60 @@
import {
isMessageItem,
isFunctionCallItem,
isWebSearchCallItem,
AnyResponseItem,
} from "../utils/item-types";
import { MessageItemComponent } from "./message-item";
import { FunctionCallItemComponent } from "./function-call-item";
import { WebSearchItemComponent } from "./web-search-item";
import { GenericItemComponent } from "./generic-item";
interface ItemRendererProps {
item: AnyResponseItem;
index: number;
keyPrefix: string;
defaultRole?: string;
}
export function ItemRenderer({
item,
index,
keyPrefix,
defaultRole = "unknown",
}: ItemRendererProps) {
if (isMessageItem(item)) {
return (
<MessageItemComponent
item={item}
index={index}
keyPrefix={keyPrefix}
defaultRole={defaultRole}
/>
);
}
if (isFunctionCallItem(item)) {
return (
<FunctionCallItemComponent
item={item}
index={index}
keyPrefix={keyPrefix}
/>
);
}
if (isWebSearchCallItem(item)) {
return (
<WebSearchItemComponent item={item} index={index} keyPrefix={keyPrefix} />
);
}
// Fallback to generic item for unknown types
return (
<GenericItemComponent
item={item as any}
index={index}
keyPrefix={keyPrefix}
/>
);
}

View file

@ -0,0 +1,41 @@
import { MessageBlock } from "@/components/ui/message-components";
import { MessageItem } from "../utils/item-types";
interface MessageItemProps {
item: MessageItem;
index: number;
keyPrefix: string;
defaultRole?: string;
}
export function MessageItemComponent({
item,
index,
keyPrefix,
defaultRole = "unknown",
}: MessageItemProps) {
let content = "";
if (typeof item.content === "string") {
content = item.content;
} else if (Array.isArray(item.content)) {
content = item.content
.map((c) => {
return c.type === "input_text" || c.type === "output_text"
? c.text
: JSON.stringify(c);
})
.join(" ");
}
const role = item.role || defaultRole;
const label = role.charAt(0).toUpperCase() + role.slice(1);
return (
<MessageBlock
key={`${keyPrefix}-${index}`}
label={label}
content={content}
/>
);
}

View file

@ -0,0 +1,28 @@
import {
MessageBlock,
ToolCallBlock,
} from "@/components/ui/message-components";
import { WebSearchCallItem } from "../utils/item-types";
interface WebSearchItemProps {
item: WebSearchCallItem;
index: number;
keyPrefix: string;
}
export function WebSearchItemComponent({
item,
index,
keyPrefix,
}: WebSearchItemProps) {
const formattedWebSearch = `web_search_call(status: ${item.status})`;
return (
<MessageBlock
key={`${keyPrefix}-${index}`}
label="Function Call"
labelDetail="(Web Search)"
content={<ToolCallBlock>{formattedWebSearch}</ToolCallBlock>}
/>
);
}