Skip to content

Commit bb579da

Browse files
ivictborCopilot
andcommitted
fix: add validation for get_resource_data response and improve datetime formatting handling
Co-authored-by: Copilot <copilot@github.com>
1 parent 99deb3c commit bb579da

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

apiBasedTools.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,17 @@ const TOOL_OVERRIDES: Record<string, ToolOverride> = {
110110
return output;
111111
}
112112

113+
if (!hasGetResourceDataRows(output)) {
114+
logger.warn(
115+
`Skipping datetime formatting for get_resource_data because response.data is not an array for resource ${getInputString(inputs, 'resourceId') ?? 'unknown'}`,
116+
);
117+
return output;
118+
}
119+
113120
const localizedTimeZone = userTimeZone ?? DEFAULT_USER_TIME_ZONE;
114-
const response = output as GetResourceDataToolResponse;
115-
formatDateTimeColumns(response.data, dateTimeColumnNames, localizedTimeZone);
121+
formatDateTimeColumns(output.data, dateTimeColumnNames, localizedTimeZone);
116122

117-
return response;
123+
return output;
118124
},
119125
},
120126
aggregate: {
@@ -288,6 +294,14 @@ function hasToolError(output: unknown): output is { error: unknown } {
288294
return typeof output === 'object' && output !== null && 'error' in output;
289295
}
290296

297+
function hasGetResourceDataRows(output: unknown): output is GetResourceDataToolResponse {
298+
if (typeof output !== 'object' || output === null || !('data' in output)) {
299+
return false;
300+
}
301+
302+
return Array.isArray((output as { data?: unknown }).data);
303+
}
304+
291305
function getDateTimeColumnNames(
292306
adminforth: IAdminForth,
293307
inputs: Record<string, unknown> | undefined,

0 commit comments

Comments
 (0)