ccdeck 3.80.0 → 3.81.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/README.md +23 -4
- package/bin/cli/tui.js +433 -11
- package/dist/web/assets/{BrowserWatchModal-Bfvo_8H6.js → BrowserWatchModal-BcvsD8Np.js} +1 -1
- package/dist/web/assets/{IntegrationModal-GS5jIQ_J.js → IntegrationModal-BMtv2XWR.js} +1 -1
- package/dist/web/assets/{RadioPanel-Bxd2ElWb.js → RadioPanel-k65VVqTb.js} +1 -1
- package/dist/web/assets/{TrafficRadar-FgHBI2Oh.js → TrafficRadar-BNw0skS3.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-APwKtE2J.js → UsageHistoryModal-CYxrrwCl.js} +1 -1
- package/dist/web/assets/{app-xTrs4aEH.css → app-BIrh5Q0W.css} +1 -1
- package/dist/web/assets/{app-BzHVsgB2.js → app-DCoamBD4.js} +93 -93
- package/dist/web/assets/{index-7whwMaPX.js → index-BMX8nr4f.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/release-notes.json +62 -0
- package/src/server/account-notify.mjs +81 -16
- package/src/server/account-routes.mjs +20 -2
- package/src/server/account-watch.mjs +21 -0
- package/src/server/codex-auto.mjs +157 -37
- package/src/server/codex-lan-identity.mjs +61 -0
- package/src/server/codex-live-engine.mjs +28 -2
- package/src/server/codex-live-rpc.mjs +4 -1
- package/src/server/codex-profiles.mjs +34 -4
- package/src/server/codex-projects.mjs +308 -0
- package/src/server/codex-selection.mjs +17 -2
- package/src/server/codex-share.mjs +74 -12
- package/src/server/codex-terminal.mjs +1 -1
- package/src/server/codex-usage.mjs +69 -0
- package/src/server/codex-windows-private.mjs +2 -0
- package/src/server/codex-windows-private.ps1 +48 -1
- package/src/server/index.mjs +6 -4
- package/src/server/lan-codex-store.mjs +173 -0
- package/src/server/lan-codex.mjs +103 -0
- package/src/server/lan-copies.mjs +1 -1
- package/src/server/lan-deck.mjs +5 -0
- package/src/server/lan-engine.mjs +34 -6
- package/src/server/lan-manifest.mjs +16 -2
- package/src/server/lan-serve.mjs +21 -6
- package/src/server/lifecycle.mjs +2 -2
- package/src/server/npm-upgrade.mjs +17 -6
- package/src/server/pinned-build.mjs +3 -0
- package/src/server/request-gates.mjs +3 -0
- package/src/server/self-update.mjs +2 -72
- package/src/server/terminal-cli.mjs +8 -2
- package/src/server/tui-codex.mjs +229 -0
- package/src/server/tui-lan.mjs +684 -0
- package/src/server/tui-machine.mjs +492 -0
- package/src/server/tui-network.mjs +730 -0
- package/src/server/tui-view.mjs +735 -60
- package/src/server/version-order.mjs +74 -0
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
// The Local network side of `ccdeck tui`: who is out there, what the section
|
|
2
|
+
// says about them, and which of this deck's accounts it offers — the deck's own
|
|
3
|
+
// rules and English words, for a terminal.
|
|
4
|
+
//
|
|
5
|
+
// PORTED, NOT IMPORTED. The TUI is plain Node and cannot load the web's
|
|
6
|
+
// TypeScript, so this is a copy of src/web/lan-roster.ts (isOnline,
|
|
7
|
+
// sectionState, checkedLabel, askedLabel, deckRows and the row builders behind
|
|
8
|
+
// it, oneRowPerMachine, entryLine), src/web/lan-round.ts (seenLabel, isSeenNow,
|
|
9
|
+
// WIRE_ANSWERS, faultText, roundWhy, roundLabel), src/web/account-lan.ts
|
|
10
|
+
// (lanAccounts, codexLanAccounts, lanKindHeads, offeredHere) and the bits of
|
|
11
|
+
// admin-failure.ts (arrivalCheck, keychainText) and i18n/translate.ts (fill,
|
|
12
|
+
// plurals) they lean on, with the strings of i18n/areas/lan/en.ts and
|
|
13
|
+
// accounts/en.ts. src/web/__tests__/tui-lan.test.ts runs both on the same
|
|
14
|
+
// statuses and holds them equal, word for word — change one, change the other.
|
|
15
|
+
//
|
|
16
|
+
// Pure: no I/O and no clock. The status is GET /api/lan, the accounts are GET
|
|
17
|
+
// /api/claude-accounts and GET /api/codex-profiles, and `now` is handed in.
|
|
18
|
+
|
|
19
|
+
const PRODUCT = "ccdeck";
|
|
20
|
+
|
|
21
|
+
/** The English words this file says, keyed as the web's catalogs key them —
|
|
22
|
+
* exported so the parity suite can hold each one to the web's. */
|
|
23
|
+
export const LAN_STRINGS = Object.freeze({
|
|
24
|
+
"lan.checking": "checking…",
|
|
25
|
+
"lan.starting": "starting…",
|
|
26
|
+
"lan.online": "online",
|
|
27
|
+
"lan.wantsPair": "wants to pair",
|
|
28
|
+
"lan.notCalledYet": "has not called yet",
|
|
29
|
+
"lan.neverReached": "never reached",
|
|
30
|
+
"lan.lastOnline": "last online {when}",
|
|
31
|
+
"lan.trying": "trying…",
|
|
32
|
+
"lan.seen.never": "not seen",
|
|
33
|
+
"lan.seen.now": "now",
|
|
34
|
+
"lan.seen.justNow": "just now",
|
|
35
|
+
"lan.ago.m": "{m}m ago",
|
|
36
|
+
"lan.ago.h": "{h}h ago",
|
|
37
|
+
"lan.ago.d": "{d}d ago",
|
|
38
|
+
"lan.list.sep": ", ",
|
|
39
|
+
"lan.round.keychain.short": "Keychain locked on the other Mac",
|
|
40
|
+
"lan.round.keychain.long": "the other Mac could not export it. On that Mac: {keychain}. The next round brings it.",
|
|
41
|
+
"lan.round.inUse.short": "in use on the other deck",
|
|
42
|
+
"lan.round.inUse.long": "the other deck is using this login right now and does not send it: two machines on one login race to renew it, and the loser is signed out. It comes on the first round after that deck switches away — or sign in to it here, which gives this machine a login of its own.",
|
|
43
|
+
"lan.round.wire.waiting": "waiting for them to say yes",
|
|
44
|
+
"lan.round.wire.no": "it said no",
|
|
45
|
+
"lan.round.wire.theirInvite": "it pairs only by invite",
|
|
46
|
+
"lan.round.wire.myInvite": "needs an invite · your setting",
|
|
47
|
+
"lan.fault.ECONNREFUSED": "not listening",
|
|
48
|
+
"lan.fault.EHOSTUNREACH": "no route to it",
|
|
49
|
+
"lan.fault.ENETUNREACH": "no network here",
|
|
50
|
+
"lan.fault.ETIMEDOUT": "no answer",
|
|
51
|
+
"lan.fault.ECONNRESET": "it hung up",
|
|
52
|
+
"lan.fault.EHOSTDOWN": "it is down",
|
|
53
|
+
"lan.fault.ENOTFOUND": "name not found",
|
|
54
|
+
"lan.fault.EACCES": "blocked here",
|
|
55
|
+
"lan.fault.quiet": "it stopped mid-sentence",
|
|
56
|
+
"lan.fault.badReply": "it answered with nonsense",
|
|
57
|
+
"lan.fault.noManifest": "it would not say what it has",
|
|
58
|
+
"lan.fault.badChallenge": "it answered as somebody else",
|
|
59
|
+
"lan.fault.otherDeck": "a different deck is at that address",
|
|
60
|
+
"lan.fault.noProof": "it could not prove who it is",
|
|
61
|
+
"lan.fault.refusedProof": "it would not take this deck's word",
|
|
62
|
+
"lan.fault.refusedHandshake": "it turned this deck away",
|
|
63
|
+
"lan.fault.otherKey": "it knows this deck by another key",
|
|
64
|
+
"lan.round.allFine": "all logins fine · {when}",
|
|
65
|
+
"lan.round.whyLead": ", {list}",
|
|
66
|
+
"lan.round.arrived.one": "{count} login arrived{why} · {when}",
|
|
67
|
+
"lan.round.arrived.other": "{count} logins arrived{why} · {when}",
|
|
68
|
+
"lan.round.partial": "{ok} of {total} logins arrived{why} · {when}",
|
|
69
|
+
"lan.round.then": "{head}, then {fault} · {when}",
|
|
70
|
+
"lan.sec.couldNotStart": "could not start — {why}",
|
|
71
|
+
"lan.sec.waitingAnswer.one": "1 deck is waiting for your answer",
|
|
72
|
+
"lan.sec.waitingAnswer.other": "{count} decks are waiting for your answer",
|
|
73
|
+
"lan.sec.none": "no deck paired yet",
|
|
74
|
+
"lan.sec.foundWaiting.one": "1 deck found · waiting for them to accept",
|
|
75
|
+
"lan.sec.foundWaiting.other": "{count} decks found · waiting for them to accept",
|
|
76
|
+
"lan.sec.cannotReach.one": "this deck cannot reach the one it is paired with",
|
|
77
|
+
"lan.sec.cannotReach.other": "this deck cannot reach any of its {count} decks",
|
|
78
|
+
"lan.sec.ready.one": "1 deck ready",
|
|
79
|
+
"lan.sec.ready.other": "{count} decks ready",
|
|
80
|
+
"lan.sec.readyAway": "{ready} · {n} away",
|
|
81
|
+
"lan.checked.never": "not checked yet",
|
|
82
|
+
"lan.checked.justNow": "checked just now",
|
|
83
|
+
"lan.checked.when": "checked {when}",
|
|
84
|
+
"lan.entry.off": "Off",
|
|
85
|
+
"lan.entry.noStart": "could not start",
|
|
86
|
+
"lan.entry.wantsPair.one": "1 deck wants to pair",
|
|
87
|
+
"lan.entry.wantsPair.other": "{count} decks want to pair",
|
|
88
|
+
"lan.entry.blocked": "nothing can get in",
|
|
89
|
+
"lan.entry.onNone": "On · none paired yet",
|
|
90
|
+
"lan.entry.noneOnline": "none of {n} online",
|
|
91
|
+
"lan.entry.online": "{n} online",
|
|
92
|
+
"lan.entry.someOnline": "{online} of {n} online",
|
|
93
|
+
"lan.oneWay.never": "one-way · has not called yet",
|
|
94
|
+
"lan.oneWay.online": "online · one-way, it calls in",
|
|
95
|
+
"lan.oneWay.last": "one-way · last online {when}",
|
|
96
|
+
"lan.hint.asks": "{name} at {addr} is waiting for an answer.",
|
|
97
|
+
"lan.hint.asksTs": "{name} at {addr}, over Tailscale, is waiting for an answer.",
|
|
98
|
+
"lan.hint.noAnswer": "Nothing has answered at {where} yet — {error}.",
|
|
99
|
+
"lan.hint.dialling": "Dialling {where} until something answers.",
|
|
100
|
+
"lan.hint.at": "{name} at {where}",
|
|
101
|
+
"lan.hint.callsIn": "{name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. {last} Add its address through Add a deck, the link at the top of this view, to reach it either way.",
|
|
102
|
+
"lan.hint.neverCalled": "It has not called since this deck started.",
|
|
103
|
+
"lan.hint.lastCalled": "It last called {when}.",
|
|
104
|
+
"lan.state.needsInvite": "needs an invite",
|
|
105
|
+
"lan.state.notPaired": "not paired yet",
|
|
106
|
+
"lan.hint.nearbyTs": "{name} at {addr} is on your tailnet and nothing is shared with it.",
|
|
107
|
+
"lan.hint.nearby": "{name} at {addr} is on this network and nothing is shared with it.",
|
|
108
|
+
"lan.state.declined": "you said no",
|
|
109
|
+
"lan.hint.declined": "{name} asked and was turned away. It is not asking any more.",
|
|
110
|
+
"lan.setup.notWorking": "not working here",
|
|
111
|
+
"lan.setup.inUseNotSent": "in use here · not sent",
|
|
112
|
+
"accounts.fail.keychain": "claude-swap could not read the login keychain — start {product} from a Terminal window rather than a background service",
|
|
113
|
+
"accounts.fail.arrival.unreadable_here.short": "Keychain locked on this Mac",
|
|
114
|
+
"accounts.fail.arrival.no_credentials_here.short": "no stored login here",
|
|
115
|
+
"accounts.fail.arrival.no_credentials_here.long": "claude-swap still holds no login for it here.",
|
|
116
|
+
"accounts.fail.arrival.relogin_required_here.short": "login expired",
|
|
117
|
+
"accounts.fail.arrival.relogin_required_here.long": "the imported login was rejected — sign in again on a deck where it still works.",
|
|
118
|
+
"accounts.fail.arrival.unverified_here.short": "not checked",
|
|
119
|
+
"accounts.fail.arrival.unverified_here.long": "claude-swap could not confirm whether this Mac can read it.",
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// ── t(), English only ────────────────────────────────────────────────────────
|
|
123
|
+
|
|
124
|
+
const EN_PLURAL = new Intl.PluralRules("en");
|
|
125
|
+
|
|
126
|
+
/** {name} placeholders from `vars`; one with no value is left as written
|
|
127
|
+
* (i18n/translate.ts fill). */
|
|
128
|
+
function fill(template, vars) {
|
|
129
|
+
if (!vars) return template;
|
|
130
|
+
return template.replace(/\{(\w+)\}/g, (whole, name) => (name in vars ? String(vars[name]) : whole));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** i18n/translate.ts translate, for English: a numeric `count` tries
|
|
134
|
+
* "<key>.<one|other>", then "<key>.other", then the key; a key with no text
|
|
135
|
+
* says itself. */
|
|
136
|
+
function t(key, vars) {
|
|
137
|
+
const keys = [];
|
|
138
|
+
if (typeof vars?.count === "number") keys.push(`${key}.${EN_PLURAL.select(vars.count)}`, `${key}.other`);
|
|
139
|
+
keys.push(key);
|
|
140
|
+
for (const k of keys) {
|
|
141
|
+
const hit = Object.hasOwn(LAN_STRINGS, k) ? LAN_STRINGS[k] : undefined;
|
|
142
|
+
if (typeof hit === "string") return fill(hit, vars);
|
|
143
|
+
}
|
|
144
|
+
return fill(key, vars);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** own-row.ts: a table's own row for `key`, never Object.prototype's. */
|
|
148
|
+
const ownRow = (table, key) => (Object.hasOwn(table, key) ? table[key] : undefined);
|
|
149
|
+
|
|
150
|
+
// ── lan-round.ts ─────────────────────────────────────────────────────────────
|
|
151
|
+
|
|
152
|
+
/** How long ago, in the panel's words: "now" inside ninety seconds, then
|
|
153
|
+
* minutes, hours, and days past 48 hours; "not seen" for never. */
|
|
154
|
+
function seenLabel(lastSeen, now) {
|
|
155
|
+
if (lastSeen == null) return t("lan.seen.never");
|
|
156
|
+
const s = Math.max(0, Math.round((now - lastSeen) / 1000));
|
|
157
|
+
if (s < 90) return t("lan.seen.now");
|
|
158
|
+
const m = Math.round(s / 60);
|
|
159
|
+
if (m < 60) return t("lan.ago.m", { m });
|
|
160
|
+
const h = Math.round(m / 60);
|
|
161
|
+
return h < 48 ? t("lan.ago.h", { h }) : t("lan.ago.d", { d: Math.round(h / 24) });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Whether seenLabel said "now". */
|
|
165
|
+
const isSeenNow = label => label === t("lan.seen.now");
|
|
166
|
+
|
|
167
|
+
/** The reasons a round names about one login, from the sending deck. */
|
|
168
|
+
const ROUND_WHY = {
|
|
169
|
+
keychain_unavailable: { short: "lan.round.keychain.short", long: "lan.round.keychain.long" },
|
|
170
|
+
"in use": { short: "lan.round.inUse.short", long: "lan.round.inUse.long" },
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** The keychain sentence (admin-failure.ts keychainText). */
|
|
174
|
+
const keychainText = () => t("accounts.fail.keychain", { product: PRODUCT });
|
|
175
|
+
|
|
176
|
+
/** What this deck found wrong with a login that had just landed. */
|
|
177
|
+
const ARRIVAL_CHECK = {
|
|
178
|
+
unreadable_here: true,
|
|
179
|
+
no_credentials_here: true,
|
|
180
|
+
relogin_required_here: true,
|
|
181
|
+
unverified_here: true,
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** admin-failure.ts arrivalCheck: the words for one arrival check, or null. */
|
|
185
|
+
function arrivalCheck(code) {
|
|
186
|
+
const row = code ? ownRow(ARRIVAL_CHECK, code) : undefined;
|
|
187
|
+
if (!code || !row) return null;
|
|
188
|
+
const say = part => {
|
|
189
|
+
if (code === "unreadable_here" && part === "long") return `${keychainText()}.`;
|
|
190
|
+
return t(`accounts.fail.arrival.${code}.${part}`);
|
|
191
|
+
};
|
|
192
|
+
return { short: say("short"), long: say("long") };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** What a round has to say about one login beyond arrived / did not, or null. */
|
|
196
|
+
function roundWhy(d) {
|
|
197
|
+
if (!d.why) return null;
|
|
198
|
+
const mine = ownRow(ROUND_WHY, d.why);
|
|
199
|
+
return mine ? { short: t(mine.short), long: t(mine.long, { keychain: keychainText() }) } : arrivalCheck(d.why);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** The refusals that are answers rather than faults, keyed on the wire's own
|
|
203
|
+
* sentence (lan-call.mjs). A plain object, as the web's is. */
|
|
204
|
+
const WIRE_ANSWERS = {
|
|
205
|
+
"waiting for the other deck to accept this one": { text: t("lan.round.wire.waiting"), tone: "idle" },
|
|
206
|
+
"that deck said no": { text: t("lan.round.wire.no"), tone: "bad" },
|
|
207
|
+
"that deck pairs only by invite": { text: t("lan.round.wire.theirInvite"), tone: "idle" },
|
|
208
|
+
"this deck pairs only by invite": { text: t("lan.round.wire.myInvite"), tone: "idle" },
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/** Node's errno codes, said as a thing that happened. */
|
|
212
|
+
const FAULT_CODES = {
|
|
213
|
+
ECONNREFUSED: "lan.fault.ECONNREFUSED",
|
|
214
|
+
EHOSTUNREACH: "lan.fault.EHOSTUNREACH",
|
|
215
|
+
ENETUNREACH: "lan.fault.ENETUNREACH",
|
|
216
|
+
ETIMEDOUT: "lan.fault.ETIMEDOUT",
|
|
217
|
+
ECONNRESET: "lan.fault.ECONNRESET",
|
|
218
|
+
EHOSTDOWN: "lan.fault.EHOSTDOWN",
|
|
219
|
+
ENOTFOUND: "lan.fault.ENOTFOUND",
|
|
220
|
+
EACCES: "lan.fault.EACCES",
|
|
221
|
+
EPIPE: "lan.fault.ECONNRESET",
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** lan-call.mjs's fault sentences, in words a person can act on. */
|
|
225
|
+
const WIRE_FAULTS = {
|
|
226
|
+
"handshake timed out": "lan.fault.ETIMEDOUT",
|
|
227
|
+
"peer closed the connection": "lan.fault.ECONNRESET",
|
|
228
|
+
"peer went quiet": "lan.fault.quiet",
|
|
229
|
+
"bad reply": "lan.fault.badReply",
|
|
230
|
+
"no manifest": "lan.fault.noManifest",
|
|
231
|
+
"bad challenge": "lan.fault.badChallenge",
|
|
232
|
+
"a different deck is answering at that address": "lan.fault.otherDeck",
|
|
233
|
+
"that deck could not prove its own key": "lan.fault.noProof",
|
|
234
|
+
"the other deck refused this one's proof": "lan.fault.refusedProof",
|
|
235
|
+
"the other deck refused this handshake": "lan.fault.refusedHandshake",
|
|
236
|
+
"that deck has this one pinned under a different key": "lan.fault.otherKey",
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/** What to draw for one failure: a known sentence, the errno inside it, or the
|
|
240
|
+
* text whole. */
|
|
241
|
+
function faultText(error) {
|
|
242
|
+
const known = WIRE_FAULTS[error];
|
|
243
|
+
if (typeof known === "string") return t(known);
|
|
244
|
+
const code = /\b(E[A-Z]{3,})\b/.exec(error)?.[1];
|
|
245
|
+
const coded = code ? FAULT_CODES[code] : undefined;
|
|
246
|
+
return typeof coded === "string" ? t(coded) : error;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** What the last round with one peer did: { text, tone, hint? }, or null. */
|
|
250
|
+
function roundLabel(last, now) {
|
|
251
|
+
if (!last) return null;
|
|
252
|
+
if (last.error && last.done?.length) {
|
|
253
|
+
const finished = roundLabel({ ...last, error: undefined }, now);
|
|
254
|
+
const at = ` · ${seenLabel(last.at, now)}`;
|
|
255
|
+
return {
|
|
256
|
+
...finished,
|
|
257
|
+
text: t("lan.round.then", { head: finished.text.slice(0, -at.length), fault: faultText(last.error), when: seenLabel(last.at, now) }),
|
|
258
|
+
tone: "bad",
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (last.error) return WIRE_ANSWERS[last.error] ?? { text: faultText(last.error), tone: "bad" };
|
|
262
|
+
const done = last.done ?? [];
|
|
263
|
+
if (!done.length) return { text: t("lan.round.allFine", { when: seenLabel(last.at, now) }), tone: "idle" };
|
|
264
|
+
const ok = done.filter(d => d.ok);
|
|
265
|
+
const said = done.map(d => ({ d, why: roundWhy(d) })).filter(x => x.why);
|
|
266
|
+
const names = [...new Set(said.map(x => x.why.short))];
|
|
267
|
+
const what = names.length ? t("lan.round.whyLead", { list: names.join(t("lan.list.sep")) }) : "";
|
|
268
|
+
const hint = said.length ? said.map(x => `${x.d.email}: ${x.why.long}`).join(" ") : undefined;
|
|
269
|
+
const at = seenLabel(last.at, now);
|
|
270
|
+
return ok.length === done.length
|
|
271
|
+
? { text: t("lan.round.arrived", { count: ok.length, why: what, when: at }), tone: said.length ? "warn" : "ok", ...(hint ? { hint } : {}) }
|
|
272
|
+
: { text: t("lan.round.partial", { ok: ok.length, total: done.length, why: what, when: at }), tone: "bad", ...(hint ? { hint } : {}) };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// ── lan-roster.ts ────────────────────────────────────────────────────────────
|
|
276
|
+
|
|
277
|
+
/** How long a beacon or an answered round keeps a deck online: three beacon
|
|
278
|
+
* intervals plus slack. */
|
|
279
|
+
export const LAN_ONLINE_MS = 95_000;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Is this deck reachable right now? A failed round is offline whatever the
|
|
283
|
+
* beacon says — unless the failure was an answer (WIRE_ANSWERS); otherwise a
|
|
284
|
+
* round or a beacon inside LAN_ONLINE_MS is online.
|
|
285
|
+
*/
|
|
286
|
+
export function lanIsOnline(p, now) {
|
|
287
|
+
if (p.last?.error && !WIRE_ANSWERS[p.last.error]) return false;
|
|
288
|
+
if (p.last?.at && now - p.last.at < LAN_ONLINE_MS) return true;
|
|
289
|
+
if (p.lastSeen != null && now - p.lastSeen < LAN_ONLINE_MS) return true;
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A deck that calls in is here when it has called inside the window. */
|
|
294
|
+
function calledLately(lastSeen, now) {
|
|
295
|
+
return lastSeen != null && now - lastSeen < LAN_ONLINE_MS;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The one line under the switch: { text, tone } with tone "bad" | "idle" |
|
|
300
|
+
* "ok" | "wait". Empty text while the feature is off; "checking…" before the
|
|
301
|
+
* first status. Counts machines, not keys, by the list's own fold.
|
|
302
|
+
*/
|
|
303
|
+
export function lanSectionState(s, now) {
|
|
304
|
+
if (!s) return { text: t("lan.checking"), tone: "idle" };
|
|
305
|
+
if (!s.enabled) return { text: "", tone: "idle" };
|
|
306
|
+
if (s.stalled) return { text: t("lan.sec.couldNotStart", { why: s.stalled }), tone: "bad" };
|
|
307
|
+
if (!s.running) return { text: t("lan.starting"), tone: "wait" };
|
|
308
|
+
const asking = (s.pending ?? []).length;
|
|
309
|
+
if (asking) return { text: t("lan.sec.waitingAnswer", { count: asking }), tone: "wait" };
|
|
310
|
+
const peers = (s.peers ?? []).filter(p => p.paired !== false || p.met);
|
|
311
|
+
if (!peers.length) return { text: t("lan.sec.none"), tone: "idle" };
|
|
312
|
+
const present = p => (p.waiting ? calledLately(p.lastSeen, now) : lanIsOnline(p, now));
|
|
313
|
+
const asksToBeAccepted = p => !p.waiting && p.last?.error === "waiting for the other deck to accept this one";
|
|
314
|
+
const aliases = s.aliases ?? {};
|
|
315
|
+
let here = 0, unanswered = 0, offline = 0;
|
|
316
|
+
for (const machine of machines(peers, p => pairedName(p, p.peerFp ?? p.fp, aliases).name, p => p.addr ?? "")) {
|
|
317
|
+
const on = machine.filter(present);
|
|
318
|
+
if (!on.length) { offline++; continue; }
|
|
319
|
+
here++;
|
|
320
|
+
if (on.every(asksToBeAccepted)) unanswered++;
|
|
321
|
+
}
|
|
322
|
+
if (here && unanswered === here) return { text: t("lan.sec.foundWaiting", { count: here }), tone: "wait" };
|
|
323
|
+
if (!here) return { text: t("lan.sec.cannotReach", { count: offline }), tone: "bad" };
|
|
324
|
+
const ready = t("lan.sec.ready", { count: here });
|
|
325
|
+
return { text: offline ? t("lan.sec.readyAway", { ready, n: offline }) : ready, tone: "ok" };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** When every paired deck was last asked, as a phrase: "checking…" while
|
|
329
|
+
* busy, "not checked yet", "checked just now", or "checked 3m ago". */
|
|
330
|
+
export function lanCheckedLabel(at, now, busy) {
|
|
331
|
+
if (busy) return t("lan.checking");
|
|
332
|
+
if (at == null) return t("lan.checked.never");
|
|
333
|
+
const when = seenLabel(at, now);
|
|
334
|
+
return isSeenNow(when) ? t("lan.checked.justNow") : t("lan.checked.when", { when });
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** How long a request has been waiting, coarser than the peer clock. */
|
|
338
|
+
function askedLabel(at, now) {
|
|
339
|
+
const s = Math.max(0, Math.round((now - at) / 1000));
|
|
340
|
+
if (s < 90) return t("lan.seen.justNow");
|
|
341
|
+
const m = Math.round(s / 60);
|
|
342
|
+
return m < 60 ? t("lan.ago.m", { m }) : t("lan.ago.h", { h: Math.round(m / 60) });
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** A deck that is paired, holds no address here, and calls this one. */
|
|
346
|
+
function callsIn(lastSeen, now) {
|
|
347
|
+
if (lastSeen == null) return { text: t("lan.oneWay.never"), here: false };
|
|
348
|
+
const fresh = calledLately(lastSeen, now);
|
|
349
|
+
return { text: fresh ? t("lan.oneWay.online") : t("lan.oneWay.last", { when: seenLabel(lastSeen, now) }), here: fresh };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Whether it is there now, and when it last was. */
|
|
353
|
+
function presenceLabel(p, here, now) {
|
|
354
|
+
if (here) return t("lan.online");
|
|
355
|
+
if (p.lastSeen != null) return t("lan.lastOnline", { when: seenLabel(p.lastSeen, now) });
|
|
356
|
+
return p.waiting ? t("lan.notCalledYet") : t("lan.neverReached");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** deckRows: every machine this deck knows of, one row each — requests, then
|
|
360
|
+
* paired decks (one row per machine), addresses still dialled, decks nearby,
|
|
361
|
+
* and the ones declined; by name within each kind. */
|
|
362
|
+
function deckRows(s, now) {
|
|
363
|
+
if (!s) return [];
|
|
364
|
+
const rows = [];
|
|
365
|
+
const seen = new Set();
|
|
366
|
+
const byName = (a, b) => a.name.localeCompare(b.name, undefined, { numeric: true });
|
|
367
|
+
const aliases = s.aliases ?? {};
|
|
368
|
+
|
|
369
|
+
for (const p of s.pending ?? []) {
|
|
370
|
+
if (!p?.fp || seen.has(p.fp)) continue;
|
|
371
|
+
seen.add(p.fp);
|
|
372
|
+
rows.push(askingRow(p, aliases, now));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const paired = [];
|
|
376
|
+
const dialling = [];
|
|
377
|
+
for (const p of s.peers ?? []) {
|
|
378
|
+
const fp = p.peerFp ?? p.fp;
|
|
379
|
+
if (!fp || seen.has(fp)) continue;
|
|
380
|
+
seen.add(fp);
|
|
381
|
+
if (!p.paired && p.manual && !p.met) dialling.push(diallingRow(p, fp, now));
|
|
382
|
+
else paired.push(pairedRow(p, fp, aliases, now));
|
|
383
|
+
}
|
|
384
|
+
rows.push(...oneRowPerMachine(paired).sort(byName), ...dialling.sort(byName));
|
|
385
|
+
|
|
386
|
+
const nearby = [];
|
|
387
|
+
for (const p of s.strangers ?? []) {
|
|
388
|
+
if (!p?.fp || seen.has(p.fp)) continue;
|
|
389
|
+
seen.add(p.fp);
|
|
390
|
+
nearby.push(nearbyRow(p, aliases, s.pairingMode));
|
|
391
|
+
}
|
|
392
|
+
rows.push(...nearby.sort(byName));
|
|
393
|
+
|
|
394
|
+
const declined = [];
|
|
395
|
+
for (const p of s.declined ?? []) {
|
|
396
|
+
if (!p?.fp || seen.has(p.fp)) continue;
|
|
397
|
+
seen.add(p.fp);
|
|
398
|
+
declined.push(declinedRow(p, aliases));
|
|
399
|
+
}
|
|
400
|
+
rows.push(...declined.sort(byName));
|
|
401
|
+
|
|
402
|
+
// Two rows under one name carry the address that tells them apart.
|
|
403
|
+
const times = new Map();
|
|
404
|
+
for (const r of rows) times.set(r.name, (times.get(r.name) ?? 0) + 1);
|
|
405
|
+
for (const r of rows) {
|
|
406
|
+
if ((times.get(r.name) ?? 0) < 2 || !r.addr) continue;
|
|
407
|
+
r.state = r.quiet || !r.state ? r.addr : `${r.addr} · ${r.state}`;
|
|
408
|
+
r.quiet = false;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return rows;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** A deck asking to pair. */
|
|
415
|
+
function askingRow(p, aliases, now) {
|
|
416
|
+
const n = named(aliases, p.fp, p.name || p.fp);
|
|
417
|
+
return {
|
|
418
|
+
fp: p.fp, ...n, addr: p.addr ?? "",
|
|
419
|
+
kind: "asks", state: `${t("lan.wantsPair")} · ${askedLabel(p.at, now)}`, tone: "wait", here: true,
|
|
420
|
+
hint: t(p.via === "tailscale" ? "lan.hint.asksTs" : "lan.hint.asks", { name: n.name, addr: p.addr ?? "" }),
|
|
421
|
+
...tailnet(p.via),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** An address somebody typed that nothing has answered at yet. */
|
|
426
|
+
function diallingRow(p, fp, now) {
|
|
427
|
+
const line = roundLabel(p.last, now);
|
|
428
|
+
const where = p.addr ? `${p.addr}:${p.port}` : "";
|
|
429
|
+
return {
|
|
430
|
+
fp: where, name: where || p.name || fp, addr: p.addr ?? "",
|
|
431
|
+
kind: "dialling",
|
|
432
|
+
state: line ? roundWords(line) : t("lan.trying"),
|
|
433
|
+
tone: line ? line.tone : "idle",
|
|
434
|
+
here: false,
|
|
435
|
+
hint: p.last?.error
|
|
436
|
+
? t("lan.hint.noAnswer", { where, error: p.last.error })
|
|
437
|
+
: t("lan.hint.dialling", { where }),
|
|
438
|
+
...tailnet(p.via),
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/** A paired deck, or an address that has answered. */
|
|
443
|
+
function pairedRow(p, fp, aliases, now) {
|
|
444
|
+
const line = roundLabel(p.last, now);
|
|
445
|
+
const here = lanIsOnline(p, now);
|
|
446
|
+
const where = p.addr ? `${p.addr}:${p.port}` : "";
|
|
447
|
+
const called = p.waiting ? callsIn(p.lastSeen, now) : null;
|
|
448
|
+
const present = called ? called.here : here;
|
|
449
|
+
const said = !called && line
|
|
450
|
+
? (present ? `${t("lan.online")} · ${roundWords(line)}` : `${roundWords(line)} · ${presenceLabel(p, present, now)}`)
|
|
451
|
+
: called ? called.text
|
|
452
|
+
: presenceLabel(p, present, now);
|
|
453
|
+
const answered = p.last?.error ? WIRE_ANSWERS[p.last.error] : null;
|
|
454
|
+
const quiet = !called && present && !p.last?.error && !(p.last?.done ?? []).length;
|
|
455
|
+
const n = pairedName(p, fp, aliases);
|
|
456
|
+
return {
|
|
457
|
+
fp,
|
|
458
|
+
...n,
|
|
459
|
+
addr: p.addr ?? "",
|
|
460
|
+
kind: "paired",
|
|
461
|
+
state: said,
|
|
462
|
+
quiet,
|
|
463
|
+
tone: answered ? (answered.tone === "bad" ? "bad" : "wait")
|
|
464
|
+
: line ? line.tone
|
|
465
|
+
: present ? "ok" : "idle",
|
|
466
|
+
here: called ? called.here : here,
|
|
467
|
+
...tailnet(p.via),
|
|
468
|
+
...(called ? { oneWay: true } : {}),
|
|
469
|
+
...(!present && p.lastSeen != null ? { since: seenLabel(p.lastSeen, now) } : {}),
|
|
470
|
+
hint: called
|
|
471
|
+
? t("lan.hint.callsIn", {
|
|
472
|
+
name: n.name,
|
|
473
|
+
last: p.lastSeen == null ? t("lan.hint.neverCalled") : t("lan.hint.lastCalled", { when: seenLabel(p.lastSeen, now) }),
|
|
474
|
+
})
|
|
475
|
+
: `${where ? t("lan.hint.at", { name: n.name, where }) : n.name}${p.last?.error ? ` — ${p.last.error}` : ""}${line?.hint ? ` — ${line.hint}` : ""}`,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/** The name a paired deck's row is drawn under, which the list folds by. */
|
|
480
|
+
function pairedName(p, fp, aliases) {
|
|
481
|
+
return p.manual && !p.met ? { name: p.addr ? `${p.addr}:${p.port}` : "" } : named(aliases, fp, p.name || fp);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/** A machine on the network that nobody here has paired with. */
|
|
485
|
+
function nearbyRow(p, aliases, pairingMode) {
|
|
486
|
+
const n = named(aliases, p.fp, p.name || p.fp);
|
|
487
|
+
return {
|
|
488
|
+
fp: p.fp, ...n, addr: p.addr ?? "",
|
|
489
|
+
kind: "nearby", state: pairingMode === "invite" ? t("lan.state.needsInvite") : t("lan.state.notPaired"), tone: "idle", here: true,
|
|
490
|
+
hint: t(p.via === "tailscale" ? "lan.hint.nearbyTs" : "lan.hint.nearby", { name: n.name, addr: p.addr ?? "" }),
|
|
491
|
+
...tailnet(p.via),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/** A deck that asked and was told no. */
|
|
496
|
+
function declinedRow(p, aliases) {
|
|
497
|
+
const n = named(aliases, p.fp, p.name || p.fp);
|
|
498
|
+
return {
|
|
499
|
+
fp: p.fp, ...n, addr: p.addr ?? "",
|
|
500
|
+
kind: "declined", state: t("lan.state.declined"), tone: "idle", here: false,
|
|
501
|
+
hint: t("lan.hint.declined", { name: n.name }),
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** What somebody here calls it: { name } or, renamed, { name, self }. */
|
|
506
|
+
function named(aliases, fp, own) {
|
|
507
|
+
const given = fp ? aliases[fp] : undefined;
|
|
508
|
+
return given && given !== own ? { name: given, self: own } : { name: own };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/** `via` for a row, present only for a deck reached over the tailnet. */
|
|
512
|
+
function tailnet(via) {
|
|
513
|
+
return via === "tailscale" ? { via: "tailscale" } : {};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** What a round did, without its clock: everything before the first " · ". */
|
|
517
|
+
function roundWords(line) {
|
|
518
|
+
return line.text.replace(/ · .*$/, "");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** One row per machine among the paired decks: by name, split by address only
|
|
522
|
+
* where one name is at two; the online one leads, the rest are its `twins`. */
|
|
523
|
+
function oneRowPerMachine(rows) {
|
|
524
|
+
return machines(rows, r => r.name, r => r.addr).map(fold);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/** oneRowPerMachine's grouping, for rows and for peers alike. */
|
|
528
|
+
function machines(list, nameOf, addrOf) {
|
|
529
|
+
const byName = new Map();
|
|
530
|
+
for (const item of list) {
|
|
531
|
+
const group = byName.get(nameOf(item));
|
|
532
|
+
if (group) group.push(item); else byName.set(nameOf(item), [item]);
|
|
533
|
+
}
|
|
534
|
+
const out = [];
|
|
535
|
+
for (const group of byName.values()) {
|
|
536
|
+
const addrs = [...new Set(group.map(addrOf).filter(Boolean))];
|
|
537
|
+
if (addrs.length > 1) {
|
|
538
|
+
for (const a of addrs) out.push(group.filter(item => addrOf(item) === a));
|
|
539
|
+
for (const item of group) if (!addrOf(item)) out.push([item]);
|
|
540
|
+
} else {
|
|
541
|
+
out.push(group);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return out;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** One machine's decks as one row: the lead, and the rest as its twins. */
|
|
548
|
+
function fold(list) {
|
|
549
|
+
const [lead, ...twins] = [...list].sort((a, b) =>
|
|
550
|
+
(Number(b.here) - Number(a.here)) || (Number(!!b.addr) - Number(!!a.addr)));
|
|
551
|
+
return twins.length ? { ...lead, twins } : lead;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The list of machines, as the Local network view draws it (LanSyncSection):
|
|
556
|
+
* deckRows over the status, with the requests left out while this deck pairs
|
|
557
|
+
* only by invite. Each row is { fp, name, self?, addr, kind: "asks" | "paired" |
|
|
558
|
+
* "dialling" | "nearby" | "declined", state, quiet?, tone, here, via?, oneWay?,
|
|
559
|
+
* since?, hint, twins? }.
|
|
560
|
+
*/
|
|
561
|
+
export function lanDeckRows(status, now) {
|
|
562
|
+
return deckRows(status?.pairingMode === "invite" && status ? { ...status, pending: [] } : status, now);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* The way in, in one line — { text, tone, live }: off, could not start,
|
|
567
|
+
* requests waiting, nothing can get in, or how many paired machines are
|
|
568
|
+
* online now. From the same rows lanDeckRows draws.
|
|
569
|
+
*/
|
|
570
|
+
export function lanEntryLine(status, now) {
|
|
571
|
+
return entryLine(status, lanDeckRows(status, now));
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function entryLine(s, rows) {
|
|
575
|
+
if (!s) return { text: t("lan.checking"), tone: "idle", live: false };
|
|
576
|
+
if (!s.enabled) return { text: t("lan.entry.off"), tone: "idle", live: false };
|
|
577
|
+
if (s.stalled) return { text: t("lan.entry.noStart"), tone: "bad", live: false };
|
|
578
|
+
if (!s.running) return { text: t("lan.starting"), tone: "wait", live: false };
|
|
579
|
+
const asks = rows.filter(r => r.kind === "asks").length;
|
|
580
|
+
if (asks) return { text: t("lan.entry.wantsPair", { count: asks }), tone: "wait", live: false };
|
|
581
|
+
if (s.reach?.blocked) return { text: t("lan.entry.blocked"), tone: "bad", live: false };
|
|
582
|
+
const paired = rows.filter(r => r.kind === "paired");
|
|
583
|
+
if (!paired.length) return { text: t("lan.entry.onNone"), tone: "idle", live: false };
|
|
584
|
+
const online = paired.filter(r => r.here).length;
|
|
585
|
+
if (!online) return { text: t("lan.entry.noneOnline", { n: paired.length }), tone: "idle", live: false };
|
|
586
|
+
if (online === paired.length) return { text: t("lan.entry.online", { n: online }), tone: "ok", live: true };
|
|
587
|
+
return { text: t("lan.entry.someOnline", { online, n: paired.length }), tone: "ok", live: true };
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// ── account-lan.ts ───────────────────────────────────────────────────────────
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* This deck's Claude accounts as Local network lists them (/api/claude-accounts
|
|
594
|
+
* rows): { key: "email@@orgUuid", email, alive, shareable, active? } — keyed as
|
|
595
|
+
* the server keys them, shareable as its export preflight decides.
|
|
596
|
+
*/
|
|
597
|
+
export function lanAccounts(accounts) {
|
|
598
|
+
return (accounts ?? []).map(a => ({
|
|
599
|
+
key: `${String(a.email ?? "").trim().toLowerCase()}@@${a.orgUuid ?? ""}`,
|
|
600
|
+
email: a.email ?? "",
|
|
601
|
+
alive: a.alive === true,
|
|
602
|
+
shareable: a.collector === "ok" || (a.collector == null && !a.active),
|
|
603
|
+
...(a.active ? { active: true } : {}),
|
|
604
|
+
}));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** A Local network key that names a Codex login. */
|
|
608
|
+
export const isCodexLanKey = key => key.startsWith("codex:");
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* This deck's Codex logins (/api/codex-profiles profiles carrying `lan`), one
|
|
612
|
+
* row per account, the active profile's row winning: { key, email, alive: true,
|
|
613
|
+
* shareable: true, provider: "codex", active? }.
|
|
614
|
+
*/
|
|
615
|
+
export function codexLanAccounts(profiles) {
|
|
616
|
+
const rows = new Map();
|
|
617
|
+
for (const p of profiles ?? []) {
|
|
618
|
+
if (!p.lan || p.available === false) continue;
|
|
619
|
+
const had = rows.get(p.lan.key);
|
|
620
|
+
if (had && (had.active || !p.active)) continue;
|
|
621
|
+
rows.set(p.lan.key, {
|
|
622
|
+
key: p.lan.key, email: p.lan.email, alive: true, shareable: true, provider: "codex",
|
|
623
|
+
...(p.active ? { active: true } : {}),
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
return [...rows.values()];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/** "Claude" above the first Claude login and "Codex" above the first Codex
|
|
630
|
+
* one, only on a deck that has both; null elsewhere. */
|
|
631
|
+
export function lanKindHeads(accounts) {
|
|
632
|
+
const kind = a => (a.provider === "codex" ? "Codex" : "Claude");
|
|
633
|
+
const mixed = new Set(accounts.map(kind)).size > 1;
|
|
634
|
+
return accounts.map((a, i) => (mixed && (i === 0 || kind(accounts[i - 1]) !== kind(a)) ? kind(a) : null));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** The accounts as Local network hands them out: unless `status.sendInUse`,
|
|
638
|
+
* every row of the login this deck is on is marked { shareable: false,
|
|
639
|
+
* inUse: true }. */
|
|
640
|
+
export function lanOfferedHere(accounts, status) {
|
|
641
|
+
if (status?.sendInUse === true) return accounts;
|
|
642
|
+
const live = new Set(accounts.filter(a => a.active).map(a => a.key));
|
|
643
|
+
return accounts.map(a => (live.has(a.key) ? { ...a, shareable: false, inUse: true } : a));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* The "Share these accounts" list of the setup dialog (LanSetupModal), in its
|
|
648
|
+
* order: Claude's logins, then Codex's. Each row is { key, email, provider:
|
|
649
|
+
* "claude" | "codex", head: "Claude" | "Codex" | null, shared, shareable,
|
|
650
|
+
* alive, inUse, mark } — `mark` the quiet words the dialog draws after the
|
|
651
|
+
* email: "not working here" for a copy that does not work here, "in use here ·
|
|
652
|
+
* not sent" for the ticked login this deck is on, otherwise null.
|
|
653
|
+
*/
|
|
654
|
+
export function lanShareRows(status, claudeAccounts, codexProfiles) {
|
|
655
|
+
const held = [...lanAccounts(claudeAccounts ?? []), ...codexLanAccounts(codexProfiles ?? [])];
|
|
656
|
+
const accounts = lanOfferedHere(held, status ?? null);
|
|
657
|
+
const heads = lanKindHeads(accounts);
|
|
658
|
+
const shared = new Set(status?.shared ?? []);
|
|
659
|
+
return accounts.map((a, i) => {
|
|
660
|
+
const inUse = a.inUse === true;
|
|
661
|
+
const ticked = shared.has(a.key);
|
|
662
|
+
return {
|
|
663
|
+
key: a.key,
|
|
664
|
+
email: a.email,
|
|
665
|
+
provider: a.provider === "codex" ? "codex" : "claude",
|
|
666
|
+
head: heads[i],
|
|
667
|
+
shared: ticked,
|
|
668
|
+
shareable: a.shareable === true,
|
|
669
|
+
alive: a.alive === true,
|
|
670
|
+
inUse,
|
|
671
|
+
mark: !a.alive ? t("lan.setup.notWorking")
|
|
672
|
+
: inUse && ticked ? t("lan.setup.inUseNotSent")
|
|
673
|
+
: null,
|
|
674
|
+
};
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** The shared list after one tick (lan-share.ts nextShared): `key` removed if
|
|
679
|
+
* it is there, added at the end if not; every other key kept, in order. */
|
|
680
|
+
export function toggleShared(shared, key) {
|
|
681
|
+
const next = new Set(shared ?? []);
|
|
682
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
683
|
+
return [...next];
|
|
684
|
+
}
|