Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(skills): look up the GitHub sign-in once per skill import
Ooi Pin Junf63f8daefc35
diff --git a/server/skill-fetch.test.ts b/server/skill-fetch.test.tsindex 07b92e58fa..e2550cbcac 100644--- a/server/skill-fetch.test.ts+++ b/server/skill-fetch.test.ts@@ -95,10 +95,16 @@ describe("importing a skill's whole folder", () => {it("sends the connected GitHub sign-in on every API request and keeps raw downloads anonymous", async () => {const github = fakeGitHub({ "a/b": PDF_SKILL });const recorded = recordingFetch(github.fetch);- const [skill] = ok(await fetchSkillFromSource("https://github.com/a/b/tree/main/skills/pdf", recorded.fetch, undefined, async () => SIGNED_IN));+ let lookups = 0;+ const [skill] = ok(await fetchSkillFromSource("https://github.com/a/b/tree/main/skills/pdf", recorded.fetch, undefined, async () => {+ lookups += 1;+ return SIGNED_IN;+ }));expect(skill!.github?.commit).toBe(github.commitOf("a/b"));const api = apiCalls(recorded.calls);const raw = rawCalls(recorded.calls);+ expect(api.length).toBeGreaterThan(1);+ expect(lookups).toBe(1);expect(api.some((call) => call.url.includes("/commits/"))).toBe(true);expect(api.some((call) => call.url.includes("/contents/"))).toBe(true);expect(api.some((call) => call.url.includes("/git/trees/"))).toBe(true);@@ -113,10 +119,16 @@ describe("importing a skill's whole folder", () => {it("stays anonymous when the sign-in getter has no token", async () => {const github = fakeGitHub({ "a/b": PDF_SKILL });const recorded = recordingFetch(github.fetch);- const [skill] = ok(await fetchSkillFromSource("https://github.com/a/b/tree/main/skills/pdf", recorded.fetch, undefined, async () => null));+ let lookups = 0;+ const [skill] = ok(await fetchSkillFromSource("https://github.com/a/b/tree/main/skills/pdf", recorded.fetch, undefined, async () => {+ lookups += 1;+ return null;+ }));expect(skill!.files.length).toBeGreaterThan(0);const api = apiCalls(recorded.calls);const raw = rawCalls(recorded.calls);+ expect(api.length).toBeGreaterThan(1);+ expect(lookups).toBe(1);expect(api.length).toBeGreaterThan(0);expect(raw.length).toBeGreaterThan(0);expect(recorded.calls.every((call) => call.headers.get("authorization") === null)).toBe(true);diff --git a/server/skill-fetch.ts b/server/skill-fetch.tsindex 9434caf20c..530c96e43b 100644--- a/server/skill-fetch.ts+++ b/server/skill-fetch.ts@@ -53,8 +53,11 @@ function boundedImportFetch(let apiRequests = 0;let downloads = 0;let bytes = 0;+ let credential: Promise<string | null> | undefined;const timeout = AbortSignal.timeout(IMPORT_LIMITS.ms);const signal = cancel ? AbortSignal.any([timeout, cancel]) : timeout;+ // `gh auth token` starts a process; a null answer stays null for this import.+ const credentialOnce = (): Promise<string | null> => (credential ??= (async () => authorization())());return async (input, init) => {const api = isGitHubApiRequest(input);if (api ? ++apiRequests > IMPORT_LIMITS.apiRequests : ++downloads > IMPORT_LIMITS.downloads) {@@ -63,8 +66,8 @@ function boundedImportFetch(signal.throwIfAborted();const sent: RequestInit = { ...init, signal };if (api) {- const credential = await authorization();- const headers = credential ? withBearer(input, init, credential) : null;+ const token = await credentialOnce();+ const headers = token ? withBearer(input, init, token) : null;if (headers) {sent.headers = headers;sent.redirect = "error";