usebeeline 0.1.207 → 0.1.208
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/dist/usebeeline.mjs +26 -33
- package/package.json +1 -1
package/dist/usebeeline.mjs
CHANGED
|
@@ -20597,7 +20597,7 @@ async function postJson(url, body, headers = {}, signal, _timeoutMs = 6e4, held
|
|
|
20597
20597
|
}
|
|
20598
20598
|
async function attachLocalDelivery(server, secret) {
|
|
20599
20599
|
const { status, value } = await postJson(`${server}/mcp/oauth/delivery-attach`, { secret });
|
|
20600
|
-
if (status !== 200 || typeof value.clientId !== "string" || typeof value.access_token !== "string" ||
|
|
20600
|
+
if (status !== 200 || typeof value.clientId !== "string" || typeof value.access_token !== "string" || !value.access_token)
|
|
20601
20601
|
throw new Error("The local delivery handoff ended or was already used. Ask this same connected member for setup_delivery again.");
|
|
20602
20602
|
return value;
|
|
20603
20603
|
}
|
|
@@ -20635,12 +20635,8 @@ function signInLink(server, clientId, memberName, claudeInboundFallback = false)
|
|
|
20635
20635
|
}
|
|
20636
20636
|
async function finishSignIn(server, clientId, signIn, deadlineAt = Date.now() + 10 * 6e4, persist = () => {
|
|
20637
20637
|
}) {
|
|
20638
|
-
if (signIn.tokens
|
|
20639
|
-
|
|
20640
|
-
if (expires <= 0)
|
|
20641
|
-
throw new SignInPendingError("The sign-in result needs a new explicit authorization");
|
|
20642
|
-
return { ...signIn.tokens, expires_in: expires };
|
|
20643
|
-
}
|
|
20638
|
+
if (signIn.tokens)
|
|
20639
|
+
return signIn.tokens;
|
|
20644
20640
|
if (signIn.exchangeStarted)
|
|
20645
20641
|
throw new SignInPendingError("The sign-in result is unknown; no code exchange was repeated");
|
|
20646
20642
|
if (Date.now() >= deadlineAt)
|
|
@@ -20677,9 +20673,9 @@ async function finishSignIn(server, clientId, signIn, deadlineAt = Date.now() +
|
|
|
20677
20673
|
} catch {
|
|
20678
20674
|
throw new SignInPendingError("The sign-in result is unknown; no code exchange was repeated");
|
|
20679
20675
|
}
|
|
20680
|
-
if (token.status !== 200 || typeof token.value.access_token !== "string" || !token.value.access_token
|
|
20676
|
+
if (token.status !== 200 || typeof token.value.access_token !== "string" || !token.value.access_token)
|
|
20681
20677
|
throw new SignInPendingError("The sign-in result is unknown; explicit authorization is required");
|
|
20682
|
-
signIn.tokens = { access_token: token.value.access_token
|
|
20678
|
+
signIn.tokens = { access_token: token.value.access_token };
|
|
20683
20679
|
signIn.tokensAt = Date.now();
|
|
20684
20680
|
persist(signIn);
|
|
20685
20681
|
return signIn.tokens;
|
|
@@ -20693,28 +20689,29 @@ async function refresh(server, clientId, refreshToken) {
|
|
|
20693
20689
|
});
|
|
20694
20690
|
if (status !== 200)
|
|
20695
20691
|
throw new Error(status === 400 ? DISCONNECTED : `Beeline token refresh failed (HTTP ${status})`);
|
|
20696
|
-
|
|
20692
|
+
if (typeof value.access_token !== "string" || !value.access_token)
|
|
20693
|
+
throw new Error(DISCONNECTED);
|
|
20694
|
+
return { access_token: value.access_token };
|
|
20697
20695
|
}
|
|
20698
|
-
async function accessToken(dir, key
|
|
20699
|
-
const valid = (session2) => session2.accessToken && session2.accessToken !== expiredToken && (session2.accessExpiresAt ?? 0) > Date.now() + 6e4 ? session2.accessToken : void 0;
|
|
20696
|
+
async function accessToken(dir, key) {
|
|
20700
20697
|
const current = readState(dir).sessions.find((s) => s.key === key);
|
|
20701
20698
|
if (!current)
|
|
20702
20699
|
throw new Error("This session has not joined Beeline");
|
|
20703
|
-
|
|
20704
|
-
|
|
20705
|
-
return ready;
|
|
20700
|
+
if (current.accessToken)
|
|
20701
|
+
return current.accessToken;
|
|
20706
20702
|
return withLock(dir, async () => {
|
|
20707
20703
|
const state = readState(dir);
|
|
20708
20704
|
const session2 = state.sessions.find((s) => s.key === key);
|
|
20709
20705
|
if (!session2)
|
|
20710
20706
|
throw new Error("This session has not joined Beeline");
|
|
20711
|
-
|
|
20712
|
-
|
|
20713
|
-
|
|
20707
|
+
if (session2.accessToken)
|
|
20708
|
+
return session2.accessToken;
|
|
20709
|
+
if (!session2.refreshToken)
|
|
20710
|
+
throw new Error(DISCONNECTED);
|
|
20714
20711
|
const tokens = await refresh(session2.server, session2.clientId, session2.refreshToken);
|
|
20715
20712
|
session2.accessToken = tokens.access_token;
|
|
20716
|
-
session2.refreshToken
|
|
20717
|
-
session2.accessExpiresAt
|
|
20713
|
+
delete session2.refreshToken;
|
|
20714
|
+
delete session2.accessExpiresAt;
|
|
20718
20715
|
writeState(dir, state);
|
|
20719
20716
|
return tokens.access_token;
|
|
20720
20717
|
});
|
|
@@ -23979,8 +23976,8 @@ async function flush(dir, sources, deps = realDeps) {
|
|
|
23979
23976
|
const live = liveSessions(sources);
|
|
23980
23977
|
for (const joined2 of state.sessions) {
|
|
23981
23978
|
const session2 = findSession(joined2, live, state.sessions);
|
|
23982
|
-
if (session2 && (session2.sessionId !== joined2.sessionId || session2.pid !== joined2.pid)) {
|
|
23983
|
-
if (joined2.deliveryGeneration
|
|
23979
|
+
if (session2 && (session2.sessionId !== joined2.sessionId || session2.pid !== joined2.pid || hasLocalDelivery(joined2) && !joined2.deliveryGeneration)) {
|
|
23980
|
+
if (hasLocalDelivery(joined2) && (!joined2.deliveryGeneration || session2.sessionId !== joined2.sessionId)) {
|
|
23984
23981
|
const binding = await callTool(joined2, await accessToken(dir, joined2.key), "setup_delivery", {
|
|
23985
23982
|
mechanism: "local",
|
|
23986
23983
|
host: joined2.agent,
|
|
@@ -23989,6 +23986,7 @@ async function flush(dir, sources, deps = realDeps) {
|
|
|
23989
23986
|
installed: true
|
|
23990
23987
|
});
|
|
23991
23988
|
joined2.deliveryGeneration = binding.delivery.generation;
|
|
23989
|
+
joined2.deliveryMechanism = "local";
|
|
23992
23990
|
}
|
|
23993
23991
|
await updateState(dir, (s) => {
|
|
23994
23992
|
const current = s.sessions.find((x) => x.key === joined2.key);
|
|
@@ -23996,6 +23994,7 @@ async function flush(dir, sources, deps = realDeps) {
|
|
|
23996
23994
|
current.sessionId = session2.sessionId;
|
|
23997
23995
|
current.pid = session2.pid;
|
|
23998
23996
|
current.deliveryGeneration = joined2.deliveryGeneration;
|
|
23997
|
+
current.deliveryMechanism = joined2.deliveryMechanism;
|
|
23999
23998
|
}
|
|
24000
23999
|
});
|
|
24001
24000
|
log(dir, `${joined2.key}: in session ${session2.sessionId}`);
|
|
@@ -24242,11 +24241,10 @@ async function runBridge(dir, runner2) {
|
|
|
24242
24241
|
const controller = new AbortController(), entry = { fingerprint: fingerprint(joined2), controller, recovered };
|
|
24243
24242
|
streams.set(joined2.key, entry);
|
|
24244
24243
|
const job = (async () => {
|
|
24245
|
-
let expiredToken;
|
|
24246
24244
|
while (!controller.signal.aborted) {
|
|
24247
24245
|
let opened = false, terminal = false;
|
|
24248
24246
|
try {
|
|
24249
|
-
const token = await accessToken(dir, joined2.key
|
|
24247
|
+
const token = await accessToken(dir, joined2.key);
|
|
24250
24248
|
const current = readState(dir).sessions.find((session2) => session2.key === joined2.key);
|
|
24251
24249
|
if (!current) {
|
|
24252
24250
|
failedStartup("session disappeared");
|
|
@@ -24279,9 +24277,7 @@ async function runBridge(dir, runner2) {
|
|
|
24279
24277
|
continue;
|
|
24280
24278
|
}
|
|
24281
24279
|
if (frame.type === "ended") {
|
|
24282
|
-
terminal =
|
|
24283
|
-
if (!terminal)
|
|
24284
|
-
expiredToken = token;
|
|
24280
|
+
terminal = true;
|
|
24285
24281
|
break;
|
|
24286
24282
|
}
|
|
24287
24283
|
if (await acceptMemberDelivery(dir, joined2.key, runner2, frame)) {
|
|
@@ -25459,9 +25455,8 @@ async function joinCommand(args, env) {
|
|
|
25459
25455
|
const previous = existingPending(dir, own2, server);
|
|
25460
25456
|
const clientId = previous?.pending.clientId ?? await registerClient(server, agentLabel(own2.agent));
|
|
25461
25457
|
const available = previous ? await tryWithKernelLock(finisherKey(previous.file), async () => true) : true;
|
|
25462
|
-
const known = previous?.pending.signIn.tokens
|
|
25463
|
-
const
|
|
25464
|
-
const resume = previous && (available !== true || Number.isFinite(knownUntil) && knownUntil > Date.now() || !known && !previous.pending.signIn.exchangeStarted && previous.pending.startedAt + 6e5 > Date.now());
|
|
25458
|
+
const known = previous?.pending.signIn.tokens;
|
|
25459
|
+
const resume = previous && (available !== true || Boolean(known) || !known && !previous.pending.signIn.exchangeStarted && previous.pending.startedAt + 6e5 > Date.now());
|
|
25465
25460
|
const signIn = resume ? previous.pending.signIn : signInLink(server, clientId, name, own2.claudeInboundFallback);
|
|
25466
25461
|
const pending = resume ? previous.pending : {
|
|
25467
25462
|
server,
|
|
@@ -25545,9 +25540,7 @@ async function finishJoinOwned(file, env) {
|
|
|
25545
25540
|
server: pending.server,
|
|
25546
25541
|
clientId: pending.clientId,
|
|
25547
25542
|
deliveryMechanism: "unfinished",
|
|
25548
|
-
refreshToken: tokens.refresh_token,
|
|
25549
25543
|
accessToken: tokens.access_token,
|
|
25550
|
-
accessExpiresAt: Date.now() + tokens.expires_in * 1e3,
|
|
25551
25544
|
sessionId: pending.sessionId,
|
|
25552
25545
|
pid: pending.pid,
|
|
25553
25546
|
cursor: "0",
|
|
@@ -25753,7 +25746,7 @@ async function session(args, env) {
|
|
|
25753
25746
|
await fetch(`${joined2.server}/mcp/oauth/revoke`, {
|
|
25754
25747
|
method: "POST",
|
|
25755
25748
|
headers: { "content-type": "application/json" },
|
|
25756
|
-
body: JSON.stringify({ client_id: joined2.clientId, token: joined2.refreshToken }),
|
|
25749
|
+
body: JSON.stringify({ client_id: joined2.clientId, token: joined2.accessToken ?? joined2.refreshToken }),
|
|
25757
25750
|
signal: void 0
|
|
25758
25751
|
}).catch(() => void 0);
|
|
25759
25752
|
const left = await updateState(dir, (state) => {
|