feat: System-AI cache surface (v0.8.0)

Picks up cache-related additions in HubAdmin:
- AskAi gains `forceFresh` request flag and `cached` /
  `cachedAt` / `cacheHits` response fields.
- New ClearSystemLlmCache + ForgetCachedExplanation RPCs.
- SystemAiStatus carries `cacheCount` so the UI can render
  "Cache: N cached explanations".

HubClient exposes `clearSystemLlmCache()` returning the
purged count and `forgetCachedExplanation(prompt)` for the
Regenerate flow.

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-05-07 17:29:26 +02:00
parent 26d9d1f502
commit 6dc058344b
5 changed files with 227 additions and 7 deletions

View file

@ -217,8 +217,31 @@ class HubClient {
/// One-shot prompt to the configured System AI. Errors come
/// back inside [AskAiResponse.errorKind] (not as exceptions)
/// so Studio can map each category to its inline-fix copy.
Future<AskAiResponse> askAi(String prompt) {
return _admin.askAi(pb.AskAiRequest(prompt: prompt));
///
/// Cache-aware: identical prompts hit the persistent
/// per-(model, privacy_mode, prompt) cache; the response
/// carries `cached: true` plus the original generation
/// latency. Pass [forceFresh] to skip the cache (Studio's
/// Regenerate button).
Future<AskAiResponse> askAi(String prompt, {bool forceFresh = false}) {
return _admin.askAi(
pb.AskAiRequest(prompt: prompt, forceFresh: forceFresh),
);
}
/// Drop every cached System-AI explanation. Used by Settings
/// when the operator wants a clean slate without changing
/// model/privacy mode (which would also flush).
Future<int> clearSystemLlmCache() async {
final r = await _admin.clearSystemLlmCache(Empty());
return r.purged.toInt();
}
/// Drop a single cached entry by prompt. Studio's Regenerate
/// button calls this so the next askAi falls through to the
/// live provider.
Future<void> forgetCachedExplanation(String prompt) async {
await _admin.forgetCachedExplanation(pb.AskAiRequest(prompt: prompt));
}
/// Persist a new System-AI configuration. Validates +