|
| 1 | +import type { OnlineEvaluationConfigSummary } from "@aws-sdk/client-bedrock-agentcore-control"; |
| 2 | +import { useNavigate } from "react-router"; |
| 3 | +import type { ScreenProps } from "../handlers/types"; |
| 4 | +import { coreOptsFromCtx } from "../handlers/utils"; |
| 5 | +import { formatTimestamp } from "./formatTimestamp"; |
| 6 | +import { PaginatedTablePicker } from "./PaginatedTablePicker"; |
| 7 | +import type { DataTableColumn } from "./ui/data-table"; |
| 8 | + |
| 9 | +// OnlineEvalRow is the flat, display-ready shape the table renders. It also |
| 10 | +// satisfies DataTable's `T extends Record<string, unknown>` constraint, which the |
| 11 | +// SDK's OnlineEvaluationConfigSummary interface does not. The list API returns |
| 12 | +// only summary fields (name/status/executionStatus/timestamps); richer detail |
| 13 | +// like sampling rate and evaluators comes from GetOnlineEvaluationConfig. |
| 14 | +interface OnlineEvalRow extends Record<string, unknown> { |
| 15 | + configId: string; |
| 16 | + configName: string; |
| 17 | + status: string; |
| 18 | + executionStatus: string; |
| 19 | + updatedAt: string; |
| 20 | +} |
| 21 | + |
| 22 | +export const onlineEvalColumns = [ |
| 23 | + { key: "configName", header: "name", flex: true }, |
| 24 | + { key: "status", header: "status", width: 12 }, |
| 25 | + { key: "executionStatus", header: "execution", width: 11 }, |
| 26 | + { |
| 27 | + key: "updatedAt", |
| 28 | + header: "updated UTC", |
| 29 | + width: 16, |
| 30 | + render: formatTimestamp, |
| 31 | + }, |
| 32 | +] satisfies DataTableColumn<OnlineEvalRow>[]; |
| 33 | + |
| 34 | +function toRow(config: OnlineEvaluationConfigSummary): OnlineEvalRow { |
| 35 | + const id = config.onlineEvaluationConfigId ?? ""; |
| 36 | + return { |
| 37 | + configId: id, |
| 38 | + configName: config.onlineEvaluationConfigName ?? id, |
| 39 | + status: config.status ?? "-", |
| 40 | + executionStatus: config.executionStatus ?? "-", |
| 41 | + updatedAt: config.updatedAt?.toISOString() ?? "-", |
| 42 | + }; |
| 43 | +} |
| 44 | + |
| 45 | +export interface OnlineEvalPickerProps extends ScreenProps { |
| 46 | + breadcrumb: string[]; |
| 47 | + description?: string; |
| 48 | + onSelect: (configId: string) => void; |
| 49 | + onEscape?: () => void; |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * Fetches the caller's online evaluation configs and renders them as a navigable |
| 54 | + * table. The shared body of every "pick a config" screen (list, and — in the |
| 55 | + * write TUI — update/pause/resume/delete). Esc returns to the parent menu derived |
| 56 | + * from the breadcrumb unless a host supplies its own onEscape. |
| 57 | + */ |
| 58 | +export function OnlineEvalPicker({ |
| 59 | + ctx, |
| 60 | + core, |
| 61 | + breadcrumb, |
| 62 | + description, |
| 63 | + onSelect, |
| 64 | + onEscape, |
| 65 | +}: OnlineEvalPickerProps) { |
| 66 | + const opts = coreOptsFromCtx(ctx); |
| 67 | + const navigate = useNavigate(); |
| 68 | + const goBack = onEscape ?? (() => navigate("/" + breadcrumb.slice(0, -1).join("/"))); |
| 69 | + |
| 70 | + return ( |
| 71 | + <PaginatedTablePicker |
| 72 | + breadcrumb={breadcrumb} |
| 73 | + description={description} |
| 74 | + queryKey={["online-evals", opts.region]} |
| 75 | + loadPage={async (token, pageSize) => { |
| 76 | + const response = await core.eval.listOnlineEvaluationConfigs(token, pageSize, opts); |
| 77 | + return { |
| 78 | + items: response.onlineEvaluationConfigs ?? [], |
| 79 | + nextToken: response.nextToken, |
| 80 | + }; |
| 81 | + }} |
| 82 | + toRow={toRow} |
| 83 | + columns={onlineEvalColumns} |
| 84 | + getValue={(row) => row.configId} |
| 85 | + onSelect={onSelect} |
| 86 | + onBack={goBack} |
| 87 | + loadingMessage="Loading online evaluation configs…" |
| 88 | + errorMessage={(error) => `Error: ${error.message}`} |
| 89 | + emptyMessage="No online evaluation configs found in this Region." |
| 90 | + emptyPageMessage="No online evaluation configs on this page." |
| 91 | + /> |
| 92 | + ); |
| 93 | +} |
0 commit comments