fluffychat/lib/pangea/common/models/base_request_model.dart
wcjord dec473d579
Writing assistance (#5598)
* feat: wa working full stack

* feat: writing assistance made anew

* docs: migrate copilot docs to .github/instructions/ format

- Create choreographer.instructions.md (applyTo: lib/pangea/choreographer/**)
- Create events-and-tokens.instructions.md (applyTo: lib/pangea/events/**,lib/pangea/extensions/**)
- Create modules.instructions.md (applyTo: lib/pangea/**) — full module map
- Track copilot-instructions.md (remove .gitignore rule)
- Add documentation reference table to copilot-instructions.md

Content sourced from docs/copilot/ on writing-assistance branch.

* docs: remove old docs/copilot/ (migrated to .github/instructions/)

* docs: update choreographer + modules docs for writing-assistance audit

- Mark IT (Interactive Translation) as deprecated throughout
- Document new ReplacementTypeEnum taxonomy (grammar, surface, word-choice categories)
- Add AssistanceStateEnum, AutocorrectPopup, feedback rerun flow
- Mark SpanDataRepo/span_details as dead code
- Mark SpanChoiceTypeEnum.bestCorrection/bestAnswer as deprecated
- Add new files to modules listing (autocorrect_popup, start_igc_button, etc.)
- Update API endpoints table with active/deprecated/dead status

* formatting, replace deprecated withOpacity calls

* fix linter issues from deprecated types

* use better error color

* move cloing of overlays into choreographer

* reduce duplicate code on igc_controller, update UI on feedback

* couple of adjustments

* display prompt in span card by type

* fix error in tests

* translations

* simplify span card feedback

---------

Co-authored-by: ggurdin <ggurdin@gmail.com>
2026-02-09 15:55:18 -05:00

41 lines
1.5 KiB
Dart

import 'package:fluffychat/pangea/common/constants/model_keys.dart';
import 'package:fluffychat/pangea/learning_settings/gender_enum.dart';
import 'package:fluffychat/widgets/matrix.dart';
/// Base request schema matching the backend's BaseRequestSchema.
/// Common fields for all LLM-based requests.
mixin BaseRequestModel {
/// User's native language code (L1)
String get userL1;
/// User's target language code (L2)
String get userL2;
/// User's CEFR proficiency level (defaults to "pre_a1")
String get userCefr;
/// Convert to JSON map with common fields
Map<String, dynamic> toBaseJson() => {
ModelKey.userL1: userL1,
ModelKey.userL2: userL2,
ModelKey.cefrLevel: userCefr,
ModelKey.userGender: MatrixState
.pangeaController.userController.profile.userSettings.gender.string,
};
/// Injects user context (CEFR level, gender) into a request body.
/// Safely handles cases where MatrixState is not yet initialized.
/// Does not overwrite existing values.
static Map<String, dynamic> injectUserContext(Map<dynamic, dynamic> body) {
final result = Map<String, dynamic>.from(body);
try {
final settings =
MatrixState.pangeaController.userController.profile.userSettings;
result[ModelKey.cefrLevel] ??= settings.cefrLevel.string;
result[ModelKey.userGender] ??= settings.gender.string;
} catch (_) {
// MatrixState not initialized - leave existing values or omit
}
return result;
}
}