Skip to content

Commit 02a23dd

Browse files
committed
Improve login UI
1 parent 037728b commit 02a23dd

15 files changed

Lines changed: 311 additions & 136 deletions

src/bridge/api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { resolveBaseUrl } from './utils';
1818

1919
export class EcaRemoteApi {
2020
private baseUrl: string;
21-
private token: string;
21+
private password: string;
2222

23-
constructor(host: string, token: string) {
23+
constructor(host: string, password: string) {
2424
this.baseUrl = resolveBaseUrl(host);
25-
this.token = token;
25+
this.password = password;
2626
}
2727

2828
// ---------------------------------------------------------------------------
@@ -31,7 +31,7 @@ export class EcaRemoteApi {
3131

3232
/** Build auth + optional JSON content-type headers. */
3333
private headers(json = false): HeadersInit {
34-
const h: HeadersInit = { 'Authorization': `Bearer ${this.token}` };
34+
const h: HeadersInit = { 'Authorization': `Bearer ${this.password}` };
3535
if (json) h['Content-Type'] = 'application/json';
3636
return h;
3737
}
@@ -219,8 +219,8 @@ export class EcaRemoteApi {
219219
return `${this.baseUrl}/events`;
220220
}
221221

222-
/** The auth token (needed by SSEClient to authenticate the stream). */
223-
get authToken(): string {
224-
return this.token;
222+
/** The auth password (needed by SSEClient to authenticate the stream). */
223+
get authPassword(): string {
224+
return this.password;
225225
}
226226
}

src/bridge/connection.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
* before establishing a full WebBridge connection.
44
*
55
* This is used by the ConnectForm to provide fast, specific error
6-
* messages (wrong host? wrong token?) before attempting the heavier
6+
* messages (wrong host? wrong password?) before attempting the heavier
77
* SSE connection.
88
*/
99

1010
import { fetchWithTimeout, resolveBaseUrl } from './utils';
1111

1212
/**
13-
* Test whether a host is reachable and the token is valid.
13+
* Test whether a host is reachable and the password is valid.
1414
*
1515
* Returns a human-readable error message on failure, or null on success.
1616
* Performs two sequential checks:
1717
* 1. Health endpoint (unauthenticated) — tests reachability
1818
* 2. Session endpoint (authenticated) — tests credentials
1919
*/
20-
export async function testConnection(host: string, token: string): Promise<string | null> {
20+
export async function testConnection(host: string, password: string): Promise<string | null> {
2121
const baseUrl = resolveBaseUrl(host);
2222

2323
// 1. Test host reachability (health endpoint — no auth)
@@ -38,11 +38,11 @@ export async function testConnection(host: string, token: string): Promise<strin
3838
// 2. Test authentication (session endpoint — requires auth)
3939
try {
4040
const res = await fetchWithTimeout(`${baseUrl}/session`, {
41-
headers: { 'Authorization': `Bearer ${token}` },
41+
headers: { 'Authorization': `Bearer ${password}` },
4242
});
4343
if (!res.ok) {
4444
return (res.status === 401 || res.status === 403)
45-
? 'Authentication failed. Check your password or token.'
45+
? 'Authentication failed. Check your password.'
4646
: `Session check failed (${res.status}).`;
4747
}
4848
} catch (err: any) {

src/bridge/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Usage:
88
* import { WebBridge } from '@/bridge';
9-
* const bridge = new WebBridge(host, token);
9+
* const bridge = new WebBridge(host, password);
1010
* await bridge.connect();
1111
*/
1212

src/bridge/outbound-handler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export interface OutboundContext {
2525
setCurrentChatId: (id: string) => void;
2626
/** Triggers initial state dispatch (called on webview/ready). */
2727
dispatchInitialState: () => Promise<void>;
28+
/** Lazy-load messages for a chat (fetches from server if not yet loaded). */
29+
loadChatMessages: (chatId: string) => Promise<void>;
2830
}
2931

3032
/**
@@ -179,11 +181,16 @@ export async function handleOutbound(
179181

180182
/**
181183
* Handle a user prompt: creates a new chat if no chatId is provided.
184+
* Ensures the chat messages are loaded before sending (handles the case
185+
* where a prompt targets a chat whose history hasn't been lazy-loaded yet).
182186
*/
183187
async function handleUserPrompt(data: UserPromptData, ctx: OutboundContext): Promise<void> {
184188
const chatId = data.chatId || crypto.randomUUID();
185189
ctx.setCurrentChatId(chatId);
186190

191+
// Ensure messages are loaded so the webview has full context
192+
await ctx.loadChatMessages(chatId);
193+
187194
await ctx.api.sendPrompt(chatId, {
188195
message: data.prompt,
189196
model: data.model,

src/bridge/sse.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface SSEClientOptions {
2727

2828
export class SSEClient {
2929
private url: string;
30-
private token: string;
30+
private password: string;
3131
private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;
3232
private abortController: AbortController | null = null;
3333
private onEvent: EventHandler;
@@ -39,14 +39,14 @@ export class SSEClient {
3939

4040
constructor(
4141
url: string,
42-
token: string,
42+
password: string,
4343
onEvent: EventHandler,
4444
onError: ErrorHandler,
4545
onDisconnect: () => void,
4646
options: SSEClientOptions = {},
4747
) {
4848
this.url = url;
49-
this.token = token;
49+
this.password = password;
5050
this.onEvent = onEvent;
5151
this.onError = onError;
5252
this.onDisconnect = onDisconnect;
@@ -59,7 +59,7 @@ export class SSEClient {
5959
this.abortController = new AbortController();
6060

6161
const response = await fetch(this.url, {
62-
headers: { 'Authorization': `Bearer ${this.token}` },
62+
headers: { 'Authorization': `Bearer ${this.password}` },
6363
signal: this.abortController.signal,
6464
});
6565

0 commit comments

Comments
 (0)