后端: - 新增 ai_intent_router 意图路由 - 新增 AiEntryDraft 草稿存储 + EF 迁移 - 新增 Prompts 模块化(global/modules/rag/router) - AI Agent handlers 扩展 前端: - 新增 AI 同意门 (ai_consent_gate/provider/details_page) - HealthMetricVisuals 视觉统一 - 设备扫描/管理页面优化 - agent 插图替换 + 趋势指标图标 配置: - DeepSeek 模型改 deepseek-v4-flash - .gitignore 加 artifacts/audit - build.gradle.kts 签名配置调整
94 lines
2.3 KiB
Dart
94 lines
2.3 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'auth_provider.dart' show localDbProvider;
|
|
|
|
const aiConsentVersion = 'ai-data-consent-v1';
|
|
|
|
class AiConsentState {
|
|
final bool isLoading;
|
|
final bool isSaving;
|
|
final bool granted;
|
|
final String? userId;
|
|
final String? error;
|
|
|
|
const AiConsentState({
|
|
this.isLoading = true,
|
|
this.isSaving = false,
|
|
this.granted = false,
|
|
this.userId,
|
|
this.error,
|
|
});
|
|
}
|
|
|
|
final aiConsentProvider = NotifierProvider<AiConsentNotifier, AiConsentState>(
|
|
AiConsentNotifier.new,
|
|
);
|
|
|
|
class AiConsentNotifier extends Notifier<AiConsentState> {
|
|
@override
|
|
AiConsentState build() => const AiConsentState();
|
|
|
|
String _key(String userId) => '$aiConsentVersion:$userId';
|
|
|
|
Future<void> load(String userId) async {
|
|
state = AiConsentState(isLoading: true, userId: userId);
|
|
try {
|
|
final value = await ref.read(localDbProvider).read(_key(userId));
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
granted: value == 'granted',
|
|
userId: userId,
|
|
);
|
|
} catch (_) {
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
userId: userId,
|
|
error: '授权状态加载失败,请重试',
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<bool> grant(String userId) async {
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
isSaving: true,
|
|
granted: state.granted,
|
|
userId: userId,
|
|
);
|
|
try {
|
|
await ref.read(localDbProvider).write(_key(userId), 'granted');
|
|
state = AiConsentState(isLoading: false, granted: true, userId: userId);
|
|
return true;
|
|
} catch (_) {
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
userId: userId,
|
|
error: '授权保存失败,请稍后重试',
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<bool> revoke(String userId) async {
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
isSaving: true,
|
|
granted: state.granted,
|
|
userId: userId,
|
|
);
|
|
try {
|
|
await ref.read(localDbProvider).delete(_key(userId));
|
|
state = AiConsentState(isLoading: false, granted: false, userId: userId);
|
|
return true;
|
|
} catch (_) {
|
|
state = AiConsentState(
|
|
isLoading: false,
|
|
granted: true,
|
|
userId: userId,
|
|
error: '撤回授权失败,请稍后重试',
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
}
|