Contratto condiviso per collegamento, vista remota e problemi di configurazione
verifica / prove (push) Successful in 5m40s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 19:20:19 +00:00
1 parent d8b181eb16
commit 0515776b04
3 files changed
+127

No files matched your search

@@ -0,0 +1,23 @@
namespace Febe.Web.Connection;
/// <summary>A configuration problem that keeps the engine from starting (spec §8.2, §11). Texts in Italian.</summary>
/// <param name="Code">Stable code, e.g. "password-mancante", "dati-non-scrivibili", "dati-in-rete", "webview2-assente".</param>
/// <param name="Title">What is wrong.</param>
/// <param name="Message">What Febe did (the engine did not start) and why.</param>
/// <param name="Remedy">What Alberto must do.</param>
public sealed record ConfigurationProblem(string Code, string Title, string Message, string Remedy);
/// <summary>
/// Problems found at startup. When the list is not empty the interface shows only the page that explains them
/// (field <c>problems</c> of <c>GET /api/capabilities</c>) and <c>/salute</c> answers 503.
/// </summary>
public interface IConfigurationProblems
{
IReadOnlyList<ConfigurationProblem> Current { get; }
}
/// <summary>No problems (default registration).</summary>
public sealed class NoConfigurationProblems : IConfigurationProblems
{
public IReadOnlyList<ConfigurationProblem> Current => [];
}
@@ -0,0 +1,60 @@
namespace Febe.Web.Connection;
/// <summary>State of the link to Instagram shown at the bottom of the sidebar and on the Collegamento page (spec §4.1).</summary>
public enum ConnectionState
{
/// <summary>No session in the browser profile: «Non collegato».</summary>
NotConnected,
/// <summary>Session cookie present: «Collegato».</summary>
Connected,
/// <summary>The engine stopped for a challenge or a disconnection: «Verifica richiesta».</summary>
VerificationRequired,
/// <summary>The browser is not available (starting, crashed, demo without browser).</summary>
BrowserUnavailable,
}
/// <summary>What the interface knows about the link to Instagram.</summary>
/// <param name="State">Current state.</param>
/// <param name="Username">Connected account (from the data the page received, hypothesis H10), when known.</param>
/// <param name="DisplayName">Display name, when known.</param>
/// <param name="UserIsDriving">True while Alberto is using the browser (login page, remote view, browser window): the engine is still.</param>
/// <param name="CurrentUrl">Address shown in the remote view's address bar, without query string.</param>
public sealed record ConnectionStatus(
ConnectionState State,
string? Username,
string? DisplayName,
bool UserIsDriving,
string? CurrentUrl);
/// <summary>Result of «Ho finito» on the Collegamento page.</summary>
/// <param name="Connected">True when the session cookie now exists.</param>
/// <param name="Message">Italian message for the page (what happened, what Febe did, what Alberto should do).</param>
public sealed record FinishResult(bool Connected, string Message);
/// <summary>
/// The link to Instagram (spec §4.1, §10.3 «Collegamento» and «Browser» pages). Implemented by the server/desktop
/// composition over the real browser host, and by the demo mode with a fake driven by the scene.
/// Opening the login page here is not an engine action (rule 7): Alberto is using the browser and the engine is still.
/// </summary>
public interface IConnectionService
{
Task<ConnectionStatus> GetStatusAsync(CancellationToken ct);
/// <summary>
/// Alberto starts using the browser: the engine stops acting (UserIsDriving), and when <paramref name="openLogin"/>
/// is true the browser loads the real Instagram login page. Windows: the browser window is brought to the front.
/// </summary>
Task BeginUserDrivingAsync(bool openLogin, CancellationToken ct);
/// <summary>«Ho finito»: checks that the session cookie exists (value never read), hides the browser, ends user driving.</summary>
Task<FinishResult> FinishAsync(CancellationToken ct);
/// <summary>«Annulla»: ends user driving and puts the browser on the empty rest page.</summary>
Task CancelAsync(CancellationToken ct);
/// <summary>«Scollega» (after confirmation in the UI): stops the engine and deletes the browser profile.</summary>
Task DisconnectAsync(CancellationToken ct);
}
+44
View File
@@ -0,0 +1,44 @@
# Collegamento, vista remota e problemi di configurazione
Contratto fra l'interfaccia (pagine Collegamento, Browser, errore di configurazione) e la composizione del server.
Lo usano due parti scritte in parallelo: non cambiarlo senza aggiornare entrambe.
## Collegamento (`IConnectionService`)
| Endpoint | Corpo e risposta |
|---|---|
| `GET /api/connection` | `{ state: "notConnected"\|"connected"\|"verificationRequired"\|"browserUnavailable", username, displayName, userIsDriving, currentUrl }` |
| `POST /api/connection/begin` | `{ openLogin: bool }` → 204. Alberto usa il browser; con `openLogin` il browser carica la pagina di accesso vera |
| `POST /api/connection/finish` | → `{ connected: bool, message }` («Ho finito») |
| `POST /api/connection/cancel` | → 204 («Annulla») |
| `POST /api/connection/disconnect` | → 204 («Scollega», dopo la conferma nell'interfaccia) |
In modalità dimostrativa la scena `scollegato` dà `notConnected`, la scena `fermo` dà `verificationRequired`.
## Vista remota (`/api/vista`, solo veste Docker)
WebSocket sullo stesso host dell'interfaccia; si apre solo da una sessione autenticata e con `Origin` uguale
all'host (§13.1). Aprirla mette il motore fermo (`UserIsDriving`); chiuderla lo libera.
Dal server al browser di Alberto:
- messaggio di testo `{ "type": "meta", "width": 1280, "height": 900, "url": "https://www.instagram.com/accounts/login/" }`
all'apertura e a ogni cambio di indirizzo o dimensione (l'indirizzo senza parametri di ricerca);
- messaggi binari: un fotogramma JPEG ciascuno (da `Page.startScreencast`), da disegnare su un `<canvas>`.
Dal browser di Alberto al server, solo messaggi di testo JSON:
- `{ "type": "mouse", "action": "move"|"down"|"up"|"wheel", "x": 0..1, "y": 0..1, "button": "left"|"right"|"middle", "deltaX": n, "deltaY": n, "clickCount": n }`
con coordinate relative al fotogramma;
- `{ "type": "key", "action": "down"|"up"|"char", "key": "a", "code": "KeyA", "text": "a", "modifiers": n }`
(i tasti non si registrano mai, né sul server né nel browser di Alberto);
- `{ "type": "navigate", "action": "back"|"reload" }`.
## Problemi di configurazione
`GET /api/capabilities` ha il campo `problems`: elenco di `{ code, title, message, remedy }` in italiano.
Se non è vuoto il motore non parte e l'interfaccia mostra solo la pagina che spiega il problema (§8.2, §11):
password mancante (`FEBE_PASSWORD`), cartella dei dati non scrivibile o su un disco di rete, runtime WebView2 assente
(Windows). In modalità dimostrativa la scena `errore` ne simula uno.
`GET /salute` (senza autenticazione) risponde `200 {"stato":"ok"}` o `503 {"stato":"problema"}`, senza altri dettagli.