feat(assistant): Improve screen context processing with model selection

This commit is contained in:
cogwheel0
2025-11-21 21:12:39 +05:30
parent 9d47c8a964
commit 1a6ec3f9ad
2 changed files with 31 additions and 5 deletions

View File

@@ -40,7 +40,7 @@ class AndroidAssistantHandler {
Future<void> _handleMethodCall(MethodCall call) async {
if (call.method == 'analyzeScreen') {
final String context = call.arguments as String;
_ref.read(screenContextProvider.notifier).setContext(context);
await _processScreenContext(context);
} else if (call.method == 'analyzeScreenshot') {
final String screenshotPath = call.arguments as String;
await _processScreenshot(screenshotPath);
@@ -49,6 +49,34 @@ class AndroidAssistantHandler {
}
}
Future<void> _processScreenContext(String context) async {
try {
DebugLogger.log('Processing screen context', scope: 'assistant');
// Wait for app to be ready (authenticated and model available)
final navState = _ref.read(authNavigationStateProvider);
final model = _ref.read(selectedModelProvider);
if (navState != AuthNavigationState.authenticated || model == null) {
DebugLogger.log('App not ready for screen context processing', scope: 'assistant');
return;
}
// Navigate to chat if not already there
final isOnChatRoute = NavigationService.currentRoute == Routes.chat;
if (!isOnChatRoute) {
// Navigation will happen via auth state
return;
}
// Set the screen context
_ref.read(screenContextProvider.notifier).setContext(context);
DebugLogger.log('Screen context set successfully', scope: 'assistant');
} catch (e) {
DebugLogger.log('Failed to process screen context: $e', scope: 'assistant');
}
}
Future<void> _processScreenshot(String screenshotPath) async {
try {
DebugLogger.log('Processing screenshot: $screenshotPath', scope: 'assistant');

View File

@@ -315,12 +315,10 @@ class _ChatPageState extends ConsumerState<ChatPage> {
// Clear the context so we don't process it again
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(screenContextProvider.notifier).setContext(null);
// Pre-fill the input or send a message
// For now, let's just pre-fill the input with a prompt
// TODO: Ideally we should add this as a system message or attachment
final currentModel = ref.read(selectedModelProvider);
_handleMessageSend(
"Here is the content of my screen:\n\n$screenContext\n\nCan you summarize this?",
null,
currentModel,
);
});
}