fix(app): fix instance chat routing to iAgent instead of OpenClaw
chatRepositoryProvider and sendMessageUseCaseProvider were not overridden in AgentInstanceChatPage's ProviderScope, causing ChatNotifier.sendMessage to use the parent scope's ChatRemoteDatasource (iAgent endpoint POST /api/v1/agent/tasks) instead of AgentInstanceChatDatasource (OpenClaw endpoint POST /api/v1/agent/instances/:id/tasks). Fix: override both providers in the child scope so the full call chain (sendMessage → SendMessage → ChatRepositoryImpl → createTask) routes to the correct instance-specific endpoint. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
73bd32b247
commit
a8c72aca76
|
|
@ -1,10 +1,16 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../../auth/data/providers/auth_provider.dart';
|
||||||
|
import '../../../chat/data/datasources/chat_local_datasource.dart';
|
||||||
|
import '../../../chat/data/models/chat_message_model.dart';
|
||||||
|
import '../../../chat/data/repositories/chat_repository_impl.dart';
|
||||||
|
import '../../../chat/domain/usecases/send_message.dart';
|
||||||
import '../../../chat/presentation/pages/chat_page.dart';
|
import '../../../chat/presentation/pages/chat_page.dart';
|
||||||
import '../../../chat/presentation/providers/chat_providers.dart';
|
import '../../../chat/presentation/providers/chat_providers.dart';
|
||||||
import '../../../my_agents/presentation/pages/my_agents_page.dart';
|
import '../../../my_agents/presentation/pages/my_agents_page.dart';
|
||||||
import '../../data/datasources/agent_instance_chat_remote_datasource.dart';
|
import '../../data/datasources/agent_instance_chat_remote_datasource.dart';
|
||||||
import '../../../../core/network/dio_client.dart';
|
import '../../../../core/network/dio_client.dart';
|
||||||
|
import '../../../../core/network/websocket_client.dart';
|
||||||
import '../../../../core/widgets/floating_robot_fab.dart';
|
import '../../../../core/widgets/floating_robot_fab.dart';
|
||||||
import '../../../../core/widgets/robot_painter.dart';
|
import '../../../../core/widgets/robot_painter.dart';
|
||||||
|
|
||||||
|
|
@ -29,6 +35,28 @@ class AgentInstanceChatPage extends StatelessWidget {
|
||||||
return AgentInstanceChatDatasource(dio, instance.id);
|
return AgentInstanceChatDatasource(dio, instance.id);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// chatRepositoryProvider must also be overridden so that sendMessage
|
||||||
|
// goes through AgentInstanceChatDatasource (instance endpoint) rather
|
||||||
|
// than the parent scope's ChatRemoteDatasource (iAgent endpoint).
|
||||||
|
chatRepositoryProvider.overrideWith((ref) {
|
||||||
|
final remote = ref.watch(chatRemoteDatasourceProvider);
|
||||||
|
final local = ref.watch(chatLocalDatasourceProvider);
|
||||||
|
final ws = ref.watch(webSocketClientProvider);
|
||||||
|
final storage = ref.watch(secureStorageProvider);
|
||||||
|
return ChatRepositoryImpl(
|
||||||
|
remoteDatasource: remote,
|
||||||
|
localDatasource: local ?? _NoOpLocal(),
|
||||||
|
webSocketClient: ws,
|
||||||
|
getAccessToken: () => storage.read(key: 'access_token'),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
|
||||||
|
// sendMessageUseCaseProvider must be overridden so ChatNotifier.sendMessage
|
||||||
|
// reads the child-scope chatRepositoryProvider (instance endpoint).
|
||||||
|
sendMessageUseCaseProvider.overrideWith(
|
||||||
|
(ref) => SendMessage(ref.watch(chatRepositoryProvider)),
|
||||||
|
),
|
||||||
|
|
||||||
// Fresh, isolated chatProvider for this instance — does NOT share
|
// Fresh, isolated chatProvider for this instance — does NOT share
|
||||||
// state with iAgent's chatProvider in the parent scope.
|
// state with iAgent's chatProvider in the parent scope.
|
||||||
chatProvider.overrideWith((ref) => ChatNotifier(ref)),
|
chatProvider.overrideWith((ref) => ChatNotifier(ref)),
|
||||||
|
|
@ -58,3 +86,15 @@ class AgentInstanceChatPage extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// No-op local cache — instance chat sessions are not cached locally.
|
||||||
|
class _NoOpLocal implements ChatLocalDatasource {
|
||||||
|
@override
|
||||||
|
Future<void> cacheMessages(String sessionId, List<ChatMessageModel> messages) async {}
|
||||||
|
@override
|
||||||
|
List<ChatMessageModel> getCachedMessages(String sessionId) => [];
|
||||||
|
@override
|
||||||
|
Future<void> clearCache(String sessionId) async {}
|
||||||
|
@override
|
||||||
|
Future<void> clearAllCaches() async {}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue