@bivy/bivy 0.2.1 → 0.3.0
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/server.js +32 -2
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -4578,6 +4578,36 @@ function invalidateGitHubApps() {
|
|
|
4578
4578
|
* replies post as `<app>[bot]`; anything else uses the device-flow PAT. This is
|
|
4579
4579
|
* where future sources (Slack bot token, Linear/Notion OAuth) branch in.
|
|
4580
4580
|
*/
|
|
4581
|
+
// Hosted (control-plane-orchestrated) machines carry neither a static GitHub
|
|
4582
|
+
// token nor an app key. When BIVY_HOSTED_MINT is set they mint a fresh,
|
|
4583
|
+
// short-lived token from the control plane per git op — cached until ~5 min
|
|
4584
|
+
// before expiry so a burst of git ops is a single round trip. This is the final
|
|
4585
|
+
// fallback rung after local apps and BIVY_GITHUB_TOKEN.
|
|
4586
|
+
let hostedMintCache;
|
|
4587
|
+
async function hostedMintToken() {
|
|
4588
|
+
if (!process.env.BIVY_HOSTED_MINT || !sessionAdvertiseTarget)
|
|
4589
|
+
return undefined;
|
|
4590
|
+
const now = Date.now();
|
|
4591
|
+
if (hostedMintCache && hostedMintCache.expiresAt - now > 5 * 60 * 1000)
|
|
4592
|
+
return hostedMintCache.token;
|
|
4593
|
+
try {
|
|
4594
|
+
const res = await fetch(`${sessionAdvertiseTarget.controlPlaneUrl.replace(/\/$/, "")}/node/hosted-git-credential`, {
|
|
4595
|
+
method: "POST",
|
|
4596
|
+
headers: { authorization: `Bearer ${sessionAdvertiseTarget.enrollmentToken}` },
|
|
4597
|
+
});
|
|
4598
|
+
if (!res.ok)
|
|
4599
|
+
return undefined;
|
|
4600
|
+
const data = (await res.json().catch(() => ({})));
|
|
4601
|
+
if (!data.token)
|
|
4602
|
+
return undefined;
|
|
4603
|
+
const parsed = data.expiresAt ? Date.parse(data.expiresAt) : NaN;
|
|
4604
|
+
hostedMintCache = { token: data.token, expiresAt: Number.isFinite(parsed) ? parsed : now + 55 * 60 * 1000 };
|
|
4605
|
+
return data.token;
|
|
4606
|
+
}
|
|
4607
|
+
catch {
|
|
4608
|
+
return undefined;
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4581
4611
|
async function resolveTokenForWorkItem(item) {
|
|
4582
4612
|
if (item.installationId) {
|
|
4583
4613
|
const apps = await ensureGitHubApps();
|
|
@@ -4595,7 +4625,7 @@ async function resolveTokenForWorkItem(item) {
|
|
|
4595
4625
|
}
|
|
4596
4626
|
}
|
|
4597
4627
|
}
|
|
4598
|
-
return resolveGitHubToken();
|
|
4628
|
+
return (await resolveGitHubToken()) ?? (await hostedMintToken());
|
|
4599
4629
|
}
|
|
4600
4630
|
/**
|
|
4601
4631
|
* The token for interactive repo operations (clone/fetch/push/PR) on `owner/repo`.
|
|
@@ -4643,7 +4673,7 @@ async function resolveTokenForRepo(owner, repo) {
|
|
|
4643
4673
|
}
|
|
4644
4674
|
}
|
|
4645
4675
|
}
|
|
4646
|
-
return resolveGitHubToken();
|
|
4676
|
+
return (await resolveGitHubToken()) ?? (await hostedMintToken());
|
|
4647
4677
|
}
|
|
4648
4678
|
async function runWorkItem(item, report) {
|
|
4649
4679
|
if ((item.source === "schedule" || item.source === "manual") && item.body?.startsWith("bivy-room-v1:")) {
|