getStructuredData method
Implementation
@override
Future<Map<String, dynamic>> getStructuredData(
String prompt, {
String? sessionId,
}) async {
if (prompt.trim().isEmpty) {
throw AppleFoundationException(
'Prompt cannot be empty',
code: 'INVALID_PROMPT',
);
}
try {
final String? jsonString = await _invokeMethodWithTimeout<String>(
'getStructuredData',
{'prompt': prompt, if (sessionId != null) 'sessionId': sessionId},
);
if (jsonString == null || jsonString.isEmpty) {
throw AppleFoundationException(
'Received empty response from native layer',
code: 'EMPTY_RESPONSE',
);
}
final Map<String, dynamic> decodedData =
json.decode(jsonString) as Map<String, dynamic>;
return decodedData;
} on FormatException catch (e) {
_logError('getStructuredData - JSON decode', e);
throw AppleFoundationException(
'Failed to parse structured data response',
code: 'JSON_PARSE_ERROR',
details: e.toString(),
);
} catch (e) {
_logError('getStructuredData', e);
throw AppleFoundationException(
'Failed to get structured data: ${e.toString()}',
code: 'STRUCTURED_DATA_FAILED',
details: {'prompt': prompt, 'sessionId': sessionId},
);
}
}