Use project-scoped endpoints and run IDs for current project, SCADA metadata, historical time series, migrated DMA results, and sensor placement runs. The regressions recurred because tests mocked pre-interceptor and new-only payload shapes, while history queries relied on implicit global scheme state and unbounded request fan-out. Cover post-interceptor pages, migrated result_rows, explicit run_id routing, multi-element requests, request limits, and cancellation.
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import type { ChatToolAction } from "@/store/chatToolStore";
|
|
|
|
type ViewHistoryAction = Extract<ChatToolAction, { type: "view_history" }>;
|
|
|
|
const readOptionalString = (value: unknown) =>
|
|
typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
|
|
export const buildViewHistoryAction = (
|
|
params: Record<string, unknown>,
|
|
): ViewHistoryAction => {
|
|
const rawFeatureInfos = Array.isArray(params.feature_infos)
|
|
? params.feature_infos
|
|
: [];
|
|
const featureInfos = rawFeatureInfos
|
|
.filter(
|
|
(item): item is [unknown, unknown] =>
|
|
Array.isArray(item) && item.length >= 2,
|
|
)
|
|
.map(
|
|
([id, type]) => [String(id).trim(), String(type).trim()] as [string, string],
|
|
)
|
|
.filter(([id, type]) => id.length > 0 && type.length > 0);
|
|
const rawDataType = params.data_type;
|
|
const dataType =
|
|
rawDataType === "realtime" ||
|
|
rawDataType === "scheme" ||
|
|
rawDataType === "none"
|
|
? rawDataType
|
|
: "realtime";
|
|
|
|
return {
|
|
type: "view_history",
|
|
featureInfos,
|
|
dataType,
|
|
runId: readOptionalString(params.run_id ?? params.runId),
|
|
startTime: readOptionalString(
|
|
params.start_time ?? params.startTime ?? params.from ?? params.start,
|
|
),
|
|
endTime: readOptionalString(
|
|
params.end_time ?? params.endTime ?? params.to ?? params.end,
|
|
),
|
|
};
|
|
};
|