feat(studio): trust pass — friendly errors + store clarity + MCP i18n
Second half of the May-2026 trust pass. Drops the wall of gRPC trailers from every error surface and makes the Store honest about what is and isn't installable. Friendly errors: - New `friendlyError(Object, AppLocalizations)` mapper turns GrpcError + arbitrary throwables into a localised headline, optional recovery hint, and a verbatim detail string kept behind a "Show details" expander. Duck-typed on `.code` / `.message` so Studio doesn't have to depend on package:grpc directly. - `FaiErrorBox` gains an `error:` constructor that runs the mapper. Every call site that used to render `snap.error.toString()` (flows, welcome, store) switches to it. - 9 .arb entries per locale cover the gRPC codes we actually emit (INVALID_ARGUMENT, NOT_FOUND, ALREADY_EXISTS, PERMISSION_DENIED, FAILED_PRECONDITION, INTERNAL, UNAVAILABLE, UNAUTHENTICATED) plus copy/details affordances. - `test/friendly_error_test.dart` — 6 unit tests for the mapper. Covers the mapping table, locale-switching, and the non-gRPC fallback so future regressions show up in CI. Capability discovery: - New `HubService.allCapabilities()` reads the kind-aware capability list (wasm + builtin + federated) and returns a Dart-side `CapabilityInfo` value type. The flow page's missing-dependency check uses it so `system.approval` and federated MCP/n8n tools count as "available" — fixes the Run button staying disabled forever. - `HubService.listModules()` filters to kind=wasm so the Modules page doesn't sprout synthetic "system" entries that the operator can't uninstall. Store clarity: - New "Installable only" filter, on by default. Roughly 2/3 of seed entries currently carry `status: planned`; the default view stops being noise. - Featured-strip cards for planned modules now show a "Coming soon" pill instead of an empty action area. - Main-grid cards for non-installable modules dim to 60% opacity so the eye lands on actionable cards first. - Detail-sheet "Nicht installierbar" tooltip → inline hint box. The reason is visible without hovering. MCP localisation: - `_kMcpSuggestions` no longer holds 11 hardcoded English description strings. The `description` field is replaced with a `resolveDescription(AppLocalizations)` lookup that switches on the suggestion `name` to read the matching `mcpSuggestion*Desc` .arb key. EN + DE shipped. - New `FaiEnBadge` widget renders a small `[EN]` pill when the active locale isn't English. Used next to MCP / federated store entries' tagline + description because the server supplies them in English and we can't translate on the fly yet — the badge is the honest signal until the planned `studio.translate` plugin lands. Plus housekeeping: removed the unused `_keepImport` lint escape in the test and the dangling library doc-comment in `format.dart`. Signed-off-by: flemming-it <sf@flemming.it> Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
parent
34f2b7b313
commit
c11461b0f9
15 changed files with 1219 additions and 104 deletions
148
lib/data/friendly_error.dart
Normal file
148
lib/data/friendly_error.dart
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
// Friendly-error mapper. Turns a thrown object (typically a
|
||||
// `GrpcError` from package:grpc) into a short human sentence
|
||||
// plus an optional recovery hint, ready to drop into the UI.
|
||||
//
|
||||
// Why this exists: Studio used to render `GrpcError.toString()`
|
||||
// verbatim — operators saw walls of text like
|
||||
// "gRPC Error (code: 13, codeName: INTERNAL, message: ..., details: [], rawResponse: null, trailers: {...})".
|
||||
// The friendly mapper folds every gRPC code into a one-line
|
||||
// explanation we can localise, plus a recovery action when one
|
||||
// is obvious (open settings, restart hub, retry).
|
||||
|
||||
import '../l10n/app_localizations.dart';
|
||||
|
||||
/// Result of running an error through [friendlyError]. The
|
||||
/// `headline` is the short user-facing sentence; `detail` is
|
||||
/// the verbatim original error string (kept around in case the
|
||||
/// operator wants to copy-paste it into a bug report). `hint`
|
||||
/// is a one-sentence recovery suggestion or `null`.
|
||||
class FriendlyError {
|
||||
final String headline;
|
||||
final String detail;
|
||||
final String? hint;
|
||||
|
||||
const FriendlyError({
|
||||
required this.headline,
|
||||
required this.detail,
|
||||
this.hint,
|
||||
});
|
||||
}
|
||||
|
||||
/// Map an arbitrary thrown object to a [FriendlyError]. Always
|
||||
/// returns a value — never throws — so callers can drop the
|
||||
/// result straight into UI without try/catch ceremony.
|
||||
FriendlyError friendlyError(Object error, AppLocalizations l) {
|
||||
// We deliberately don't import package:grpc here so Studio
|
||||
// doesn't have to add it to its own pubspec — the dependency
|
||||
// lives one layer down in fai_dart_sdk. `GrpcError` has a
|
||||
// stable `.code` (int) and `.message` (String?) shape; we
|
||||
// duck-type on those instead of an `is` check.
|
||||
final code = _intField(error, 'code');
|
||||
final detail = _stringField(error, 'message') ?? '';
|
||||
if (code != null) {
|
||||
switch (code) {
|
||||
case 3: // INVALID_ARGUMENT
|
||||
return FriendlyError(
|
||||
headline: l.errInvalidArgument,
|
||||
detail: detail,
|
||||
hint: l.errInvalidArgumentHint,
|
||||
);
|
||||
case 5: // NOT_FOUND
|
||||
return FriendlyError(
|
||||
headline: l.errNotFound,
|
||||
detail: detail,
|
||||
hint: l.errNotFoundHint,
|
||||
);
|
||||
case 6: // ALREADY_EXISTS
|
||||
return FriendlyError(
|
||||
headline: l.errAlreadyExists,
|
||||
detail: detail,
|
||||
hint: null,
|
||||
);
|
||||
case 7: // PERMISSION_DENIED
|
||||
return FriendlyError(
|
||||
headline: l.errPermissionDenied,
|
||||
detail: detail,
|
||||
hint: l.errPermissionDeniedHint,
|
||||
);
|
||||
case 9: // FAILED_PRECONDITION
|
||||
return FriendlyError(
|
||||
headline: l.errFailedPrecondition,
|
||||
detail: detail,
|
||||
hint: l.errFailedPreconditionHint,
|
||||
);
|
||||
case 13: // INTERNAL
|
||||
return FriendlyError(
|
||||
headline: l.errInternal,
|
||||
detail: detail,
|
||||
hint: l.errInternalHint,
|
||||
);
|
||||
case 14: // UNAVAILABLE
|
||||
return FriendlyError(
|
||||
headline: l.errUnavailable,
|
||||
detail: detail,
|
||||
hint: l.errUnavailableHint,
|
||||
);
|
||||
case 16: // UNAUTHENTICATED
|
||||
return FriendlyError(
|
||||
headline: l.errUnauthenticated,
|
||||
detail: detail,
|
||||
hint: l.errUnauthenticatedHint,
|
||||
);
|
||||
default:
|
||||
final codeName = _stringField(error, 'codeName') ?? 'gRPC $code';
|
||||
return FriendlyError(
|
||||
headline: '$codeName: ${detail.isEmpty ? l.errGeneric : detail}',
|
||||
detail: detail,
|
||||
hint: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
// Non-gRPC error (e.g. FormatException from a bad URL). Show
|
||||
// its toString — but as the headline, not buried in a wall.
|
||||
return FriendlyError(
|
||||
headline: error.toString(),
|
||||
detail: error.toString(),
|
||||
hint: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Try to read an `int` field by name off an arbitrary object.
|
||||
/// Returns `null` when the field doesn't exist or has another
|
||||
/// runtime type. Used to duck-type `GrpcError.code` without
|
||||
/// pulling package:grpc as a Studio dependency.
|
||||
int? _intField(Object obj, String field) {
|
||||
try {
|
||||
final dyn = obj as dynamic;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final v = (() {
|
||||
switch (field) {
|
||||
case 'code':
|
||||
return dyn.code;
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
return v is int ? v : null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String? _stringField(Object obj, String field) {
|
||||
try {
|
||||
final dyn = obj as dynamic;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final v = (() {
|
||||
switch (field) {
|
||||
case 'message':
|
||||
return dyn.message;
|
||||
case 'codeName':
|
||||
return dyn.codeName;
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
return v is String ? v : null;
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,13 +93,18 @@ class HubService {
|
|||
|
||||
Future<bool> healthy() => _client.healthy();
|
||||
|
||||
/// List of installed WASM modules, grouped by `module_name`.
|
||||
/// Built-in and federated capabilities are excluded — they
|
||||
/// don't correspond to a bundle on disk and would confuse the
|
||||
/// Modules page (a "system" or "via:filesystem" pseudo-module
|
||||
/// has nothing to uninstall). Callers that need every callable
|
||||
/// capability — e.g. the flow's missing-dependencies check —
|
||||
/// use [allCapabilities] instead.
|
||||
Future<List<ModuleSummary>> listModules() async {
|
||||
final caps = await _client.listCapabilities();
|
||||
|
||||
// Group capabilities by module so Studio's UI maps a card
|
||||
// to a module rather than a capability.
|
||||
final wasm = caps.where((c) => c.kind.isEmpty || c.kind == 'wasm');
|
||||
final byModule = <String, List<CapabilityEntry>>{};
|
||||
for (final c in caps) {
|
||||
for (final c in wasm) {
|
||||
byModule.putIfAbsent(c.moduleName, () => []).add(c);
|
||||
}
|
||||
return byModule.entries.map((e) {
|
||||
|
|
@ -115,6 +120,25 @@ class HubService {
|
|||
..sort((a, b) => a.name.compareTo(b.name));
|
||||
}
|
||||
|
||||
/// Every capability the hub can execute, with the `kind` tag
|
||||
/// telling apart wasm / builtin / federated. The flow page
|
||||
/// uses this to decide which capabilities are "already
|
||||
/// available" — including built-ins like `system.approval`
|
||||
/// and federated MCP / n8n tools — so the Run button enables
|
||||
/// when the dependency is reachable, not only when a bundle
|
||||
/// happens to be installed.
|
||||
Future<List<CapabilityInfo>> allCapabilities() async {
|
||||
final caps = await _client.listCapabilities();
|
||||
return caps
|
||||
.map((c) => CapabilityInfo(
|
||||
capability: c.capability,
|
||||
version: c.version,
|
||||
moduleName: c.moduleName,
|
||||
kind: c.kind.isEmpty ? 'wasm' : c.kind,
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Fully-detailed manifest for one installed module.
|
||||
Future<ModuleDetail> moduleInfo(String name) async {
|
||||
final r = await _client.moduleInfo(name);
|
||||
|
|
@ -126,6 +150,7 @@ class HubService {
|
|||
.toList(),
|
||||
permissions: r.permissions,
|
||||
directory: r.directory,
|
||||
acceptsMime: r.acceptsMime,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -834,6 +859,26 @@ enum ThemeModeValue {
|
|||
}
|
||||
}
|
||||
|
||||
/// Single capability with its provenance. `kind` is one of
|
||||
/// `wasm` (installed module), `builtin` (hub-internal, e.g.
|
||||
/// `system.approval`), or `federated` (MCP / n8n tool reachable
|
||||
/// through the bridge). UI uses `kind` to decide what actions
|
||||
/// to offer — only `wasm` capabilities have an install /
|
||||
/// uninstall affordance.
|
||||
class CapabilityInfo {
|
||||
final String capability;
|
||||
final String version;
|
||||
final String moduleName;
|
||||
final String kind;
|
||||
|
||||
const CapabilityInfo({
|
||||
required this.capability,
|
||||
required this.version,
|
||||
required this.moduleName,
|
||||
required this.kind,
|
||||
});
|
||||
}
|
||||
|
||||
/// UI-side type, decoupled from the proto wire type so pages
|
||||
/// don't import protobuf packages.
|
||||
class ModuleSummary {
|
||||
|
|
@ -872,6 +917,10 @@ class ModuleDetail {
|
|||
final List<String> capabilities;
|
||||
final List<String> permissions;
|
||||
final String directory;
|
||||
/// MIME allow-list declared in the module's `module.yaml`.
|
||||
/// Empty when the module didn't declare any — caller falls
|
||||
/// back to its built-in extension heuristic.
|
||||
final List<String> acceptsMime;
|
||||
|
||||
const ModuleDetail({
|
||||
required this.name,
|
||||
|
|
@ -879,6 +928,7 @@ class ModuleDetail {
|
|||
required this.capabilities,
|
||||
required this.permissions,
|
||||
required this.directory,
|
||||
this.acceptsMime = const [],
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue