feat(assistant): Improve screen context processing with model selection
This commit is contained in:
@@ -40,7 +40,7 @@ class AndroidAssistantHandler {
|
|||||||
Future<void> _handleMethodCall(MethodCall call) async {
|
Future<void> _handleMethodCall(MethodCall call) async {
|
||||||
if (call.method == 'analyzeScreen') {
|
if (call.method == 'analyzeScreen') {
|
||||||
final String context = call.arguments as String;
|
final String context = call.arguments as String;
|
||||||
_ref.read(screenContextProvider.notifier).setContext(context);
|
await _processScreenContext(context);
|
||||||
} else if (call.method == 'analyzeScreenshot') {
|
} else if (call.method == 'analyzeScreenshot') {
|
||||||
final String screenshotPath = call.arguments as String;
|
final String screenshotPath = call.arguments as String;
|
||||||
await _processScreenshot(screenshotPath);
|
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 {
|
Future<void> _processScreenshot(String screenshotPath) async {
|
||||||
try {
|
try {
|
||||||
DebugLogger.log('Processing screenshot: $screenshotPath', scope: 'assistant');
|
DebugLogger.log('Processing screenshot: $screenshotPath', scope: 'assistant');
|
||||||
|
|||||||
@@ -315,12 +315,10 @@ class _ChatPageState extends ConsumerState<ChatPage> {
|
|||||||
// Clear the context so we don't process it again
|
// Clear the context so we don't process it again
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
ref.read(screenContextProvider.notifier).setContext(null);
|
ref.read(screenContextProvider.notifier).setContext(null);
|
||||||
// Pre-fill the input or send a message
|
final currentModel = ref.read(selectedModelProvider);
|
||||||
// For now, let's just pre-fill the input with a prompt
|
|
||||||
// TODO: Ideally we should add this as a system message or attachment
|
|
||||||
_handleMessageSend(
|
_handleMessageSend(
|
||||||
"Here is the content of my screen:\n\n$screenContext\n\nCan you summarize this?",
|
"Here is the content of my screen:\n\n$screenContext\n\nCan you summarize this?",
|
||||||
null,
|
currentModel,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user