clay-server 4.7.1-beta.4 → 4.8.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/login-browser-open.js +7 -0
- package/lib/project-vendor-login.js +52 -18
- package/lib/project.js +3 -0
- package/lib/public/app.js +1 -0
- package/lib/public/css/vendor-login-browser.css +63 -0
- package/lib/public/modules/app-messages.js +5 -0
- package/lib/public/modules/app-notifications.js +1 -1
- package/lib/public/modules/vendor-login-browser.js +243 -0
- package/lib/public/modules/vendor-login.js +23 -4
- package/lib/public/style.css +1 -0
- package/lib/terminal.js +4 -0
- package/lib/vendor-login-browser-flow.js +46 -0
- package/lib/vendor-login-browser-passkeys.js +27 -0
- package/lib/vendor-login-browser-worker.js +149 -0
- package/lib/vendor-login-browser.js +162 -0
- package/lib/ws-schema.js +4 -0
- package/lib/yoke/adapters/codex.js +55 -8
- package/lib/yoke/codex-idle-recovery.js +52 -0
- package/package.json +2 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Capture the CLI's exact OAuth URL without opening a browser on the host desktop.
|
|
3
|
+
var fs = require("fs");
|
|
4
|
+
var file = process.env.CLAY_LOGIN_URL_FILE;
|
|
5
|
+
var url = process.argv[2];
|
|
6
|
+
if (!file || !url || url.length > 16384) process.exit(1);
|
|
7
|
+
fs.writeFileSync(file, url, { mode: 0o600 });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Vendor login flow coordinator.
|
|
2
2
|
//
|
|
3
3
|
// Owns the "the vendor CLI is not logged in" recovery path end to end so the
|
|
4
|
-
// client never has to guess. One login terminal per vendor per
|
|
4
|
+
// client never has to guess. One login terminal per vendor per requester is the
|
|
5
5
|
// single source of truth: repeated auth_required events (other sessions, split
|
|
6
6
|
// panes, a burst of 401 retries) re-use that record instead of spawning more
|
|
7
7
|
// terminals.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// command, reply with vendor_login_ready
|
|
12
12
|
// PTY output/exit -> detect a successful login, restart the vendor's
|
|
13
13
|
// YOKE adapter so it re-reads the credential file,
|
|
14
|
-
//
|
|
14
|
+
// send auth_refreshed, close the terminal and browser
|
|
15
15
|
// vendor_login_cancel -> user dismissed the flow; kill the terminal
|
|
16
16
|
//
|
|
17
17
|
// The adapter restart is the actual bug fix: a Codex app-server is a long-lived
|
|
@@ -84,10 +84,20 @@ function attachVendorLogin(ctx) {
|
|
|
84
84
|
var getLinuxUserForSession = ctx.getLinuxUserForSession;
|
|
85
85
|
var refreshVendorAuthEverywhere = ctx.refreshVendorAuthEverywhere;
|
|
86
86
|
|
|
87
|
-
// vendor -> flow
|
|
87
|
+
// Requester + vendor -> flow. Credentials and sign-in views stay user-bound.
|
|
88
88
|
var _flows = Object.create(null);
|
|
89
|
+
function flowKey(ws, vendor) {
|
|
90
|
+
return JSON.stringify([ws && ws._clayUser ? String(ws._clayUser.id) : null, vendor]);
|
|
91
|
+
}
|
|
92
|
+
var browserLogin = require("./vendor-login-browser-flow").attachBrowserLogin({
|
|
93
|
+
osUsers: osUsers, sendTo: sendTo, hasTerminalPermission: hasTerminalPermission,
|
|
94
|
+
createLoginBrowser: ctx.createLoginBrowser,
|
|
95
|
+
flowKey: flowKey,
|
|
96
|
+
cancel: function (vendor) { closeFlowTerminal(discardFlow(vendor)); broadcastState(); },
|
|
97
|
+
});
|
|
89
98
|
|
|
90
99
|
function loginCommandFor(vendor) {
|
|
100
|
+
if (vendor === "claude") return "claude auth login";
|
|
91
101
|
var info = vendorRegistry.getVendorInfo(vendor);
|
|
92
102
|
return (info && info.loginCommand) || "claude login";
|
|
93
103
|
}
|
|
@@ -97,30 +107,34 @@ function attachVendorLogin(ctx) {
|
|
|
97
107
|
return (info && info.displayName) || vendor || "Vendor";
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
function listFlows() {
|
|
110
|
+
function listFlows(ws) {
|
|
101
111
|
var result = [];
|
|
102
112
|
var vendors = Object.keys(_flows);
|
|
103
113
|
for (var i = 0; i < vendors.length; i++) {
|
|
104
114
|
var flow = _flows[vendors[i]];
|
|
115
|
+
if (ws && flowKey(ws, flow.vendor) !== vendors[i]) continue;
|
|
105
116
|
result.push({
|
|
106
117
|
vendor: flow.vendor,
|
|
107
118
|
terminalId: flow.terminalId,
|
|
108
119
|
startedAt: flow.startedAt,
|
|
109
120
|
completed: !!flow.completed,
|
|
121
|
+
browserId: flow.browser ? flow.browser.id : null,
|
|
110
122
|
});
|
|
111
123
|
}
|
|
112
124
|
return result;
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
function broadcastState() {
|
|
128
|
+
if (ctx.clients) { ctx.clients.forEach(sendStateTo); return; }
|
|
116
129
|
send({ type: "vendor_login_state", slug: slug, flows: listFlows() });
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
function sendStateTo(ws) {
|
|
120
|
-
sendTo(ws, { type: "vendor_login_state", slug: slug, flows: listFlows() });
|
|
133
|
+
sendTo(ws, { type: "vendor_login_state", slug: slug, flows: hasTerminalPermission(ws) ? listFlows(ws) : [] });
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
function hasTerminalPermission(ws) {
|
|
137
|
+
if (ctx.requestAccess) return ctx.requestAccess.canAccessProject(ws, slug) && ctx.requestAccess.hasPermission(ws, "terminal");
|
|
124
138
|
if (!ws || !ws._clayUser) return true;
|
|
125
139
|
if (!usersModule || typeof usersModule.getEffectivePermissions !== "function") return true;
|
|
126
140
|
var perms = usersModule.getEffectivePermissions(ws._clayUser, osUsers);
|
|
@@ -164,6 +178,8 @@ function attachVendorLogin(ctx) {
|
|
|
164
178
|
var flow = _flows[vendor];
|
|
165
179
|
if (!flow) return null;
|
|
166
180
|
delete _flows[vendor];
|
|
181
|
+
if (flow.browser) flow.browser.close();
|
|
182
|
+
if (flow.expiryTimer) clearTimeout(flow.expiryTimer);
|
|
167
183
|
if (flow.closeTimer) {
|
|
168
184
|
clearTimeout(flow.closeTimer);
|
|
169
185
|
flow.closeTimer = null;
|
|
@@ -223,14 +239,17 @@ function attachVendorLogin(ctx) {
|
|
|
223
239
|
var refresh = Promise.resolve(false);
|
|
224
240
|
if (succeeded) {
|
|
225
241
|
refresh = typeof refreshVendorAuthEverywhere === "function"
|
|
226
|
-
? refreshVendorAuthEverywhere(vendor, flow.linuxUser || null)
|
|
227
|
-
: refreshVendorAuth(vendor, flow.linuxUser || null);
|
|
242
|
+
? refreshVendorAuthEverywhere(flow.vendor, flow.linuxUser || null)
|
|
243
|
+
: refreshVendorAuth(flow.vendor, flow.linuxUser || null);
|
|
228
244
|
}
|
|
229
245
|
refresh.then(function (restarted) {
|
|
246
|
+
if (_flows[vendor] !== flow) return;
|
|
230
247
|
discardFlow(vendor);
|
|
231
248
|
closeFlowTerminal(flow);
|
|
232
249
|
if (succeeded) {
|
|
233
|
-
|
|
250
|
+
var message = { type: "auth_refreshed", slug: slug, vendor: flow.vendor, adapterRestarted: !!restarted };
|
|
251
|
+
if (ctx.clients) ctx.clients.forEach(function (ws) { if (flowKey(ws, flow.vendor) === vendor && hasTerminalPermission(ws)) sendTo(ws, message); });
|
|
252
|
+
else send(message);
|
|
234
253
|
}
|
|
235
254
|
broadcastState();
|
|
236
255
|
});
|
|
@@ -240,10 +259,11 @@ function attachVendorLogin(ctx) {
|
|
|
240
259
|
var flow = _flows[vendor];
|
|
241
260
|
if (!flow || flow.finishing || flow.succeeded) return;
|
|
242
261
|
flow.outputTail = (flow.outputTail + stripAnsi(chunk)).slice(-OUTPUT_TAIL_MAX);
|
|
262
|
+
if (flow.browser) flow.browser.output(stripAnsi(chunk));
|
|
243
263
|
if (!looksLikeLoginSuccess(flow.outputTail)) return;
|
|
244
264
|
|
|
245
265
|
flow.succeeded = true;
|
|
246
|
-
console.log("[vendor-login] Detected successful " + vendor + " login in " + slug);
|
|
266
|
+
console.log("[vendor-login] Detected successful " + flow.vendor + " login in " + slug);
|
|
247
267
|
// Let the success line land on screen before the terminal disappears.
|
|
248
268
|
flow.closeTimer = setTimeout(function () {
|
|
249
269
|
finishFlow(vendor, true);
|
|
@@ -261,10 +281,15 @@ function attachVendorLogin(ctx) {
|
|
|
261
281
|
}
|
|
262
282
|
|
|
263
283
|
function startFlow(ws, vendor, msg) {
|
|
284
|
+
var key = flowKey(ws, vendor);
|
|
264
285
|
var identity = resolveLoginIdentity(ws, msg);
|
|
265
286
|
var command = loginCommandFor(vendor);
|
|
287
|
+
var browserMode = msg.mode === "browser" && (vendor === "claude" || vendor === "codex");
|
|
288
|
+
if (browserMode) command = vendor === "codex" ? "codex login" : "claude auth login";
|
|
266
289
|
var flow = {
|
|
267
290
|
vendor: vendor,
|
|
291
|
+
key: key,
|
|
292
|
+
ownerId: ws && ws._clayUser ? String(ws._clayUser.id) : null,
|
|
268
293
|
terminalId: null,
|
|
269
294
|
startedAt: Date.now(),
|
|
270
295
|
linuxUser: identity.linuxUser,
|
|
@@ -277,16 +302,18 @@ function attachVendorLogin(ctx) {
|
|
|
277
302
|
};
|
|
278
303
|
// Registered before create() so the PTY's first output chunk (hooks fire
|
|
279
304
|
// synchronously from spawn) already finds the record.
|
|
280
|
-
_flows[
|
|
305
|
+
_flows[key] = flow;
|
|
281
306
|
|
|
282
307
|
var terminal = null;
|
|
283
308
|
try {
|
|
309
|
+
if (browserMode) browserLogin.prepare(ws, flow, identity);
|
|
284
310
|
terminal = tm.create(100, 30, identity.osUserInfo, ws, {
|
|
285
311
|
initialInput: command + "\n",
|
|
286
312
|
title: vendorDisplayName(vendor) + " login",
|
|
287
313
|
kind: "vendor-login",
|
|
288
|
-
|
|
289
|
-
|
|
314
|
+
loginBrowserEnv: flow.browser ? flow.browser.env : null,
|
|
315
|
+
onData: function (data) { if (_flows[key] === flow) handleFlowOutput(key, data); },
|
|
316
|
+
onExit: function () { if (_flows[key] === flow) handleFlowExit(key); },
|
|
290
317
|
});
|
|
291
318
|
} catch (e) {
|
|
292
319
|
console.error("[vendor-login] Failed to spawn " + vendor + " login terminal in " + slug + ":",
|
|
@@ -294,17 +321,18 @@ function attachVendorLogin(ctx) {
|
|
|
294
321
|
}
|
|
295
322
|
|
|
296
323
|
if (!terminal) {
|
|
297
|
-
|
|
324
|
+
discardFlow(key);
|
|
298
325
|
return null;
|
|
299
326
|
}
|
|
300
327
|
|
|
301
328
|
flow.terminalId = terminal.id;
|
|
302
|
-
tm.attach(terminal.id, ws);
|
|
329
|
+
if (!flow.browser) tm.attach(terminal.id, ws);
|
|
303
330
|
send({ type: "term_list", terminals: tm.list() });
|
|
304
331
|
return flow;
|
|
305
332
|
}
|
|
306
333
|
|
|
307
334
|
function handleVendorLoginMessage(ws, msg) {
|
|
335
|
+
if (browserLogin.handle(ws, msg, _flows)) return true;
|
|
308
336
|
if (msg.type === "vendor_login_state_request") {
|
|
309
337
|
sendStateTo(ws);
|
|
310
338
|
return true;
|
|
@@ -312,7 +340,7 @@ function attachVendorLogin(ctx) {
|
|
|
312
340
|
|
|
313
341
|
if (msg.type === "vendor_login_cancel") {
|
|
314
342
|
var cancelVendor = String(msg.vendor || "");
|
|
315
|
-
var cancelled = discardFlow(cancelVendor);
|
|
343
|
+
var cancelled = discardFlow(flowKey(ws, cancelVendor));
|
|
316
344
|
if (cancelled) closeFlowTerminal(cancelled);
|
|
317
345
|
broadcastState();
|
|
318
346
|
return true;
|
|
@@ -329,10 +357,11 @@ function attachVendorLogin(ctx) {
|
|
|
329
357
|
return true;
|
|
330
358
|
}
|
|
331
359
|
|
|
332
|
-
var
|
|
360
|
+
var key = flowKey(ws, vendor);
|
|
361
|
+
var existing = _flows[key];
|
|
333
362
|
if (existing && !isFlowTerminalAlive(existing)) {
|
|
334
363
|
// Terminal died without its exit hook clearing the record.
|
|
335
|
-
discardFlow(
|
|
364
|
+
discardFlow(key);
|
|
336
365
|
existing = null;
|
|
337
366
|
}
|
|
338
367
|
|
|
@@ -341,13 +370,14 @@ function attachVendorLogin(ctx) {
|
|
|
341
370
|
// session or split pane) must not pop a second prompt; it only learns
|
|
342
371
|
// that a flow is already running. A deliberate request re-attaches.
|
|
343
372
|
if (!msg.auto) {
|
|
344
|
-
tm.attach(existing.terminalId, ws);
|
|
373
|
+
if (!existing.browser) tm.attach(existing.terminalId, ws);
|
|
345
374
|
sendTo(ws, {
|
|
346
375
|
type: "vendor_login_ready",
|
|
347
376
|
slug: slug,
|
|
348
377
|
vendor: vendor,
|
|
349
378
|
terminalId: existing.terminalId,
|
|
350
379
|
reused: true,
|
|
380
|
+
browserId: existing.browser ? existing.browser.id : null,
|
|
351
381
|
});
|
|
352
382
|
}
|
|
353
383
|
sendStateTo(ws);
|
|
@@ -371,6 +401,7 @@ function attachVendorLogin(ctx) {
|
|
|
371
401
|
vendor: vendor,
|
|
372
402
|
terminalId: started.terminalId,
|
|
373
403
|
reused: false,
|
|
404
|
+
browserId: started.browser ? started.browser.id : null,
|
|
374
405
|
});
|
|
375
406
|
broadcastState();
|
|
376
407
|
return true;
|
|
@@ -408,6 +439,9 @@ function attachVendorLogin(ctx) {
|
|
|
408
439
|
forgetTerminal: forgetTerminal,
|
|
409
440
|
isLoginTerminal: isLoginTerminal,
|
|
410
441
|
refreshVendorAuth: refreshVendorAuth,
|
|
442
|
+
destroy: function () {
|
|
443
|
+
Object.keys(_flows).forEach(function (vendor) { closeFlowTerminal(discardFlow(vendor)); });
|
|
444
|
+
},
|
|
411
445
|
};
|
|
412
446
|
}
|
|
413
447
|
|
package/lib/project.js
CHANGED
|
@@ -2204,6 +2204,8 @@ function createProjectContext(opts) {
|
|
|
2204
2204
|
|
|
2205
2205
|
// --- Vendor login flow (delegated to project-vendor-login.js) ---
|
|
2206
2206
|
var _vendorLogin = attachVendorLogin({
|
|
2207
|
+
requestAccess: _requestAccess,
|
|
2208
|
+
clients: clients,
|
|
2207
2209
|
slug: slug,
|
|
2208
2210
|
osUsers: osUsers,
|
|
2209
2211
|
sm: sm,
|
|
@@ -2600,6 +2602,7 @@ function createProjectContext(opts) {
|
|
|
2600
2602
|
|
|
2601
2603
|
// --- Destroy ---
|
|
2602
2604
|
function destroy() {
|
|
2605
|
+
_vendorLogin.destroy();
|
|
2603
2606
|
if (_scheduledMessages) _scheduledMessages.shutdown();
|
|
2604
2607
|
if (_autonomousRun) _autonomousRun.shutdown();
|
|
2605
2608
|
_splitGroups.shutdown();
|
package/lib/public/app.js
CHANGED
|
@@ -268,6 +268,7 @@ import { initDebate, handleDebatePreparing, handleDebateStarted, handleDebateRes
|
|
|
268
268
|
// --- Initialize store (single source of truth for client state) ---
|
|
269
269
|
createStore({
|
|
270
270
|
networkSettings: { loaded: false, busy: false, confirming: false, draft: "", saved: "", status: "", errorKind: "", requestId: 0 },
|
|
271
|
+
vendorLoginBrowser: null,
|
|
271
272
|
// session / routing
|
|
272
273
|
basePath: basePath,
|
|
273
274
|
wsPath: wsPath,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.login-browser {
|
|
2
|
+
width: min(820px, calc(100vw - 48px));
|
|
3
|
+
height: min(780px, calc(100dvh - 48px));
|
|
4
|
+
max-width: none;
|
|
5
|
+
max-height: none;
|
|
6
|
+
padding: 0;
|
|
7
|
+
margin: auto;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
border: 1px solid var(--border);
|
|
10
|
+
border-radius: 16px;
|
|
11
|
+
background: var(--bg);
|
|
12
|
+
color: var(--text);
|
|
13
|
+
box-shadow: 0 32px 100px #0005, 0 4px 16px #0003;
|
|
14
|
+
}
|
|
15
|
+
.login-browser[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
|
|
16
|
+
.login-browser::backdrop { background: #0007; backdrop-filter: blur(6px); }
|
|
17
|
+
.login-browser-header { display: flex; align-items: center; gap: 12px; padding: 17px 20px; border-bottom: 1px solid var(--border); }
|
|
18
|
+
.login-browser-vendor { width: 34px; height: 34px; border-radius: 9px; object-fit: cover; }
|
|
19
|
+
.login-browser-heading { flex: 1; min-width: 0; }
|
|
20
|
+
.login-browser h2 { font-size: 15px; line-height: 1.4; font-weight: 600; letter-spacing: -.015em; margin: 0; }
|
|
21
|
+
.login-browser-origin { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; font-size: 11px; line-height: 1.5; color: var(--text-dimmer); }
|
|
22
|
+
.login-browser-actions { display: flex; align-items: center; gap: 3px; }
|
|
23
|
+
.login-browser button, .login-browser-more summary { font: inherit; cursor: pointer; color: var(--text-muted, var(--text)); }
|
|
24
|
+
.login-browser button { border: 0; background: transparent; }
|
|
25
|
+
.login-browser svg { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.6; }
|
|
26
|
+
.login-browser .login-browser-icon, .login-browser-more summary { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border-radius: 7px; }
|
|
27
|
+
.login-browser button:hover, .login-browser-more summary:hover { background: var(--bg-alt); color: var(--text); }
|
|
28
|
+
.login-browser button:focus-visible, .login-browser-more summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
29
|
+
.login-browser .login-browser-keyboard-button { display: none; }
|
|
30
|
+
.login-browser-more { position: relative; }
|
|
31
|
+
.login-browser-more summary { list-style: none; }
|
|
32
|
+
.login-browser-more summary::-webkit-details-marker { display: none; }
|
|
33
|
+
.login-browser-menu { position: absolute; right: 0; top: 39px; z-index: 3; width: 180px; padding: 5px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); box-shadow: 0 8px 28px #0003; }
|
|
34
|
+
.login-browser-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 10px; border-radius: 6px; font-size: 12px; text-align: left; }
|
|
35
|
+
.login-browser-viewport { position: relative; min-height: 0; overflow: hidden; background: #fff; line-height: 0; }
|
|
36
|
+
.login-browser canvas { display: block; width: 100%; height: 100%; object-fit: contain; touch-action: none; }
|
|
37
|
+
.login-browser-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--bg-alt); color: var(--text-dimmer); font-size: 12px; line-height: 1.5; }
|
|
38
|
+
.login-browser-loading strong { font-size: 14px; font-weight: 500; color: var(--text); }
|
|
39
|
+
.login-browser-loading[hidden] { display: none; }
|
|
40
|
+
.login-browser-spinner { width: 22px; height: 22px; margin-bottom: 8px; border: 2px solid var(--border); border-top-color: var(--text-dimmer); border-radius: 50%; animation: login-browser-spin .9s linear infinite; }
|
|
41
|
+
.login-browser-keyboard { position: absolute; width: 1px; height: 1px; padding: 0; border: 0; bottom: 0; left: 50%; opacity: 0; font-size: 16px; }
|
|
42
|
+
.login-browser-footer { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 18px; border-top: 1px solid var(--border); }
|
|
43
|
+
.login-browser-info { min-width: 0; }
|
|
44
|
+
.login-browser-status { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
45
|
+
.login-browser-status-dot { width: 5px; height: 5px; flex-shrink: 0; border-radius: 50%; background: var(--text-dimmer); }
|
|
46
|
+
.login-browser[data-phase="error"] .login-browser-status-dot { background: var(--warning, #d69c51); }
|
|
47
|
+
.login-browser-footer p { margin: 0; font-size: 11px; color: var(--text-dimmer); line-height: 1.5; }
|
|
48
|
+
.login-browser-footer .login-browser-privacy { margin-top: 5px; color: var(--text-muted, var(--text)); }
|
|
49
|
+
.login-browser .login-browser-terminal { display: inline-flex; align-items: center; justify-content: center; gap: 7px; flex-shrink: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 11px; font-weight: 500; color: var(--text); }
|
|
50
|
+
.login-browser-terminal svg:last-child { width: 12px; height: 12px; color: var(--text-dimmer); }
|
|
51
|
+
@keyframes login-browser-spin { to { transform: rotate(360deg); } }
|
|
52
|
+
@media (max-width: 600px) {
|
|
53
|
+
.login-browser { width: 100vw; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
|
|
54
|
+
.login-browser-header { padding: max(12px, env(safe-area-inset-top)) 12px 12px; gap: 9px; }
|
|
55
|
+
.login-browser-vendor { width: 30px; height: 30px; border-radius: 8px; }
|
|
56
|
+
.login-browser h2 { font-size: 14px; }
|
|
57
|
+
.login-browser .login-browser-keyboard-button { display: flex; }
|
|
58
|
+
.login-browser-footer { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 12px max(12px, env(safe-area-inset-bottom)); }
|
|
59
|
+
.login-browser-status { justify-content: center; }
|
|
60
|
+
.login-browser-privacy { text-align: center; }
|
|
61
|
+
.login-browser .login-browser-terminal { min-height: 40px; font-size: 12px; }
|
|
62
|
+
}
|
|
63
|
+
@media (prefers-reduced-motion: reduce) { .login-browser-spinner { animation: none; } }
|
|
@@ -92,6 +92,7 @@ import { handleSkillInstallWs } from './app-skills-install.js';
|
|
|
92
92
|
import { handleNotificationsState, handleNotificationCreated, handleNotificationDismissed, handleNotificationDismissedAll, showUpdateBanner } from './app-notifications.js';
|
|
93
93
|
import { handleUpdateSnoozed } from './update-snooze.js';
|
|
94
94
|
import { autoStartLoginIfNeeded, handleVendorLoginReady, handleVendorLoginState, handleVendorLoginError, handleAuthRefreshed } from './vendor-login.js';
|
|
95
|
+
import { handleLoginBrowserMessage } from './vendor-login-browser.js';
|
|
95
96
|
import { handleDebatePreparing, handleDebateBriefReady, renderDebateBriefReady, handleDebateStarted, renderDebateStarted, handleDebateTurn, handleDebateActivity, handleDebateStream, handleDebateTurnDone, handleDebateCommentQueued, handleDebateCommentInjected, renderDebateCommentInjected, handleDebateResumed, handleDebateEnded, renderDebateEnded, handleDebateError, isDebateActive, renderMcpDebateProposal, renderDebateUserResume } from './debate.js';
|
|
96
97
|
import { handleMentionStart, handleMentionActivity, handleMentionStream, handleMentionDone, handleMentionError, renderMentionUser, renderMentionResponse, renderUserMention } from './mention.js';
|
|
97
98
|
|
|
@@ -103,6 +104,10 @@ var connectOverlay = document.getElementById("connect-overlay");
|
|
|
103
104
|
initMessageDeliveryUi();
|
|
104
105
|
|
|
105
106
|
export function processMessage(msg) {
|
|
107
|
+
if (msg.type === "vendor_login_browser_frame" || msg.type === "vendor_login_browser_status") {
|
|
108
|
+
handleLoginBrowserMessage(msg);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
106
111
|
if (handleIssuesMessage(msg)) return;
|
|
107
112
|
if (handleAutonomousRunMessage(msg)) return;
|
|
108
113
|
if (handleLoopInterviewMessage(msg)) return;
|
|
@@ -170,7 +170,7 @@ function showBanner(notif, autoDismissMs) {
|
|
|
170
170
|
} else if (isAuthRequired) {
|
|
171
171
|
actionsHtml =
|
|
172
172
|
'<div class="notif-banner-actions">' +
|
|
173
|
-
'<button class="notif-banner-auth-login notif-banner-update-now">
|
|
173
|
+
'<button class="notif-banner-auth-login notif-banner-update-now">Sign in</button>' +
|
|
174
174
|
'</div>';
|
|
175
175
|
} else if (isTuiAttention) {
|
|
176
176
|
actionsHtml =
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { store } from './store.js';
|
|
2
|
+
import { getWs } from './ws-ref.js';
|
|
3
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
4
|
+
import { cancelVendorLogin, requestVendorLogin } from './vendor-login.js';
|
|
5
|
+
|
|
6
|
+
function current() { return store.get('vendorLoginBrowser'); }
|
|
7
|
+
|
|
8
|
+
function send(type, extra) {
|
|
9
|
+
var view = current();
|
|
10
|
+
var ws = getWs();
|
|
11
|
+
if (!view || view.slug !== store.get('currentSlug') || !ws || ws.readyState !== 1) return;
|
|
12
|
+
ws.send(JSON.stringify(Object.assign({ type: type, vendor: view.vendor, browserId: view.browserId }, extra || {})));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function input(event) { send("vendor_login_browser_input", { event: event }); }
|
|
16
|
+
|
|
17
|
+
export function closeLoginBrowser() {
|
|
18
|
+
var view = current();
|
|
19
|
+
if (view && view.resizeObserver) view.resizeObserver.disconnect();
|
|
20
|
+
if (view && view.moveTimer) clearTimeout(view.moveTimer);
|
|
21
|
+
store.set({ vendorLoginBrowser: null });
|
|
22
|
+
var dialog = document.getElementById("vendor-login-browser");
|
|
23
|
+
if (dialog) { dialog.close(); dialog.remove(); }
|
|
24
|
+
if (view && view.previousFocus && view.previousFocus.isConnected) view.previousFocus.focus();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function openLoginBrowser(msg) {
|
|
28
|
+
var existing = current();
|
|
29
|
+
if (existing && existing.browserId === msg.browserId) {
|
|
30
|
+
send("vendor_login_browser_attach");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
closeLoginBrowser();
|
|
34
|
+
var title = msg.vendor === "codex" ? "Sign in to Codex" : "Sign in to Claude";
|
|
35
|
+
store.set({ vendorLoginBrowser: {
|
|
36
|
+
browserId: msg.browserId, vendor: msg.vendor, slug: msg.slug || store.get('currentSlug'),
|
|
37
|
+
previousFocus: document.activeElement, decoding: false, pointerY: null, pointerId: null, mouseDown: false, moveTimer: null, pendingMove: null, resizeObserver: null, requestedSize: null, phase: "loading",
|
|
38
|
+
} });
|
|
39
|
+
var dialog = document.createElement("dialog");
|
|
40
|
+
dialog.id = "vendor-login-browser";
|
|
41
|
+
dialog.className = "login-browser";
|
|
42
|
+
dialog.setAttribute("aria-labelledby", "login-browser-title");
|
|
43
|
+
dialog.innerHTML = '<header class="login-browser-header">' +
|
|
44
|
+
'<img class="login-browser-vendor" src="/' + (msg.vendor === "codex" ? 'codex-avatar.png' : 'claude-code-avatar.png') + '" alt="">' +
|
|
45
|
+
'<div class="login-browser-heading"><h2 id="login-browser-title"></h2>' +
|
|
46
|
+
'<span class="login-browser-origin">Opening sign-in page…</span></div>' +
|
|
47
|
+
'<div class="login-browser-actions">' +
|
|
48
|
+
'<button type="button" data-action="keyboard" class="login-browser-icon login-browser-keyboard-button" aria-label="Show keyboard" title="Show keyboard">' + iconHtml("keyboard") + '</button>' +
|
|
49
|
+
'<button type="button" data-action="reload" class="login-browser-icon" aria-label="Reload page" title="Reload page">' + iconHtml("rotate-cw") + '</button>' +
|
|
50
|
+
'<details class="login-browser-more"><summary aria-label="More sign-in options" title="More sign-in options">' + iconHtml("ellipsis") + '</summary>' +
|
|
51
|
+
'<div class="login-browser-menu"><button type="button" data-action="retry">' + iconHtml("refresh-cw") + '<span>Restart sign-in</span></button></div></details>' +
|
|
52
|
+
'<button type="button" data-action="cancel" class="login-browser-icon" aria-label="Cancel sign-in" title="Cancel sign-in">' + iconHtml("x") + '</button></div></header>' +
|
|
53
|
+
'<div class="login-browser-viewport"><canvas width="1000" height="720" aria-label="Remote sign-in page"></canvas>' +
|
|
54
|
+
'<div class="login-browser-loading"><span class="login-browser-spinner" aria-hidden="true"></span><strong>Opening your sign-in page</strong><span>This may take a moment.</span></div>' +
|
|
55
|
+
'<textarea class="login-browser-keyboard" aria-label="Type into the remote sign-in page" autocomplete="off" autocapitalize="off" spellcheck="false"></textarea></div>' +
|
|
56
|
+
'<footer class="login-browser-footer"><div class="login-browser-info"><div class="login-browser-status"><span class="login-browser-status-dot" aria-hidden="true"></span><p role="status">Preparing sign-in…</p></div>' +
|
|
57
|
+
'<p class="login-browser-privacy">Browser cookies are discarded when this session ends. You stay signed in to ' + (msg.vendor === "codex" ? 'Codex' : 'Claude') + ' after this browser closes.</p></div>' +
|
|
58
|
+
'<button type="button" data-action="terminal" class="login-browser-terminal">' + iconHtml("terminal") + '<span>Use terminal sign-in</span>' + iconHtml("arrow-up-right") + '</button></footer>';
|
|
59
|
+
dialog.querySelector("h2").textContent = title;
|
|
60
|
+
document.body.appendChild(dialog);
|
|
61
|
+
var keyboard = dialog.querySelector("textarea");
|
|
62
|
+
var canvas = dialog.querySelector("canvas");
|
|
63
|
+
function cancel() { cancelVendorLogin(msg.vendor); }
|
|
64
|
+
function restart(mode) {
|
|
65
|
+
var ws = getWs();
|
|
66
|
+
if (!ws || ws.readyState !== 1) {
|
|
67
|
+
dialog.querySelector('[role="status"]').textContent = "Reconnect to Clay before switching sign-in methods.";
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
cancel();
|
|
71
|
+
requestVendorLogin(msg.vendor, { mode: mode });
|
|
72
|
+
}
|
|
73
|
+
dialog.querySelector('[data-action="cancel"]').onclick = cancel;
|
|
74
|
+
dialog.querySelector('[data-action="retry"]').onclick = function () { restart("browser"); };
|
|
75
|
+
dialog.querySelector('[data-action="terminal"]').onclick = function () { restart("terminal"); };
|
|
76
|
+
dialog.querySelector('[data-action="reload"]').onclick = function () { input({ kind: "reload" }); };
|
|
77
|
+
dialog.querySelector('[data-action="keyboard"]').onclick = function () { keyboard.focus(); };
|
|
78
|
+
dialog.addEventListener("cancel", function (event) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
var menu = dialog.querySelector("details");
|
|
81
|
+
if (menu.open) { menu.open = false; menu.querySelector("summary").focus(); }
|
|
82
|
+
else cancel();
|
|
83
|
+
});
|
|
84
|
+
dialog.addEventListener("click", function (event) {
|
|
85
|
+
var menu = dialog.querySelector("details");
|
|
86
|
+
if (!menu.contains(event.target)) menu.open = false;
|
|
87
|
+
});
|
|
88
|
+
function pointerPoint(event) {
|
|
89
|
+
var rect = canvas.getBoundingClientRect();
|
|
90
|
+
return { x: (event.clientX - rect.left) * canvas.width / rect.width,
|
|
91
|
+
y: (event.clientY - rect.top) * canvas.height / rect.height };
|
|
92
|
+
}
|
|
93
|
+
function flushMove() {
|
|
94
|
+
var view = current();
|
|
95
|
+
if (!view || view.browserId !== msg.browserId) return;
|
|
96
|
+
clearTimeout(view.moveTimer);
|
|
97
|
+
var point = view.pendingMove;
|
|
98
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, { moveTimer: null, pendingMove: null }) });
|
|
99
|
+
if (point) input(Object.assign({ kind: "move" }, point));
|
|
100
|
+
}
|
|
101
|
+
canvas.addEventListener("pointermove", function (event) {
|
|
102
|
+
var view = current();
|
|
103
|
+
var ws = getWs();
|
|
104
|
+
if (!view || event.pointerType === "touch" || !ws || ws.bufferedAmount > 65536) return;
|
|
105
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, {
|
|
106
|
+
pendingMove: pointerPoint(event), moveTimer: view.moveTimer || setTimeout(flushMove, 40),
|
|
107
|
+
}) });
|
|
108
|
+
});
|
|
109
|
+
canvas.addEventListener("pointerdown", function (event) {
|
|
110
|
+
if (event.button !== 0 || !event.isPrimary) return;
|
|
111
|
+
flushMove();
|
|
112
|
+
var view = current();
|
|
113
|
+
if (!view || view.pointerId !== null) return;
|
|
114
|
+
canvas.setPointerCapture(event.pointerId);
|
|
115
|
+
var touch = event.pointerType === "touch";
|
|
116
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, {
|
|
117
|
+
pointerY: event.clientY, pointerId: event.pointerId, mouseDown: !touch,
|
|
118
|
+
}) });
|
|
119
|
+
if (!touch) input(Object.assign({ kind: "down" }, pointerPoint(event)));
|
|
120
|
+
});
|
|
121
|
+
function releasePointer(event, cancelled) {
|
|
122
|
+
var view = current();
|
|
123
|
+
if (!view || view.pointerId !== event.pointerId) return;
|
|
124
|
+
flushMove();
|
|
125
|
+
view = current();
|
|
126
|
+
var distance = view.pointerY === null ? 0 : view.pointerY - event.clientY;
|
|
127
|
+
if (view.mouseDown) input(Object.assign({ kind: "up" }, pointerPoint(event)));
|
|
128
|
+
else if (!cancelled) {
|
|
129
|
+
if (Math.abs(distance) > 12) input({ kind: "wheel", deltaY: distance * 2 });
|
|
130
|
+
else input(Object.assign({ kind: "click" }, pointerPoint(event)));
|
|
131
|
+
}
|
|
132
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, { pointerY: null, pointerId: null, mouseDown: false }) });
|
|
133
|
+
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
|
|
134
|
+
if (!cancelled && Math.abs(distance) <= 12) keyboard.focus({ preventScroll: true });
|
|
135
|
+
}
|
|
136
|
+
canvas.addEventListener("pointerup", function (event) { releasePointer(event, false); });
|
|
137
|
+
canvas.addEventListener("pointercancel", function (event) { releasePointer(event, true); });
|
|
138
|
+
canvas.addEventListener("lostpointercapture", function (event) { releasePointer(event, true); });
|
|
139
|
+
canvas.addEventListener("wheel", function (event) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
input({ kind: "wheel", deltaY: event.deltaY });
|
|
142
|
+
}, { passive: false });
|
|
143
|
+
keyboard.addEventListener("keydown", function (event) {
|
|
144
|
+
var key = event.key;
|
|
145
|
+
if ((event.metaKey || event.ctrlKey) && key.toLowerCase() === "a") key = "ControlOrMeta+A";
|
|
146
|
+
else if (event.shiftKey && key === "Tab") key = "Shift+Tab";
|
|
147
|
+
if (/^(Tab|Shift\+Tab|Enter|Backspace|Delete|Escape|ArrowLeft|ArrowRight|ArrowUp|ArrowDown|Home|End|ControlOrMeta\+A)$/.test(key)) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
input({ kind: "key", key: key });
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
function insert() {
|
|
154
|
+
if (keyboard.value) input({ kind: "text", text: keyboard.value.slice(0, 4096) });
|
|
155
|
+
keyboard.value = "";
|
|
156
|
+
}
|
|
157
|
+
keyboard.addEventListener("input", function (event) { if (!event.isComposing) insert(); });
|
|
158
|
+
keyboard.addEventListener("compositionend", insert);
|
|
159
|
+
keyboard.addEventListener("paste", function (event) {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
input({ kind: "text", text: event.clipboardData.getData("text/plain").slice(0, 4096) });
|
|
162
|
+
});
|
|
163
|
+
dialog.showModal();
|
|
164
|
+
refreshIcons();
|
|
165
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
166
|
+
var observer = new ResizeObserver(function () { resizeLoginBrowser(); });
|
|
167
|
+
store.set({ vendorLoginBrowser: Object.assign({}, current(), { resizeObserver: observer }) });
|
|
168
|
+
observer.observe(dialog.querySelector(".login-browser-viewport"));
|
|
169
|
+
}
|
|
170
|
+
send("vendor_login_browser_attach");
|
|
171
|
+
resizeLoginBrowser();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function resizeLoginBrowser(force) {
|
|
175
|
+
var view = current();
|
|
176
|
+
var element = document.querySelector("#vendor-login-browser .login-browser-viewport");
|
|
177
|
+
if (!view || !element) return null;
|
|
178
|
+
var size = { width: Math.max(320, Math.min(1000, Math.round(element.clientWidth))),
|
|
179
|
+
height: Math.max(360, Math.min(720, Math.round(element.clientHeight))) };
|
|
180
|
+
if (force || !view.requestedSize || view.requestedSize.width !== size.width || view.requestedSize.height !== size.height) {
|
|
181
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, { requestedSize: size }) });
|
|
182
|
+
input(Object.assign({ kind: "resize" }, size));
|
|
183
|
+
}
|
|
184
|
+
return size;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function handleLoginBrowserMessage(msg) {
|
|
188
|
+
var view = current();
|
|
189
|
+
if (!view || msg.browserId !== view.browserId) return;
|
|
190
|
+
var dialog = document.getElementById("vendor-login-browser");
|
|
191
|
+
if (!dialog) return;
|
|
192
|
+
if (msg.type === "vendor_login_browser_status") {
|
|
193
|
+
dialog.querySelector('[role="status"]').textContent = msg.text;
|
|
194
|
+
dialog.dataset.phase = msg.phase || "loading";
|
|
195
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, { phase: msg.phase || "loading" }) });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (view.decoding || typeof msg.data !== "string" || msg.origin === "null") return;
|
|
199
|
+
store.set({ vendorLoginBrowser: Object.assign({}, view, { decoding: true }) });
|
|
200
|
+
var image = new Image();
|
|
201
|
+
function done() {
|
|
202
|
+
var active = current();
|
|
203
|
+
if (active && active.browserId === msg.browserId) store.set({ vendorLoginBrowser: Object.assign({}, active, { decoding: false }) });
|
|
204
|
+
}
|
|
205
|
+
image.onload = function () {
|
|
206
|
+
var active = current();
|
|
207
|
+
if (active && active.browserId === msg.browserId) {
|
|
208
|
+
var size = resizeLoginBrowser();
|
|
209
|
+
if (image.naturalWidth !== size.width || image.naturalHeight !== size.height) {
|
|
210
|
+
resizeLoginBrowser(true);
|
|
211
|
+
done();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
var canvas = dialog.querySelector("canvas");
|
|
215
|
+
canvas.width = image.naturalWidth;
|
|
216
|
+
canvas.height = image.naturalHeight;
|
|
217
|
+
canvas.getContext("2d").drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
218
|
+
dialog.querySelector(".login-browser-loading").hidden = true;
|
|
219
|
+
var origin = dialog.querySelector(".login-browser-origin");
|
|
220
|
+
try { origin.textContent = new URL(msg.origin).host; } catch (e) { origin.textContent = "Sign-in page"; }
|
|
221
|
+
origin.title = msg.origin || "";
|
|
222
|
+
}
|
|
223
|
+
done();
|
|
224
|
+
};
|
|
225
|
+
image.onerror = done;
|
|
226
|
+
image.src = "data:image/jpeg;base64," + msg.data;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
store.subscribe(function (state, previous) {
|
|
230
|
+
var view = state.vendorLoginBrowser;
|
|
231
|
+
if (!view) return;
|
|
232
|
+
if (state.currentSlug !== previous.currentSlug && state.currentSlug !== view.slug) { closeLoginBrowser(); return; }
|
|
233
|
+
if (state.connected !== previous.connected) {
|
|
234
|
+
if (state.connected) { send("vendor_login_browser_attach"); resizeLoginBrowser(true); }
|
|
235
|
+
else {
|
|
236
|
+
var dialog = document.getElementById("vendor-login-browser");
|
|
237
|
+
if (dialog) {
|
|
238
|
+
dialog.dataset.phase = "error";
|
|
239
|
+
dialog.querySelector('[role="status"]').textContent = "Connection lost. Reconnecting…";
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|