generateSuggestions method
Implementation
@override
Future<List<String>> generateSuggestions(
String context, {
String? sessionId,
int maxSuggestions = 5,
}) async {
if (context.trim().isEmpty) {
throw AppleFoundationException(
'Context cannot be empty',
code: 'INVALID_CONTEXT',
);
}
if (maxSuggestions <= 0 || maxSuggestions > 20) {
throw AppleFoundationException(
'maxSuggestions must be between 1 and 20',
code: 'INVALID_MAX_SUGGESTIONS',
);
}
try {
final List<dynamic>? result =
await _invokeMethodWithTimeout<List<dynamic>>('generateSuggestions', {
'context': context,
if (sessionId != null) 'sessionId': sessionId,
'maxSuggestions': maxSuggestions,
});
if (result == null) {
throw AppleFoundationException(
'Received null response from native layer',
code: 'NULL_RESPONSE',
);
}
return result.cast<String>();
} catch (e) {
_logError('generateSuggestions', e);
throw AppleFoundationException(
'Failed to generate suggestions: ${e.toString()}',
code: 'GENERATE_SUGGESTIONS_FAILED',
details: {
'context': context,
'sessionId': sessionId,
'maxSuggestions': maxSuggestions,
},
);
}
}